2024-08-12 09:15:34 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
)
|
|
|
|
|
2024-08-13 08:54:21 +00:00
|
|
|
// SetupTracing initializes a new trace span and logger for the given context and tracer.
|
2024-08-12 09:15:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-08-13 08:54:21 +00:00
|
|
|
// HandleEvent logs the provided event name and adds it to the given trace span.
|
2024-08-12 09:15:34 +00:00
|
|
|
func HandleEvent(span trace.Span, logger *log.Entry, eventName string) {
|
|
|
|
logger.Debug(eventName)
|
|
|
|
span.AddEvent(eventName)
|
|
|
|
}
|