Skip to content

feat: add trace methods to public API - #1394

Open
giortzisg wants to merge 1 commit into
scopes/context-tracingfrom
scopes/integration-primitives
Open

feat: add trace methods to public API#1394
giortzisg wants to merge 1 commit into
scopes/context-tracingfrom
scopes/integration-primitives

Conversation

@giortzisg

Copy link
Copy Markdown
Contributor

Description

Issues

Changelog Entry Instructions

To add a custom changelog entry, uncomment the section above. Supports:

  • Single entry: just write text
  • Multiple entries: use bullet points
  • Nested bullets: indent 4+ spaces

For more details: custom changelog entries

Reminders

@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 4d788fd to deeab0c Compare August 24, 2026 10:53
@giortzisg
giortzisg marked this pull request as ready for review August 24, 2026 13:24
Comment thread scope.go
This adds trace, logging and metrics primitives so that integrations can
be cleanly migrated to scopes and context.
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from deeab0c to 7e6baff Compare August 31, 2026 10:50
Comment thread metrics.go
Comment on lines +120 to 127
if client.captureMetric(metric, signalCaptureContext{scope: scope, ctx: ctx}) && client.options.Debug {
debuglog.Printf("Metric %s [%s]: %v %s", metricType, name, value.AsInterface(), unit)
}
}

func prepareMetric(metric *Metric, client *Client, capture signalCaptureContext) {
trace := resolveTrace(capture.scope, client, capture.ctx, capture.fallback)
trace := resolveTrace(capture.scope, client, capture.ctx)
metric.TraceID = trace.traceID

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Removing the fallback to the creation-time context can cause trace information to be lost if metrics are emitted with a context lacking the original trace data.
Severity: MEDIUM

Suggested Fix

Restore the previous behavior by using the creation-time context as a fallback. Utilize a mechanism similar to the previous hubFromContexts(ctx, m.ctx) to ensure that if the emit-time ctx lacks a scope, the scope from the creation-time context is used to preserve trace information.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: metrics.go#L120-L127

Potential issue: The removal of a fallback to the creation-time context can lead to the
silent loss of trace information. The new code determines the Sentry scope exclusively
from the emit-time context using `scope = ScopeFromContext(ctx)`. If this context lacks
a Sentry scope, `scope` becomes `nil`, and the `resolveTrace` function returns a zeroed
`traceResolution`, dropping all trace IDs. The previous implementation avoided this by
using the creation-time context as a fallback (`hubFromContexts(ctx, m.ctx)`), which
preserved trace data even if the emit-time context was bare.

Did we get this right? 👍 / 👎 to inform future reviews.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7e6baff. Configure here.

Comment thread log.go

// NewLogger returns a Logger that emits logs to Sentry.
func NewLogger(ctx context.Context) Logger { // nolint: dupl
var hub *Hub

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client lookup skips hub-bound clients

High Severity

NewLogger and NewMeter now resolve the client only through GetClient, which checks a context scope or GlobalScope. A client bound with CurrentHub().BindClient is no longer found unless Init also set GlobalScope or the context carries a scope. Logs and metrics are silently discarded, and scope data from ConfigureScope is dropped.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7e6baff. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant