sdk-go
sdk-go copied to clipboard
Allow custom trace attribute keys
Is your feature request related to a problem? Please describe. Trace attribute keys are enforced by the Temporal SDK, and are as follow:
-
temporalWorkflowID
-
temporalRunID
-
temporalActivityID
Found here: https://github.com/temporalio/sdk-go/blob/master/interceptor/tracing_interceptor.go#L39-L43
The only way to customise those keys is to create our own implementation of interceptor.Interceptor
which is kind of heavy work to simply rename these keys.
Describe the solution you'd like
We could have the possibility to override the key values set by default in interceptor.TracerOptions
, and port these options to opentelemetry.TracerOptions
and opentracing.TracerOptions
.
Additional context Issue related to this thread on Slack
As discussed on Slack, here's a possible approach without having a custom interceptor.Interceptor
.
Create your own interceptor.Tracer
, and override the StartSpan
function:
type MyCustomTracer struct {
interceptor.Tracer
}
func (m MyCustomTracer) StartSpan(opts *interceptor.TracerStartSpanOptions) (interceptor.TracerSpan, error) {
if v := opts.Tags["temporalWorkflowID"]; v != "" {
opts.Tags["temporal.workflow.id"] = v
delete(opts.Tags, "temporalWorkflowID")
}
if v := opts.Tags["temporalRunID"]; v != "" {
opts.Tags["temporal.workflow.run_id"] = v
delete(opts.Tags, "temporalRunID")
}
if v := opts.Tags["temporalActivityID"]; v != "" {
opts.Tags["temporal.activity.id"] = v
delete(opts.Tags, "temporalActivityID")
}
return m.Tracer.StartSpan(opts)
}
Create a new tracer using the distribution of your choice, such as opentelemetry
. Then pass this tracer in interceptor.NewTracingInterceptor
:
otelTracer, err := opentelemetry.NewTracer(opentelemetry.TracerOptions{
// ...
})
customTracer := MyCustomTracer{
Tracer: otelTracer,
}
var opts = client.Options{
Interceptors: []interceptor.ClientInterceptor{
interceptor.NewTracingInterceptor(customTracer),
},
}
Leaving this issue open to let the Temporal decide if/how this should be documented or if another approach should be implemented.
+1 for this. We would like to inject additional attributes on our traces, and there doesn't seem to be a good way to do it. Even if we override StartSpan
as described in this comment (great idea, by the way), we'd like to include tags that we're storing on our context, but unfortunately the context is unavailable there.