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

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

Conversation

@giortzisg

@giortzisg giortzisg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

This adds new trace propagation APIs that resolve with context. Also changes logs and metrics to resolve scope through context rather than the old hub API.

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
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from deeab0c to 7e6baff Compare August 31, 2026 10:50
Comment thread metrics.go Outdated
Comment thread log.go
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 7e6baff to 51c535e Compare September 1, 2026 09:12

@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.

Stale Bugbot comment from a previous run.

Comment thread log.go Outdated
@giortzisg
giortzisg requested a review from Litarnus September 1, 2026 09:19
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 51c535e to d7b1f55 Compare September 1, 2026 12:57
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from d7b1f55 to 45876fc Compare September 2, 2026 07:59
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 45876fc to 71754bd Compare September 4, 2026 13:11
Comment thread tracing.go Outdated
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 71754bd to 4ec37b3 Compare September 4, 2026 13:26
Comment thread tracing.go Outdated
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 4ec37b3 to c4e83dd Compare September 7, 2026 11:40
Comment thread tracing.go Outdated
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from c4e83dd to c2a58ea Compare September 7, 2026 11:49

@szokeasaurusrex szokeasaurusrex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes mostly look okay, but it seems this PR contains more changes than are suggested by the PR description. Was there perhaps a problem when rebasing the stack? Or these are all intended to be here?

Edit: Nvm, I re-read the description and suppose everything is in scope 😅

Comment thread log_fallback.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What was this file's purpose? Was it for enable_logs == false?

Comment thread log_test.go Outdated
Comment on lines +23 to +39
type panicStringer struct{}

func (panicStringer) String() string {
panic("disabled logs must not format values")
}

// flushFromContext flushes the client from the given context.
func flushFromContext(ctx context.Context, timeout time.Duration) {
hub := GetHubFromContext(ctx)
if hub == nil {
hub = CurrentHub()
}
hub.Flush(timeout)
ClientFromContext(ctx).Flush(timeout)
}

func TestDisabledLoggerDoesNotFormatValues(_ *testing.T) {
ctx := ContextWithClient(context.Background(), NewNoopClient())
logger := NewLogger(ctx)

logger.Info().Emit(panicStringer{})
logger.Info().Emitf("%v", panicStringer{})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

Comment thread metrics.go
Comment on lines +76 to 85
fallbackCtx := m.fallbackCtx
scope := ScopeFromContext(ctx)
if scope == nil {
scope = ScopeFromContext(fallbackCtx)
} else {
fallbackCtx = nil
}
if options.scope != nil {
scope = options.scope
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: It looks like we had similar logic in log.go. Perhaps we can extract it into a function?

Comment thread scope.go
Comment on lines +548 to +555
setString("sentry.release", client.options.Release)
setString("sentry.environment", client.options.Environment)
setString("sentry.server.address", serverAddress)
setString("sentry.sdk.name", sdkName)
setString("sentry.sdk.version", client.sdkVersion)
setString("user.id", scope.user.ID)
setString("user.name", scope.user.Name)
setString("user.email", scope.user.Email)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

m: It would probably be a good idea to extract these attribute names into constants rather than hardcoding them

@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from c2a58ea to aeb2126 Compare September 16, 2026 09:14
Comment thread metrics.go Outdated
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from aeb2126 to 3da3e78 Compare September 17, 2026 08:38
Comment thread dynamic_sampling_context.go
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from 3da3e78 to a5ded29 Compare September 17, 2026 09:09
Resolve log, metric, and propagation data from context-backed clients and scopes, and expose context-based trace header helpers while retaining Hub compatibility.

Use the request transaction as the scope fallback, preserve external trace precedence and sampling flags, and propagate only matching dynamic sampling context. Freeze spanless scope metadata once on first export and take trace IDs and DSC from the same locked snapshot. Reject frozen custom metadata for another trace and propagate a negative decision for fresh unsampled scope-only traces. Explicit request scopes, including metric overrides, isolate logger and meter trace fallback.

Replace stale Sentry baggage while preserving outgoing third-party members.

Keep malformed baggage errors visible to direct parser callers while continuing valid sentry-trace headers. Preserve head sampling metadata when a late status filter rejects a transaction.
@giortzisg
giortzisg removed this pull request from stack #1420 September 18, 2026 11:17
@giortzisg
giortzisg force-pushed the scopes/integration-primitives branch from a5ded29 to 7c1e40f Compare September 18, 2026 11:18
@giortzisg
giortzisg added this pull request to stack #1433 September 18, 2026 11:22

@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 7c1e40f. Configure here.

Comment thread hub.go
return span.ToBaggage()
}
return scope.propagationContextSnapshot().DynamicSamplingContext.String()
return scope.propagationContextForPropagation(hub.Client()).DynamicSamplingContext.String()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hub trace headers disagree on sampling

Medium Severity

GetBaggage now applies the static zero-rate decision and writes sampled=false into DSC, but GetTraceparent and GetTraceparentW3C still read the unsampled snapshot. Callers that emit the sentry-trace header first, including the documented Hub pairing, send a deferred sampling flag while baggage already says the trace is unsampled.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7c1e40f. 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.

2 participants