Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: [OTel] Support for events and exceptions generated via trace.Span #690

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions otel/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package sentryotel

import (
"context"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
"time"

"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -77,6 +78,8 @@ func (ssp *sentrySpanProcessor) OnEnd(s otelSdkTrace.ReadOnlySpan) {
return
}

processEvents(sentrySpan, s)

if sentrySpan.IsTransaction() {
updateTransactionWithOtelData(sentrySpan, s)
} else {
Expand All @@ -101,6 +104,57 @@ func (ssp *sentrySpanProcessor) ForceFlush(ctx context.Context) error {
return flushSpanProcessor(ctx)
}

func processEvents(sentrySpan *sentry.Span, s otelSdkTrace.ReadOnlySpan) {
ctx := sentrySpan.Context()

hub := sentry.GetHubFromContext(ctx)
if hub == nil {
hub = sentry.CurrentHub()
}

for _, event := range s.Events() {
sentryEvent := sentry.NewEvent()
sentryEvent.Timestamp = event.Time

switch event.Name {
case semconv.ExceptionEventName:
sentryEvent.Level = sentry.LevelError

var exceptionType string
var exceptionMessage string
//var exceptionStacktrace string

for _, kv := range event.Attributes {
switch kv.Key {
case semconv.ExceptionTypeKey:
exceptionType = kv.Value.Emit()
case semconv.ExceptionMessageKey:
exceptionMessage = kv.Value.Emit()
// case semconv.ExceptionStacktraceKey:
// exceptionStacktrace = kv.Value.Emit()
}
}

// todo(vtfr): Parse the exceptionStacktrace into an []sentry.Exception
sentryEvent.Message = exceptionMessage
sentryEvent.Exception = []sentry.Exception{
{
Type: exceptionType,
Value: exceptionMessage,
},
}
default:
// todo(vtfr): Check for attributes for setting the level
sentryEvent.Level = sentry.LevelInfo
sentryEvent.Message = event.Name
}

hub.Client().CaptureEvent(sentryEvent, &sentry.EventHint{
Context: ctx,
}, nil)
}
}

func flushSpanProcessor(ctx context.Context) error {
hub := sentry.GetHubFromContext(ctx)
// TODO(michi) should we make this configurable?
Expand Down
Loading