From e0db6423cba494043021e4d9acecae8ef2706529 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Fri, 26 Jul 2024 15:00:20 +0200 Subject: [PATCH 1/9] Add `transaction.data` to `contexts.trace.data` --- tracing.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tracing.go b/tracing.go index 0c5877c59..b87f92f0f 100644 --- a/tracing.go +++ b/tracing.go @@ -763,12 +763,13 @@ func (ss SpanStatus) MarshalJSON() ([]byte, error) { // A TraceContext carries information about an ongoing trace and is meant to be // stored in Event.Contexts (as *TraceContext). type TraceContext struct { - TraceID TraceID `json:"trace_id"` - SpanID SpanID `json:"span_id"` - ParentSpanID SpanID `json:"parent_span_id"` - Op string `json:"op,omitempty"` - Description string `json:"description,omitempty"` - Status SpanStatus `json:"status,omitempty"` + TraceID TraceID `json:"trace_id"` + SpanID SpanID `json:"span_id"` + ParentSpanID SpanID `json:"parent_span_id"` + Op string `json:"op,omitempty"` + Description string `json:"description,omitempty"` + Status SpanStatus `json:"status,omitempty"` + Data map[string]interface{} `json:"data,omitempty"` } func (tc *TraceContext) MarshalJSON() ([]byte, error) { @@ -811,6 +812,10 @@ func (tc TraceContext) Map() map[string]interface{} { m["status"] = tc.Status } + if len(tc.Data) > 0 { + m["data"] = tc.Data + } + return m } From b515ee991fae68cdad3cc6aeeefdb5691298b385 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Tue, 7 Jan 2025 18:19:07 +0100 Subject: [PATCH 2/9] WIP --- tracing.go | 2 +- tracing_test.go | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tracing.go b/tracing.go index b87f92f0f..789d4c825 100644 --- a/tracing.go +++ b/tracing.go @@ -569,7 +569,6 @@ func (s *Span) toEvent() *Event { Transaction: s.Name, Contexts: contexts, Tags: s.Tags, - Extra: s.Data, Timestamp: s.EndTime, StartTime: s.StartTime, Spans: finished, @@ -588,6 +587,7 @@ func (s *Span) traceContext() *TraceContext { SpanID: s.SpanID, ParentSpanID: s.ParentSpanID, Op: s.Op, + Data: s.Data, Description: s.Description, Status: s.Status, } diff --git a/tracing_test.go b/tracing_test.go index 519b6f38f..c0078dd32 100644 --- a/tracing_test.go +++ b/tracing_test.go @@ -138,15 +138,12 @@ func TestStartSpan(t *testing.T) { SpanID: span.SpanID, ParentSpanID: parentSpanID, Op: op, + Data: span.Data, Description: description, Status: status, }.Map(), }, - Tags: nil, - // TODO(tracing): the root span / transaction data field is - // mapped into Event.Extra for now, pending spec clarification. - // https://github.com/getsentry/develop/issues/244#issuecomment-778694182 - Extra: span.Data, + Tags: nil, Timestamp: endTime, StartTime: startTime, TransactionInfo: &TransactionInfo{ @@ -283,16 +280,13 @@ func TestStartTransaction(t *testing.T) { "trace": TraceContext{ TraceID: transaction.TraceID, SpanID: transaction.SpanID, + Data: transaction.Data, Description: description, Status: status, }.Map(), "otel": {"k": "v"}, }, - Tags: nil, - // TODO(tracing): the root span / transaction data field is - // mapped into Event.Extra for now, pending spec clarification. - // https://github.com/getsentry/develop/issues/244#issuecomment-778694182 - Extra: transaction.Data, + Tags: nil, Timestamp: endTime, StartTime: startTime, TransactionInfo: &TransactionInfo{ From 3bb38a608a96a9aac7e06cc7c4f912a82044a43a Mon Sep 17 00:00:00 2001 From: Giannis Gkiortzis Date: Fri, 4 Apr 2025 11:14:10 +0200 Subject: [PATCH 3/9] check trace data instead of extra in tests --- echo/sentryecho_test.go | 94 +++++++++++++++++++++++++++----- fasthttp/sentryfasthttp_test.go | 82 +++++++++++++++++++++++----- fiber/sentryfiber_test.go | 95 +++++++++++++++++++++++++-------- gin/sentrygin_test.go | 94 +++++++++++++++++++++++++++----- http/sentryhttp_test.go | 71 ++++++++++++++++++++---- iris/sentryiris_test.go | 83 +++++++++++++++++++++------- negroni/sentrynegroni_test.go | 70 ++++++++++++++++++++---- 7 files changed, 487 insertions(+), 102 deletions(-) diff --git a/echo/sentryecho_test.go b/echo/sentryecho_test.go index 4eaa285ed..03a060589 100644 --- a/echo/sentryecho_test.go +++ b/echo/sentryecho_test.go @@ -65,7 +65,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "GET", "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -88,8 +97,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "GET", "http.response.status_code": 404}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusNotFound, + }, + Op: "http.server", + Status: sentry.SpanStatusNotFound, + }.Map(), + }}, }, { RequestPath: "/post", @@ -135,8 +152,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "POST", "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { RequestPath: "/get", @@ -173,8 +198,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "GET", "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { RequestPath: "/post/large", @@ -220,8 +253,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "POST", "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { RequestPath: "/post/body-ignored", @@ -265,8 +306,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "POST", "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { RequestPath: "/badreq", @@ -289,8 +338,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": "GET", "http.response.status_code": 400}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusBadRequest, + }, + Op: "http.server", + Status: sentry.SpanStatusInvalidArgument, + }.Map(), + }}, WantEvent: nil, }, } @@ -402,7 +459,7 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), @@ -410,6 +467,15 @@ func TestIntegration(t *testing.T) { sentry.Request{}, "Env", ), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wantTrans, gott, optstrans); diff != "" { t.Fatalf("Transaction mismatch (-want +got):\n%s", diff) diff --git a/fasthttp/sentryfasthttp_test.go b/fasthttp/sentryfasthttp_test.go index 7fdacc0b7..44bd19c83 100644 --- a/fasthttp/sentryfasthttp_test.go +++ b/fasthttp/sentryfasthttp_test.go @@ -64,7 +64,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -103,8 +112,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/get", @@ -138,8 +155,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/post/large", @@ -178,8 +203,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/post/body-ignored", @@ -219,8 +252,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/post/error-handler", @@ -262,8 +303,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, } @@ -379,7 +428,7 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), @@ -401,6 +450,15 @@ func TestIntegration(t *testing.T) { // ignore them. return k == "Content-Length" || k == "Content-Type" }), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wantTransactions, gotTransactions, optstrans); diff != "" { t.Fatalf("Transactions mismatch (-want +gotEvents):\n%s", diff) diff --git a/fiber/sentryfiber_test.go b/fiber/sentryfiber_test.go index d135b122f..2504b40b5 100644 --- a/fiber/sentryfiber_test.go +++ b/fiber/sentryfiber_test.go @@ -108,9 +108,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodGet, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -148,9 +154,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodPost, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -184,9 +196,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodGet, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -219,9 +237,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodGet, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -260,9 +284,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodPost, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -301,9 +331,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodPost, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -344,9 +380,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{ - "http.request.method": http.MethodPost, - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, }, @@ -452,7 +494,7 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), @@ -464,6 +506,15 @@ func TestIntegration(t *testing.T) { sentry.Exception{}, "Stacktrace", ), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wantTransactions, gotTransactions, optstrans); diff != "" { diff --git a/gin/sentrygin_test.go b/gin/sentrygin_test.go index 3b33bc683..01dbdff33 100644 --- a/gin/sentrygin_test.go +++ b/gin/sentrygin_test.go @@ -54,8 +54,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": string("GET"), "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, WantEvent: &sentry.Event{ Level: sentry.LevelFatal, Message: "test", @@ -88,7 +96,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": string("GET"), "http.response.status_code": 404}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusNotFound, + }, + Op: "http.server", + Status: sentry.SpanStatusNotFound, + }.Map(), + }, }, WantEvent: nil, }, @@ -122,8 +139,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": string("POST"), "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, Message: "post: payload", @@ -162,8 +187,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": string("GET"), "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, Message: "get", @@ -205,8 +238,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": string("POST"), "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, Message: "post: 15 KB", @@ -249,8 +290,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": string("POST"), "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, Message: "body ignored", @@ -288,8 +337,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]any{"http.request.method": string("GET"), "http.response.status_code": 400}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusBadRequest, + }, + Op: "http.server", + Status: sentry.SpanStatusInvalidArgument, + }.Map(), + }}, WantEvent: nil, }, } @@ -394,7 +451,7 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), @@ -402,6 +459,15 @@ func TestIntegration(t *testing.T) { sentry.Request{}, "Env", ), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wanttrans, gott, optstrans); diff != "" { t.Fatalf("Transaction mismatch (-want +got):\n%s", diff) diff --git a/http/sentryhttp_test.go b/http/sentryhttp_test.go index 75f735758..b53046729 100644 --- a/http/sentryhttp_test.go +++ b/http/sentryhttp_test.go @@ -61,7 +61,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -107,7 +116,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -143,7 +161,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -191,7 +218,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -235,8 +271,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, } @@ -339,14 +383,19 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), - cmpopts.IgnoreFields( - sentry.Request{}, - "Env", - ), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wantTrans, gott, optstrans); diff != "" { t.Fatalf("Transaction mismatch (-want +got):\n%s", diff) diff --git a/iris/sentryiris_test.go b/iris/sentryiris_test.go index b1b35953d..313f154dd 100644 --- a/iris/sentryiris_test.go +++ b/iris/sentryiris_test.go @@ -53,9 +53,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]interface{}{ - "http.request.method": string("GET"), - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, WantEvent: &sentry.Event{ @@ -126,9 +132,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]interface{}{ - "http.request.method": string("POST"), - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, WantEvent: &sentry.Event{ @@ -170,9 +182,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]interface{}{ - "http.request.method": string("GET"), - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, WantEvent: &sentry.Event{ @@ -216,9 +234,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]interface{}{ - "http.request.method": string("POST"), - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, WantEvent: &sentry.Event{ @@ -263,9 +287,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]interface{}{ - "http.request.method": string("POST"), - "http.response.status_code": http.StatusOK, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), }, }, WantEvent: &sentry.Event{ @@ -306,9 +336,15 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "route"}, - Extra: map[string]interface{}{ - "http.request.method": string("GET"), - "http.response.status_code": http.StatusBadRequest, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusBadRequest, + }, + Op: "http.server", + Status: sentry.SpanStatusInvalidArgument, + }.Map(), }, }, WantEvent: nil, @@ -415,7 +451,7 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), @@ -423,6 +459,15 @@ func TestIntegration(t *testing.T) { sentry.Request{}, "Env", ), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wanttrans, gott, optstrans); diff != "" { t.Fatalf("Transaction mismatch (-want +got):\n%s", diff) diff --git a/negroni/sentrynegroni_test.go b/negroni/sentrynegroni_test.go index 2336d9026..339e4b585 100644 --- a/negroni/sentrynegroni_test.go +++ b/negroni/sentrynegroni_test.go @@ -62,7 +62,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK}, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }, }, }, { @@ -108,8 +117,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/get", @@ -144,8 +161,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodGet, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/post/large", @@ -192,8 +217,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, { Path: "/post/body-ignored", @@ -236,8 +269,16 @@ func TestIntegration(t *testing.T) { }, }, TransactionInfo: &sentry.TransactionInfo{Source: "url"}, - Extra: map[string]any{"http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK}, - }, + Contexts: map[string]sentry.Context{ + "trace": sentry.TraceContext{ + Data: map[string]interface{}{ + "http.request.method": http.MethodPost, + "http.response.status_code": http.StatusOK, + }, + Op: "http.server", + Status: sentry.SpanStatusOK, + }.Map(), + }}, }, } @@ -344,7 +385,7 @@ func TestIntegration(t *testing.T) { optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, - "Contexts", "EventID", "Platform", "Modules", + "EventID", "Platform", "Modules", "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), @@ -352,6 +393,15 @@ func TestIntegration(t *testing.T) { sentry.Request{}, "Env", ), + cmpopts.IgnoreMapEntries(func(k string, v any) bool { + ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} + for _, e := range ignoredCtxEntries { + if k == e { + return true + } + } + return false + }), } if diff := cmp.Diff(wantTrans, gott, optstrans); diff != "" { t.Fatalf("Transaction mismatch (-want +got):\n%s", diff) From d2b76e7dd3100becbbe576e69e26f4712ce9b5c9 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Fri, 4 Apr 2025 15:27:36 +0200 Subject: [PATCH 4/9] wip --- fasthttp/sentryfasthttp_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fasthttp/sentryfasthttp_test.go b/fasthttp/sentryfasthttp_test.go index 44bd19c83..a9c6faedb 100644 --- a/fasthttp/sentryfasthttp_test.go +++ b/fasthttp/sentryfasthttp_test.go @@ -121,7 +121,8 @@ func TestIntegration(t *testing.T) { Op: "http.server", Status: sentry.SpanStatusOK, }.Map(), - }}, + }, + }, }, { Path: "/get", @@ -164,7 +165,8 @@ func TestIntegration(t *testing.T) { Op: "http.server", Status: sentry.SpanStatusOK, }.Map(), - }}, + }, + }, }, { Path: "/post/large", @@ -212,7 +214,8 @@ func TestIntegration(t *testing.T) { Op: "http.server", Status: sentry.SpanStatusOK, }.Map(), - }}, + }, + }, }, { Path: "/post/body-ignored", @@ -261,7 +264,8 @@ func TestIntegration(t *testing.T) { Op: "http.server", Status: sentry.SpanStatusOK, }.Map(), - }}, + }, + }, }, { Path: "/post/error-handler", @@ -312,7 +316,8 @@ func TestIntegration(t *testing.T) { Op: "http.server", Status: sentry.SpanStatusOK, }.Map(), - }}, + }, + }, }, } From d4b1fc16a65a7458987d0aff0f0902e4185ae7db Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Fri, 4 Apr 2025 15:43:19 +0200 Subject: [PATCH 5/9] wip --- fasthttp/sentryfasthttp_test.go | 7 ++-- fiber/sentryfiber_test.go | 68 ++++++++++++++------------------- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/fasthttp/sentryfasthttp_test.go b/fasthttp/sentryfasthttp_test.go index a9c6faedb..5600c42d3 100644 --- a/fasthttp/sentryfasthttp_test.go +++ b/fasthttp/sentryfasthttp_test.go @@ -424,12 +424,13 @@ func TestIntegration(t *testing.T) { close(transactionsCh) var gotTransactions []*sentry.Event - var statusCodes []sentry.SpanStatus + var gotCodes []sentry.SpanStatus for e := range transactionsCh { gotTransactions = append(gotTransactions, e) - statusCodes = append(statusCodes, e.Contexts["trace"]["status"].(sentry.SpanStatus)) + gotCodes = append(gotCodes, e.Contexts["trace"]["status"].(sentry.SpanStatus)) } + optstrans := cmp.Options{ cmpopts.IgnoreFields( sentry.Event{}, @@ -469,7 +470,7 @@ func TestIntegration(t *testing.T) { t.Fatalf("Transactions mismatch (-want +gotEvents):\n%s", diff) } - if diff := cmp.Diff(wantCodes, statusCodes, cmp.Options{}); diff != "" { + if diff := cmp.Diff(wantCodes, gotCodes, cmp.Options{}); diff != "" { t.Fatalf("Transaction status codes mismatch (-want +got):\n%s", diff) } diff --git a/fiber/sentryfiber_test.go b/fiber/sentryfiber_test.go index 2504b40b5..9518744bc 100644 --- a/fiber/sentryfiber_test.go +++ b/fiber/sentryfiber_test.go @@ -6,7 +6,6 @@ import ( "fmt" "net/http" "reflect" - "strconv" "strings" "testing" "time" @@ -71,18 +70,17 @@ func TestIntegration(t *testing.T) { }) tests := []struct { - Path string - Method string - Body string - WantStatus int - + Path string + Method string + Body string + WantStatus int WantEvent *sentry.Event WantTransaction *sentry.Event }{ { Path: "/panic", Method: "GET", - WantStatus: http.StatusOK, + WantStatus: 200, WantEvent: &sentry.Event{ Level: sentry.LevelFatal, Message: "test", @@ -107,7 +105,7 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ @@ -124,7 +122,7 @@ func TestIntegration(t *testing.T) { Path: "/post", Method: "POST", Body: "payload", - WantStatus: http.StatusOK, + WantStatus: 200, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, Message: "post: payload", @@ -153,11 +151,11 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodPost, + "http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -169,7 +167,7 @@ func TestIntegration(t *testing.T) { { Path: "/get", Method: "GET", - WantStatus: http.StatusOK, + WantStatus: 200, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, @@ -195,7 +193,7 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ @@ -211,7 +209,7 @@ func TestIntegration(t *testing.T) { { Path: "/get/123", Method: "GET", - WantStatus: http.StatusOK, + WantStatus: 200, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, Message: "get: 123", @@ -236,7 +234,7 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ @@ -252,7 +250,7 @@ func TestIntegration(t *testing.T) { { Path: "/post/large", Method: "POST", - WantStatus: http.StatusOK, + WantStatus: 200, Body: largePayload, WantEvent: &sentry.Event{ Level: sentry.LevelInfo, @@ -283,11 +281,11 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodPost, + "http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -298,7 +296,7 @@ func TestIntegration(t *testing.T) { }, { Path: "/post/body-ignored", - WantStatus: http.StatusOK, + WantStatus: 200, Method: "POST", Body: "client sends, fiber always reads, SDK reports", @@ -330,11 +328,11 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodPost, + "http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -346,7 +344,7 @@ func TestIntegration(t *testing.T) { { Path: "/post/error-handler", Method: "POST", - WantStatus: http.StatusOK, + WantStatus: 200, WantEvent: &sentry.Event{ Level: sentry.LevelError, @@ -379,11 +377,11 @@ func TestIntegration(t *testing.T) { "Content-Length": "0", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "url"}, + TransactionInfo: &sentry.TransactionInfo{Source: "route"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodPost, + "http.request.method": http.MethodGet, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -422,16 +420,13 @@ func TestIntegration(t *testing.T) { t.Fatal(err) } - var wantEvents, gotEvents []*sentry.Event - var wantTransactions, gotTransactions []*sentry.Event - var wantCodes, gotCodes []sentry.SpanStatus - + var wantEvents []*sentry.Event + var wantTransactions []*sentry.Event + var wantCodes []sentry.SpanStatus for _, tt := range tests { wantEvents = append(wantEvents, tt.WantEvent) wantTransactions = append(wantTransactions, tt.WantTransaction) - wantCodes = append(wantCodes, sentry.HTTPtoSpanStatus(tt.WantStatus)) - req, err := http.NewRequest(tt.Method, "http://example.com"+tt.Path, strings.NewReader(tt.Body)) if err != nil { t.Fatal(err) @@ -452,6 +447,7 @@ func TestIntegration(t *testing.T) { } close(eventsCh) + var gotEvents []*sentry.Event for e := range eventsCh { gotEvents = append(gotEvents, e) } @@ -477,18 +473,12 @@ func TestIntegration(t *testing.T) { } close(transactionsCh) + var gotTransactions []*sentry.Event + var gotCodes []sentry.SpanStatus for e := range transactionsCh { - for k, v := range e.Extra { - if k != "http.response.status_code" { - continue - } - f, _ := v.(float64) - e.Extra[k] = int(f) - } gotTransactions = append(gotTransactions, e) - gotCode, _ := strconv.Atoi(e.Contexts["trace"]["status"].(string)) - gotCodes = append(gotCodes, sentry.HTTPtoSpanStatus(gotCode)) + gotCodes = append(gotCodes, e.Contexts["trace"]["status"].(sentry.SpanStatus)) } optstrans := cmp.Options{ From 506e3b75a36102819c4ed4b0f33000da8c6301ef Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 7 Apr 2025 12:49:25 +0200 Subject: [PATCH 6/9] wip --- http/sentryhttp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/sentryhttp_test.go b/http/sentryhttp_test.go index b53046729..9e9928115 100644 --- a/http/sentryhttp_test.go +++ b/http/sentryhttp_test.go @@ -387,7 +387,7 @@ func TestIntegration(t *testing.T) { "Release", "Sdk", "ServerName", "Timestamp", "sdkMetaData", "StartTime", "Spans", ), - cmpopts.IgnoreMapEntries(func(k string, v any) bool { + cmpopts.IgnoreMapEntries(func(k string, _ any) bool { ignoredCtxEntries := []string{"span_id", "trace_id", "device", "os", "runtime"} for _, e := range ignoredCtxEntries { if k == e { From 54cb5c3c54088f97f856a3630e51b1319d0a3b88 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 7 Apr 2025 13:14:45 +0200 Subject: [PATCH 7/9] wip --- fiber/sentryfiber_test.go | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/fiber/sentryfiber_test.go b/fiber/sentryfiber_test.go index 9518744bc..842215e57 100644 --- a/fiber/sentryfiber_test.go +++ b/fiber/sentryfiber_test.go @@ -1,7 +1,6 @@ package sentryfiber_test import ( - "encoding/json" "errors" "fmt" "net/http" @@ -105,7 +104,7 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ @@ -151,11 +150,11 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodGet, + "http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -193,7 +192,7 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ @@ -234,7 +233,7 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ @@ -281,11 +280,11 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodGet, + "http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -328,11 +327,11 @@ func TestIntegration(t *testing.T) { "User-Agent": "fiber", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodGet, + "http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -377,11 +376,11 @@ func TestIntegration(t *testing.T) { "Content-Length": "0", }, }, - TransactionInfo: &sentry.TransactionInfo{Source: "route"}, + TransactionInfo: &sentry.TransactionInfo{Source: "url"}, Contexts: map[string]sentry.Context{ "trace": sentry.TraceContext{ Data: map[string]interface{}{ - "http.request.method": http.MethodGet, + "http.request.method": http.MethodPost, "http.response.status_code": http.StatusOK, }, Op: "http.server", @@ -394,7 +393,6 @@ func TestIntegration(t *testing.T) { eventsCh := make(chan *sentry.Event, len(tests)) transactionsCh := make(chan *sentry.Event, len(tests)) - err := sentry.Init(sentry.ClientOptions{ EnableTracing: true, TracesSampleRate: 1.0, @@ -403,16 +401,7 @@ func TestIntegration(t *testing.T) { return event }, BeforeSendTransaction: func(tx *sentry.Event, hint *sentry.EventHint) *sentry.Event { - // Deep copy the transaction - jsonStr, err := json.Marshal(tx) - if err != nil { - t.Fatal(err) - } - var cpTx sentry.Event - if err := json.Unmarshal(jsonStr, &cpTx); err != nil { - t.Fatal(err) - } - transactionsCh <- &cpTx + transactionsCh <- tx return tx }, }) From d3dfb02fac24f6d2af6b73458c25931d12bd109e Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 7 Apr 2025 13:22:55 +0200 Subject: [PATCH 8/9] wip --- tracing.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tracing.go b/tracing.go index 789d4c825..50439e30e 100644 --- a/tracing.go +++ b/tracing.go @@ -38,20 +38,22 @@ const ( // // Spans must be started with either StartSpan or Span.StartChild. type Span struct { //nolint: maligned // prefer readability over optimal memory layout (see note below *) - TraceID TraceID `json:"trace_id"` - SpanID SpanID `json:"span_id"` - ParentSpanID SpanID `json:"parent_span_id"` - Name string `json:"name,omitempty"` - Op string `json:"op,omitempty"` - Description string `json:"description,omitempty"` - Status SpanStatus `json:"status,omitempty"` - Tags map[string]string `json:"tags,omitempty"` - StartTime time.Time `json:"start_timestamp"` - EndTime time.Time `json:"timestamp"` - Data map[string]interface{} `json:"data,omitempty"` - Sampled Sampled `json:"-"` - Source TransactionSource `json:"-"` - Origin SpanOrigin `json:"origin,omitempty"` + TraceID TraceID `json:"trace_id"` + SpanID SpanID `json:"span_id"` + ParentSpanID SpanID `json:"parent_span_id"` + Name string `json:"name,omitempty"` + Op string `json:"op,omitempty"` + Description string `json:"description,omitempty"` + Status SpanStatus `json:"status,omitempty"` + Tags map[string]string `json:"tags,omitempty"` + StartTime time.Time `json:"start_timestamp"` + EndTime time.Time `json:"timestamp"` + // Deprecated, use Data instead. To be removed in 0.33.0 + Extra map[string]interface{} `json:"-"` + Data map[string]interface{} `json:"data,omitempty"` + Sampled Sampled `json:"-"` + Source TransactionSource `json:"-"` + Origin SpanOrigin `json:"origin,omitempty"` // mu protects concurrent writes to map fields mu sync.RWMutex From de309ba9a82a2670f3ec9ba4a7771a6d1f2e66cc Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 7 Apr 2025 13:24:15 +0200 Subject: [PATCH 9/9] wip --- tracing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing.go b/tracing.go index 50439e30e..d0b748466 100644 --- a/tracing.go +++ b/tracing.go @@ -48,7 +48,7 @@ type Span struct { //nolint: maligned // prefer readability over optimal memory Tags map[string]string `json:"tags,omitempty"` StartTime time.Time `json:"start_timestamp"` EndTime time.Time `json:"timestamp"` - // Deprecated, use Data instead. To be removed in 0.33.0 + // Deprecated: use Data instead. To be removed in 0.33.0 Extra map[string]interface{} `json:"-"` Data map[string]interface{} `json:"data,omitempty"` Sampled Sampled `json:"-"`