From a963cd002dfe6b975384defabbf24c37b231d4d1 Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Wed, 2 Aug 2023 11:34:09 -0300 Subject: [PATCH 1/4] change fork name --- go.mod | 2 +- otel/go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index ba844a7e5..bce2ce3d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/getsentry/sentry-go +module github.com/vtfr/sentry-go go 1.18 diff --git a/otel/go.mod b/otel/go.mod index 08771b455..9127b90e7 100644 --- a/otel/go.mod +++ b/otel/go.mod @@ -1,4 +1,4 @@ -module github.com/getsentry/sentry-go/otel +module github.com/vtfr/sentry-go/otel go 1.18 From 4240d04623abc9a17c709d1031b67353de0cea1e Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Mon, 7 Aug 2023 14:04:44 -0300 Subject: [PATCH 2/4] initial support for capturing otel event --- otel/span_processor.go | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/otel/span_processor.go b/otel/span_processor.go index 8b64d9dd0..e9c6b0d8b 100644 --- a/otel/span_processor.go +++ b/otel/span_processor.go @@ -4,6 +4,7 @@ package sentryotel import ( "context" + semconv "go.opentelemetry.io/otel/semconv/v1.12.0" "time" "github.com/getsentry/sentry-go" @@ -76,6 +77,9 @@ func (ssp *sentrySpanProcessor) OnEnd(s otelSdkTrace.ReadOnlySpan) { sentrySpanMap.Delete(otelSpanId) return } + sentrySpan.Context() + + processEvents(sentrySpan, s) if sentrySpan.IsTransaction() { updateTransactionWithOtelData(sentrySpan, s) @@ -101,6 +105,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? From 71a632e79f8fd278328da5934a4c21f734669765 Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Mon, 7 Aug 2023 14:05:35 -0300 Subject: [PATCH 3/4] Revert "change fork name" This reverts commit a963cd002dfe6b975384defabbf24c37b231d4d1. --- go.mod | 2 +- otel/go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index bce2ce3d3..ba844a7e5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/vtfr/sentry-go +module github.com/getsentry/sentry-go go 1.18 diff --git a/otel/go.mod b/otel/go.mod index 9127b90e7..08771b455 100644 --- a/otel/go.mod +++ b/otel/go.mod @@ -1,4 +1,4 @@ -module github.com/vtfr/sentry-go/otel +module github.com/getsentry/sentry-go/otel go 1.18 From e3346bb72e5dc5a118323ad8bd4ada38bb9d7eb8 Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Mon, 7 Aug 2023 14:06:43 -0300 Subject: [PATCH 4/4] remove unused variable --- otel/span_processor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/otel/span_processor.go b/otel/span_processor.go index e9c6b0d8b..5342bc085 100644 --- a/otel/span_processor.go +++ b/otel/span_processor.go @@ -77,7 +77,6 @@ func (ssp *sentrySpanProcessor) OnEnd(s otelSdkTrace.ReadOnlySpan) { sentrySpanMap.Delete(otelSpanId) return } - sentrySpan.Context() processEvents(sentrySpan, s)