Skip to content

Commit

Permalink
feat: add sentryx.StartSpan method (#50)
Browse files Browse the repository at this point in the history
This is a handy method that ensures the context passed to StartSpan can
be overrided with span.Context. Using span.Context is required to make
new span children of the first span.
  • Loading branch information
tbruyelle authored Apr 27, 2022
1 parent 52c5d7d commit d3aef17
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sentryx/sentryx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sentryx

import (
"context"

"github.com/getsentry/sentry-go"
)

// StartSpan calls sentry.StartSpan and returns the span and the span context.
// This is handy to ensure correct hierarchy of span if other spans are started
// after this one. Indeed you need to use the span.Context() to start a child
// span. Recommanded usage is:
//
// span, ctx := sentryx.StartSpan(ctx, "operation")
// defer span.Finish()
func StartSpan(ctx context.Context, operation string, options ...sentry.SpanOption) (*sentry.Span, context.Context) {
s := sentry.StartSpan(ctx, operation, options...)
return s, s.Context()
}

0 comments on commit d3aef17

Please sign in to comment.