-
Notifications
You must be signed in to change notification settings - Fork 103
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
Update OTLP auth example #803
Update OTLP auth example #803
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #803 +/- ##
==========================================
- Coverage 60.80% 60.73% -0.08%
==========================================
Files 56 56
Lines 5649 5649
==========================================
- Hits 3435 3431 -4
- Misses 2066 2070 +4
Partials 148 148 ☔ View full report in Codecov by Sentry. |
0f22764
to
bf8e8ad
Compare
bf8e8ad
to
341dc95
Compare
341dc95
to
2f416c2
Compare
Updated this to add an http sample too, going to merge if everything is green |
example/trace/otlpgrpc/example.go
Outdated
res := resource.NewWithAttributes(semconv.SchemaURL, attribute.String("gcp.project_id", projectID)) | ||
|
||
// set endpoint with OTEL_EXPORTER_OTLP_ENDPOINT=https://<endpoint> | ||
exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithDialOption(grpc.WithPerRPCCredentials(creds)), otlptracegrpc.WithHeaders(map[string]string{"x-goog-user-project": projectID})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we tell users to use OTEL_EXPORTER_OTLP_HEADERS instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, using the env vars should be fine. One thing though is the Authorization header in the http example. You could do something like set it in the env var with Authorization: Bearer $(gcloud auth print-access-token)
but I think getting that programmatically is probably better. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will still need to get credentials programmatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This took some digging, but it looks like WithHeaders
overwrites OTEL_EXPORTER_OTLP_HEADERS (couldn't find docs but I found a test asserting it, and I couldn't get it to work with both)
So if we pass Authorization using WithHeaders, we also need the other headers that way too. Unless they can be merged somehow
Add
x-goog-user-project
header and setgcp.project_id
(not sure if that needs to be a span attribute or resource attribute, so I'm setting both for now)Repro steps:
gcloud auth application-default login
export OTEL_EXPORTER_OTLP_ENDPOINT=otlp://<endpoint>
export GCLOUD_PROJECT=<project id>
go run example.go