diff --git a/http/sentryhttp.go b/http/sentryhttp.go index b2a7351cf..86c5df380 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -92,7 +92,7 @@ func (h *Handler) handle(handler http.Handler) http.HandlerFunc { } // We don't mind getting an existing transaction back so we don't need to // check if it is. - transaction, _ := sentry.StartTransaction(ctx, + transaction := sentry.StartTransaction(ctx, fmt.Sprintf("%s %s", r.Method, r.URL.Path), options..., ) diff --git a/tracing.go b/tracing.go index 4af7e5308..77666d4b5 100644 --- a/tracing.go +++ b/tracing.go @@ -636,11 +636,10 @@ func spanFromContext(ctx context.Context) *Span { // StartTransaction will create a transaction (root span) if there's no existing // transaction in the context otherwise, it will return the existing transaction. -// The boolean indicates if it returned the existing transaction or not. -func StartTransaction(ctx context.Context, name string, options ...SpanOption) (*Span, bool) { - currentTransaction := ctx.Value(spanContextKey{}) - if currentTransaction != nil { - return currentTransaction.(*Span), true +func StartTransaction(ctx context.Context, name string, options ...SpanOption) *Span { + currentTransaction, exists := ctx.Value(spanContextKey{}).(*Span) + if exists { + return currentTransaction } hub := GetHubFromContext(ctx) if hub == nil { @@ -652,5 +651,5 @@ func StartTransaction(ctx context.Context, name string, options ...SpanOption) ( ctx, "", options..., - ), false + ) } diff --git a/tracing_test.go b/tracing_test.go index f5fb6f4bd..347a6dded 100644 --- a/tracing_test.go +++ b/tracing_test.go @@ -240,7 +240,7 @@ func TestStartTransaction(t *testing.T) { data := map[string]interface{}{ "k": "v", } - transaction, _ := StartTransaction(ctx, + transaction := StartTransaction(ctx, transactionName, func(s *Span) { s.Description = description @@ -298,20 +298,6 @@ func TestStartTransaction(t *testing.T) { } } -func TestStartTransactionAlreadyInProgress(t *testing.T) { - transport := &TransportMock{} - ctx := NewTestContext(ClientOptions{ - Transport: transport, - }) - // Simulate a transaction already in progress - ctx = context.WithValue(ctx, spanContextKey{}, &Span{}) - transactionName := "Test Transaction" - _, existing := StartTransaction(ctx, transactionName) - if !existing { - t.Fatal("StartTransaction should return true if a transaction is already in progress") - } -} - // testContextKey is used to store a value in a context so that we can check // that SDK operations on that context preserve the original context values. type testContextKey struct{}