temporalio / sdk-go

Temporal Go SDK
https://docs.temporal.io/application-development?lang=go
MIT License
481 stars 197 forks source link

Make TraceID and SpanID logger keys configurable #1492

Closed PatrikValo closed 4 weeks ago

PatrikValo commented 1 month ago

Is your feature request related to a problem? Please describe. It would be nice to have an option to configure the logging keys for the tracing interceptor. Currently the keys are hardcoded and it makes it harder to keep the logging consistent with other components in my system. What do you think?

Describe the solution you'd like https://github.com/temporalio/sdk-go/blob/master/contrib/opentelemetry/tracing_interceptor.go

type TracerOptions struct {
        ...
        LoggingTraceIDKey string 
    LoggingSpanIDKey string
}

where by default LoggingTraceIDKey="TraceID", LoggingSpanIDKey="SpanID"

func (t *tracer) GetLogger(logger log.Logger, ref interceptor.TracerSpanRef) log.Logger {
    span, ok := ref.(*tracerSpan)
    if !ok {
        return logger
    }

    logger = log.With(logger,
        tracer.options.LoggingTraceIDKey, span.SpanContext().TraceID(),
        tracer.options.LoggingSpanIDKey, span.SpanContext().SpanID(),
    )

    return logger
}

or something similar to that.

Describe alternatives you've considered There is probably a workaround to create another interceptor which would basically does the same thing but it would use different keys and it would be responsible for mapping. So there would be all keys (default + custom).

Quinn-With-Two-Ns commented 1 month ago

All logging keys can also be changed by the logger implementation. If your using the standard library slog with our integration you can use ReplaceAttr in HandlerOptions to replace any key you want.

PatrikValo commented 4 weeks ago

Thanks!