-
Notifications
You must be signed in to change notification settings - Fork 251
feat: re-enable Telemetry Processor and simplify setup #1254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f12e2cd
e7bfe5e
5229042
cb84b35
3d172e2
f7f02a8
228ede0
7786612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "sort" | ||
| "strings" | ||
| "sync" | ||
| "sync/atomic" | ||
| "time" | ||
|
|
||
| "github.com/getsentry/sentry-go/internal/debug" | ||
|
|
@@ -294,12 +295,13 @@ type ClientOptions struct { | |
| type Client struct { | ||
| mu sync.RWMutex | ||
| options ClientOptions | ||
| dsn *Dsn | ||
| dsn *protocol.Dsn | ||
| eventProcessors []EventProcessor | ||
| integrations []Integration | ||
| externalTraceResolver externalContextTraceResolver | ||
| sdkIdentifier string | ||
| sdkVersion string | ||
| sdkInfo atomic.Pointer[protocol.SdkInfo] | ||
| // Transport is read-only. Replacing the transport of an existing client is | ||
| // not supported, create a new client instead. | ||
| Transport Transport | ||
|
|
@@ -395,10 +397,10 @@ func NewClient(options ClientOptions) (*Client, error) { | |
| } | ||
| } | ||
|
|
||
| var dsn *Dsn | ||
| var dsn *protocol.Dsn | ||
| if options.Dsn != "" { | ||
| var err error | ||
| dsn, err = NewDsn(options.Dsn) | ||
| dsn, err = protocol.NewDsn(options.Dsn) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -412,32 +414,37 @@ func NewClient(options ClientOptions) (*Client, error) { | |
| reportRecorder: report.NoopRecorder(), | ||
| reportProvider: report.NoopProvider(), | ||
| } | ||
| client.refreshSDKInfo() | ||
|
|
||
| if !options.DisableClientReports { | ||
| a := report.NewAggregator() | ||
| client.reportRecorder = a | ||
| client.reportProvider = a | ||
| } | ||
|
|
||
| client.setupTransport() | ||
|
|
||
| // noop Telemetry Buffers and Processor fow now | ||
| // if !options.DisableTelemetryBuffer { | ||
| // client.setupTelemetryProcessor() | ||
| // } else | ||
| if options.EnableLogs { | ||
| client.batchLogger = newLogBatchProcessor(&client) | ||
| client.batchLogger.Start() | ||
| } | ||
| // We currently disallow using custom Transport with the new Telemetry Processor, due to the difference in transport signatures. | ||
| // The option should be enabled when the new Transport interface signature changes. | ||
| if !options.DisableTelemetryBuffer && client.options.Transport == nil { | ||
| client.setupTelemetryProcessor() | ||
| } else { | ||
| if client.options.Transport != nil { | ||
| debuglog.Println("Cannot enable Telemetry Processor with custom Transport: fallback to old transport") | ||
| } | ||
| client.setupTransport() | ||
| client.setupIntegrations() | ||
|
|
||
| if !options.DisableMetrics { | ||
| client.batchMeter = newMetricBatchProcessor(&client) | ||
| client.batchMeter.Start() | ||
| if options.EnableLogs { | ||
| client.batchLogger = newLogBatchProcessor(&client) | ||
| client.batchLogger.Start() | ||
| } | ||
| if !options.DisableMetrics { | ||
| client.batchMeter = newMetricBatchProcessor(&client) | ||
| client.batchMeter.Start() | ||
| } | ||
| } | ||
| if options.OrgID != 0 && client.dsn != nil { | ||
| client.dsn.SetOrgID(options.OrgID) | ||
| } | ||
| client.setupIntegrations() | ||
|
|
||
| return &client, nil | ||
| } | ||
|
|
@@ -467,38 +474,15 @@ func (client *Client) setupTransport() { | |
| case *internalAsyncTransportAdapter: | ||
| tr.recorder = client.reportRecorder | ||
| tr.provider = client.reportProvider | ||
| tr.sdkInfo = &client.sdkInfo | ||
| } | ||
| } | ||
|
|
||
| transport.Configure(opts) | ||
| client.Transport = transport | ||
| } | ||
|
|
||
| func (client *Client) setupTelemetryProcessor() { // nolint: unused | ||
| if client.options.DisableTelemetryBuffer { | ||
| return | ||
| } | ||
|
|
||
| if client.dsn == nil { | ||
| debuglog.Println("Telemetry buffer disabled: no DSN configured") | ||
| return | ||
| } | ||
|
|
||
| // We currently disallow using custom Transport with the new Telemetry Processor, due to the difference in transport signatures. | ||
| // The option should be enabled when the new Transport interface signature changes. | ||
| if client.options.Transport != nil { | ||
| debuglog.Println("Cannot enable Telemetry Processor/Buffers with custom Transport: fallback to old transport") | ||
| if client.options.EnableLogs { | ||
| client.batchLogger = newLogBatchProcessor(client) | ||
| client.batchLogger.Start() | ||
| } | ||
| if !client.options.DisableMetrics { | ||
| client.batchMeter = newMetricBatchProcessor(client) | ||
| client.batchMeter.Start() | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func (client *Client) setupTelemetryProcessor() { | ||
| transport := httpInternal.NewAsyncTransport(httpInternal.TransportOptions{ | ||
| Dsn: client.options.Dsn, | ||
| HTTPClient: client.options.HTTPClient, | ||
|
|
@@ -508,8 +492,9 @@ func (client *Client) setupTelemetryProcessor() { // nolint: unused | |
| CaCerts: client.options.CaCerts, | ||
| Recorder: client.reportRecorder, | ||
| Provider: client.reportProvider, | ||
| SdkInfo: &client.sdkInfo, | ||
| }) | ||
| client.Transport = &internalAsyncTransportAdapter{transport: transport} | ||
| client.Transport = &internalAsyncTransportAdapter{transport: transport, sdkInfo: &client.sdkInfo} | ||
|
|
||
| buffers := map[ratelimit.Category]telemetry.Buffer[protocol.TelemetryItem]{ | ||
| ratelimit.CategoryError: telemetry.NewRingBuffer[protocol.TelemetryItem](ratelimit.CategoryError, 100, telemetry.OverflowPolicyDropOldest, 1, 0, client.reportRecorder), | ||
|
|
@@ -519,12 +504,8 @@ func (client *Client) setupTelemetryProcessor() { // nolint: unused | |
| ratelimit.CategoryTraceMetric: telemetry.NewRingBuffer[protocol.TelemetryItem](ratelimit.CategoryTraceMetric, 10*100, telemetry.OverflowPolicyDropOldest, 100, 5*time.Second, client.reportRecorder), | ||
| } | ||
|
|
||
| sdkInfo := &protocol.SdkInfo{ | ||
| Name: client.sdkIdentifier, | ||
| Version: client.sdkVersion, | ||
| } | ||
|
|
||
| client.telemetryProcessor = telemetry.NewProcessor(buffers, transport, &client.dsn.Dsn, sdkInfo, client.reportRecorder) | ||
| client.setupIntegrations() | ||
| client.telemetryProcessor = telemetry.NewProcessor(buffers, transport, client.dsn, &client.sdkInfo, client.reportRecorder) | ||
| } | ||
|
|
||
| func (client *Client) setupIntegrations() { | ||
|
|
@@ -554,6 +535,7 @@ func (client *Client) setupIntegrations() { | |
| sort.Slice(client.integrations, func(i, j int) bool { | ||
| return client.integrations[i].Name() < client.integrations[j].Name() | ||
| }) | ||
| client.refreshSDKInfo() | ||
| } | ||
|
|
||
| // AddEventProcessor adds an event processor to the client. It must not be | ||
|
|
@@ -874,9 +856,10 @@ func (client *Client) EventFromCheckIn(checkIn *CheckIn, monitorConfig *MonitorC | |
|
|
||
| func (client *Client) SetSDKIdentifier(identifier string) { | ||
| client.mu.Lock() | ||
| defer client.mu.Unlock() | ||
|
|
||
| client.sdkIdentifier = identifier | ||
| client.mu.Unlock() | ||
|
|
||
| client.refreshSDKInfo() | ||
| } | ||
|
|
||
| func (client *Client) GetSDKIdentifier() string { | ||
|
|
@@ -982,15 +965,7 @@ func (client *Client) prepareEvent(event *Event, hint *EventHint, scope EventMod | |
| } | ||
|
|
||
| event.Platform = "go" | ||
| event.Sdk = SdkInfo{ | ||
| Name: client.GetSDKIdentifier(), | ||
| Version: SDKVersion, | ||
| Integrations: client.listIntegrations(), | ||
| Packages: []SdkPackage{{ | ||
| Name: "sentry-go", | ||
| Version: SDKVersion, | ||
| }}, | ||
| } | ||
| event.Sdk = *client.sdkInfo.Load() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: A Suggested FixIn Prompt for AI Agent |
||
|
|
||
| if scope != nil { | ||
| event = scope.ApplyToEvent(event, hint, client) | ||
|
|
@@ -1061,6 +1036,22 @@ func (client *Client) integrationAlreadyInstalled(name string) bool { | |
| return false | ||
| } | ||
|
|
||
| func (client *Client) refreshSDKInfo() { | ||
| client.mu.RLock() | ||
| info := protocol.SdkInfo{ | ||
| Name: client.sdkIdentifier, | ||
| Version: client.sdkVersion, | ||
| Integrations: client.listIntegrations(), | ||
| Packages: []protocol.SdkPackage{{ | ||
| Name: "sentry-go", | ||
| Version: client.sdkVersion, | ||
| }}, | ||
| } | ||
| client.mu.RUnlock() | ||
|
|
||
| client.sdkInfo.Store(&info) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race in refreshSDKInfo can store stale SDK infoLow Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 7786612. Configure here. |
||
|
|
||
| // sample returns true with the given probability, which must be in the range | ||
| // [0.0, 1.0]. | ||
| func sample(probability float64) bool { | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.