From f13c84aa003407d054476b2c288393f6c730a7fb Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 4 Sep 2024 09:22:59 +0200 Subject: [PATCH] cleanup --- hub.go | 22 -------------- hub_test.go | 84 ----------------------------------------------------- 2 files changed, 106 deletions(-) diff --git a/hub.go b/hub.go index 358e712f..c99b6d70 100644 --- a/hub.go +++ b/hub.go @@ -366,28 +366,6 @@ func (hub *Hub) Flush(timeout time.Duration) bool { return client.Flush(timeout) } -// Continue a trace based on HTTP header values. If performance is enabled this -// returns a SpanOption that can be used to start a transaction, otherwise nil. -// TODO: remove - moved to tracing.go. -func (hub *Hub) ContinueTrace(trace, baggage string) (SpanOption, error) { - scope := hub.Scope() - propagationContext, err := PropagationContextFromHeaders(trace, baggage) - if err != nil { - return nil, err - } - - scope.SetPropagationContext(propagationContext) - - client := hub.Client() - if client != nil && client.options.EnableTracing { - return ContinueFromHeaders(trace, baggage), nil - } - - scope.SetContext("trace", propagationContext.Map()) - - return nil, nil -} - // GetTraceparent returns the current Sentry traceparent string, to be used as a HTTP header value // or HTML meta tag value. // This function is context aware, as in it either returns the traceparent based diff --git a/hub_test.go b/hub_test.go index 59c56f44..0b306a0a 100644 --- a/hub_test.go +++ b/hub_test.go @@ -2,7 +2,6 @@ package sentry import ( "context" - "errors" "fmt" "strings" "sync" @@ -10,7 +9,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stretchr/testify/assert" ) const testDsn = "http://whatever@example.com/1337" @@ -327,88 +325,6 @@ func TestHasHubOnContextReturnsFalseIfHubIsNotThere(t *testing.T) { assertEqual(t, false, HasHubOnContext(ctx)) } -func TestHub_ContinueTrace(t *testing.T) { - newScope := func() *Scope { - return &Scope{contexts: make(map[string]Context)} - } - - mockClient := &Client{options: ClientOptions{EnableTracing: true}} - - tests := map[string]struct { - hub *Hub - trace string - baggage string - expectedErr error - expectedSpan bool // Whether a SpanOption is expected to be returned - checkScope func(t *testing.T, scope *Scope) // Additional checks on the scope - }{ - "Valid trace and baggage": { - hub: NewHub(mockClient, newScope()), - trace: "4fbfb1b884c8532962a3c0b7b834428e-a9f442f9330b4e09", - baggage: "sentry-release=1.0.0,sentry-environment=production", - expectedErr: nil, - expectedSpan: true, - checkScope: func(t *testing.T, scope *Scope) { - assert.Equal(t, "4fbfb1b884c8532962a3c0b7b834428e", scope.propagationContext.TraceID.String()) - }, - }, - "Invalid trace": { - hub: NewHub(mockClient, newScope()), - trace: "invalid", - baggage: "sentry-release=1.0.0,sentry-environment=production", - expectedErr: nil, - expectedSpan: true, - checkScope: func(t *testing.T, scope *Scope) { - assert.NotEmpty(t, scope.propagationContext.TraceID.String()) - }, - }, - "Invalid baggage": { - hub: NewHub(mockClient, newScope()), - trace: "4fbfb1b884c8532962a3c0b7b834428e-a9f442f9330b4e09", - baggage: "invalid_baggage", - expectedErr: errors.New("invalid baggage list-member: \"invalid_baggage\""), - expectedSpan: false, - checkScope: func(t *testing.T, scope *Scope) { - assert.Equal(t, "00000000000000000000000000000000", scope.propagationContext.TraceID.String()) - }, - }, - "Tracing not enabled": { - hub: NewHub(&Client{options: ClientOptions{EnableTracing: false}}, newScope()), - trace: "4fbfb1b884c8532962a3c0b7b834428e-a9f442f9330b4e09", - baggage: "sentry-release=1.0.0,sentry-environment=production", - expectedErr: nil, - expectedSpan: false, - checkScope: func(t *testing.T, scope *Scope) { - assert.Equal(t, "4fbfb1b884c8532962a3c0b7b834428e", scope.propagationContext.TraceID.String()) - assert.Contains(t, scope.contexts, "trace") - }, - }, - } - - for name, tt := range tests { - t.Run(name, func(t *testing.T) { - opt, err := tt.hub.ContinueTrace(tt.trace, tt.baggage) - - if tt.expectedErr != nil { - assert.Error(t, err, "expected error, got nil") - assert.Equal(t, tt.expectedErr.Error(), err.Error()) - } else { - assert.NoError(t, err, "expected no error, got one") - } - - // Check for expected SpanOption - if tt.expectedSpan { - assert.NotNil(t, opt, "expected SpanOption, got nil") - } else { - assert.Nil(t, opt, "expected no SpanOption, got one") - } - - // Additional checks on the scope - tt.checkScope(t, tt.hub.Scope()) - }) - } -} - func TestGetTraceparent(t *testing.T) { tests := map[string]struct { hub *Hub