Skip to content

Commit

Permalink
Closes #854
Browse files Browse the repository at this point in the history
  • Loading branch information
far4599 committed Jul 9, 2024
1 parent dafeb07 commit 270bfca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ func SpanFromContext(ctx context.Context) *Span {
func StartTransaction(ctx context.Context, name string, options ...SpanOption) *Span {
currentTransaction, exists := ctx.Value(spanContextKey{}).(*Span)
if exists {
currentTransaction.ctx = ctx
return currentTransaction
}

Expand Down
21 changes: 21 additions & 0 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,27 @@ func TestStartTransaction(t *testing.T) {
}
}

func TestStartTransaction_with_context(t *testing.T) {
t.Run("get transaction from context", func(t *testing.T) {
tr := StartTransaction(context.TODO(), "")
ctx := tr.Context()
existingTr := StartTransaction(ctx, "")
if existingTr != tr {
t.Fatalf("existing transaction not found")
}
})

t.Run("get transaction with latest context", func(t *testing.T) {
tr := StartTransaction(context.TODO(), "")
ctx := context.WithValue(tr.Context(), "key", "value")

Check failure on line 332 in tracing_test.go

View workflow job for this annotation

GitHub Actions / Lint

context-keys-type: should not use basic type string as key in context.WithValue (revive)
existingTr := StartTransaction(ctx, "")
_, keyExists := existingTr.Context().Value("key").(string)
if !keyExists {
t.Fatalf("key not found in context")
}
})
}

func TestSetTag(t *testing.T) {
ctx := NewTestContext(ClientOptions{
EnableTracing: true,
Expand Down

0 comments on commit 270bfca

Please sign in to comment.