Skip to content

Commit

Permalink
sentrycore: emit trace ID, span ID in Sentry-specific trace context a…
Browse files Browse the repository at this point in the history
…s well (#66)

Following
https://develop.sentry.dev/sdk/event-payloads/contexts/#trace-context -
looks like Sentry might have some special UI presentation/categorization
capabilities around this
  • Loading branch information
bobheadxi committed Apr 22, 2024
1 parent f530238 commit 5e85304
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/sinkcores/sentrycore/integration_test.go
Expand Up @@ -134,6 +134,10 @@ func TestWithTrace(t *testing.T) {
attrs := tr.Events()[0].Contexts["log"]
assert.Equal(t, "123", attrs["TraceId"])
assert.Equal(t, "456", attrs["SpanId"])
// Also reflect trace into Sentry's specialized trace context
traceAttrs := tr.Events()[0].Contexts["trace"]
assert.Equal(t, "123", traceAttrs["trace_id"])
assert.Equal(t, "456", traceAttrs["span_id"])
}

func TestFields(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions internal/sinkcores/sentrycore/worker.go
Expand Up @@ -189,6 +189,14 @@ func (w *worker) capture(errCtx *errorContext) {
w.hub.hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtras(extraDetails)
scope.SetContext("log", enc.Fields)
if enc.Fields != nil {
// Also reflect trace into Sentry's specialized trace context
// https://develop.sentry.dev/sdk/event-payloads/contexts/#trace-context
scope.SetContext("trace", sentry.Context{
"trace_id": enc.Fields["TraceId"],
"span_id": enc.Fields["SpanId"],
})
}
scope.SetTags(tags)
scope.SetLevel(level)
w.hub.hub.CaptureEvent(event)
Expand Down

0 comments on commit 5e85304

Please sign in to comment.