getsentry / getsentry/sentry-java
Support dynamic error sampling
- 主要語言
- Kotlin
- 星號
- 1.4k
- 分支
- 478
- 平均合併
- 3 天 4 小時
- 30 天內合併 PR
- 72
描述
### Description
Just like `TracesSamplerCallback`, we want to have a callback capable sampling errors. This feature already exists in our [Python SDK](https://docs.sentry.io/platforms/python/configuration/sampling/#dynamically-sampling-error-events).
```Python
sentry_sdk.init(
# ...
error_sampler=my_sampler,
)
```
Right now the workaround would be to keep hold of the options and change the `sampleRate` after the SDK has been initialized.
This should work just fine, as `SentryClient` reads out the sample rate every time, but is still discouraged, as we don't officially support changing options on the fly.
```Java
final AtomicReference optionsRef = new AtomicReference<>();
Sentry.init(new Sentry.OptionsConfiguration() {
@Override
public void configure(@NotNull SentryOptions options) {
options.setDsn("...");
options.setSampleRate(1.0); // some sane default
// ...
optionsRef.set(options);
}
});
// later, dynamically update the sampleRate
private void onRemoteConfigChanged(final @NotNull RemoteConfig remoteConfig){
final @Nullable SentryOptions options = optionsRef.get();
if (options != null) {
options.setSampleRate(remoteConfig.sampleRate);
}
}
```
貢獻指南
研究方向
先閱讀現有的 TracesSamplerCallback、SentryClient 和 SentryOptions 流程,尤其是如何為錯誤讀取 sampleRate。在現有的 trace sampler 旁定義錯誤採樣回呼,並驗證錯誤事件可以動態採樣,而不必在初始化後變更選項。當 Java SDK 支援所要求的回呼行為,且測試涵蓋採樣結果時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java, kotlin
- 領域
- observability
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100