From d3aef17a7ca35d72d3fd48756409447f3a9d4166 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 27 Apr 2022 10:51:23 +0200 Subject: [PATCH] feat: add sentryx.StartSpan method (#50) 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. --- sentryx/sentryx.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sentryx/sentryx.go diff --git a/sentryx/sentryx.go b/sentryx/sentryx.go new file mode 100644 index 0000000..2273c22 --- /dev/null +++ b/sentryx/sentryx.go @@ -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() +}