Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose trace IDs in background and cloud event functions #42

Open
roffjulie opened this issue Aug 13, 2020 · 3 comments
Open

Expose trace IDs in background and cloud event functions #42

roffjulie opened this issue Aug 13, 2020 · 3 comments
Labels
enhancement New feature or request P3 Low Priority

Comments

@roffjulie
Copy link
Contributor

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.

@ericwenn
Copy link

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.

@jrmeinride
Copy link

Also wondering about this, it would be greatly beneficial to have this.

@grant
Copy link
Contributor

grant commented Dec 9, 2021

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
	})
}

@josephlewis42 josephlewis42 added enhancement New feature or request P3 Low Priority labels Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P3 Low Priority
Projects
None yet
Development

No branches or pull requests

5 participants