functions-framework-go
functions-framework-go copied to clipboard
Expose trace IDs in background and cloud event functions
The X-Cloud-Trace-Context header is included in requests, but as we don't expose headers to the event-style functions it is inaccessible. This value is the only means of grouping StackDriver logs by request, and so we should expose it to the user function code.
Background events: The trace ID should be available in the context parameter.
CloudEvents: The trace ID should be encoded as an extension on the event, leveraging the traceparent extension field as described in https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md.
Have any progress been made on this issue? Our ability to correlate logs between cloud functions and our other services are severely impaired due to this header not being exposed to us.
Also wondering about this, it would be greatly beneficial to have this.
I believe the CESDK should already support this, after you inject the tracing extension.
Very rough code below:
import (
otelObs "github.com/cloudevents/sdk-go/observability/opentelemetry/v2/client"
)
const (
TraceParentExtension = "traceparent"
TraceStateExtension = "tracestate"
)
// DistributedTracingExtension represents the extension for cloudevents context
type DistributedTracingExtension struct {
TraceParent string `json:"traceparent"`
TraceState string `json:"tracestate"`
}
func main() {
registry.RegisterCloudEvent("cefn", func(ctx context.Context, event cloudevents.Event) error {
otelObs.InjectDistributedTracingExtension(ctx, event)
fmt.Print(event.Extensions()[TraceParentExtension])
return nil
})
}
- https://github.com/cloudevents/sdk-go/blob/main/v2/extensions/distributed_tracing_extension.go
- https://github.com/d7561985/protonats/blob/44319ea8f497ae739cc91bb72ad99ee65113be44/cloudevents_carrier.go#L25