forked from smallstep/certificates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b78e306
commit 7658697
Showing
3 changed files
with
47 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package monitoring | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/getsentry/sentry-go" | ||
) | ||
|
||
type sentryTrace struct{} | ||
type sentryBaggage struct{} | ||
|
||
func WrapSentryTrace(ctx context.Context) (context.Context, *sentry.Hub) { | ||
hub := sentry.GetHubFromContext(ctx) | ||
if hub == nil { | ||
hub = sentry.CurrentHub().Clone() | ||
} | ||
span := sentry.SpanFromContext(ctx) | ||
ctx = context.Background() | ||
ctx = sentry.SetHubOnContext(ctx, hub) | ||
if span != nil { | ||
ctx = context.WithValue(ctx, sentryTrace{}, span.ToSentryTrace()) | ||
ctx = context.WithValue(ctx, sentryBaggage{}, span.ToBaggage()) | ||
} | ||
return ctx, hub | ||
} | ||
|
||
func GetSpanOptions(ctx context.Context) []sentry.SpanOption { | ||
var opts []sentry.SpanOption | ||
trace, okTrace := ctx.Value(sentryTrace{}).(string) | ||
baggage, okBaggage := ctx.Value(sentryBaggage{}).(string) | ||
if okTrace && okBaggage { | ||
opts = append(opts, sentry.ContinueFromHeaders(trace, baggage)) | ||
} | ||
return opts | ||
} |