feat(tracing): Add utils for OpenTelemetry tracing and event logging

This commit is contained in:
SoXX 2024-08-12 11:15:34 +02:00
parent 505bc3b522
commit 9512cd10bc

20
internal/utils/tracing.go Normal file
View File

@ -0,0 +1,20 @@
package utils
import (
"context"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/trace"
)
func SetupTracing(ctx context.Context, tracer trace.Tracer, tracerName string) (context.Context, trace.Span, *log.Entry) {
ctx, span := tracer.Start(ctx, tracerName)
localLogger := log.WithContext(ctx)
return ctx, span, localLogger
}
func HandleEvent(span trace.Span, logger *log.Entry, eventName string) {
logger.Debug(eventName)
span.AddEvent(eventName)
}