-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentry.go
55 lines (44 loc) · 1.52 KB
/
sentry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package tracing
import (
"github.com/getsentry/sentry-go"
"go.opencensus.io/trace"
)
const (
integrationName = "Tracing"
integrationContextNamespace = "trace"
)
type tracingIntegration struct {}
var Integration sentry.Integration = new(tracingIntegration)
func (ti *tracingIntegration) Name() string {
return integrationName
}
func (ti *tracingIntegration) SetupOnce(client *sentry.Client) {
client.AddEventProcessor(ti.processor)
}
func (ti *tracingIntegration) processor(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
if event.Contexts == nil {
event.Contexts = make(map[string]interface{})
}
if sp, ok := event.Extra[sentrySpanKey]; ok {
if span, ok := sp.(*trace.Span); ok {
var parent map[string]interface{}
if psc, ok := event.Extra[sentryParentSpanContextKey]; ok {
if psc, ok := psc.(trace.SpanContext); ok {
parent = map[string]interface{}{
"trace_id": psc.TraceID.String(),
"span_id": psc.SpanID.String(),
}
}
delete(event.Extra, sentryParentSpanContextKey)
}
sc := span.SpanContext()
event.Contexts[integrationContextNamespace] = map[string]interface{}{
"parent": parent,
"trace_id": sc.TraceID.String(),
"span_id": sc.SpanID.String(),
}
}
delete(event.Extra, sentrySpanKey)
}
return event
}