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

Update OTLP auth example #803

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

damemi
Copy link
Contributor

@damemi damemi commented Feb 16, 2024

Add x-goog-user-project header and set gcp.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

@damemi damemi requested a review from a team as a code owner February 16, 2024 20:09
Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.73%. Comparing base (babed48) to head (5123ea8).

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.
📢 Have feedback on the report? Share it here.

@damemi damemi changed the title (wip) Update OTLP auth example Update OTLP auth example Feb 16, 2024
@damemi
Copy link
Contributor Author

damemi commented Feb 23, 2024

Updated this to add an http sample too, going to merge if everything is green

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}))
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

@damemi damemi merged commit 87124ac into GoogleCloudPlatform:main Feb 23, 2024
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants