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

How to update headers in StableOtlpHTTPMetricExporter? #650

Open
JustasL opened this issue Dec 4, 2024 · 9 comments
Open

How to update headers in StableOtlpHTTPMetricExporter? #650

JustasL opened this issue Dec 4, 2024 · 9 comments

Comments

@JustasL
Copy link

JustasL commented Dec 4, 2024

Hello, is there are way to update StableOtlpHTTPMetricExporter headers after it has been setup?

We want to provide authorisation token, which can expire, and will need to be updated in the future
But at the moment it seems headers can only be setup during init?

@n-ravichandran
Copy link

I am unclear about their recommended approach for including the auth token in the header while using their exporter. Their exporter includes a URLSession parameter, so you could accomplish this by supplying a URLSession object that employs a custom URLProtocol to intercept requests. Within the interceptor protocol class, you can alter the request header to include the auth token. If your auth token has expired, you can also perform a token refresh there and continue the request with the new token.

@JustasL
Copy link
Author

JustasL commented Dec 5, 2024

Thanks, I'll give it a try, but it looks a little bit overcomplicated solution to simple issue

@bryce-b
Copy link
Member

bryce-b commented Dec 5, 2024

@JustasL
You can pass headers to any of the Exporters through the OtlpConfiguration object as the config parameter in the initializer method.

@bryce-b bryce-b closed this as completed Dec 5, 2024
@JustasL
Copy link
Author

JustasL commented Dec 5, 2024

@bryce-b yeah, but it is constant, I can not update headers after the token has expired and has been updated

@bryce-b bryce-b reopened this Dec 9, 2024
@bryce-b
Copy link
Member

bryce-b commented Dec 9, 2024

Would it be possible to re-create the exporter when you need to refresh the headers?
This will probably provide the quickest resolution for you, while we sort out a structural change that can accommodate this usage.

@JustasL
Copy link
Author

JustasL commented Dec 9, 2024

I've chosen to go with custom URLProtocol where I override each request by adding auth header (as suggested by @n-ravichandran)
Should be fine for now, although for longer term I guess headers should be allowed to passed as a closure, like it's done on Android

@bryce-b
Copy link
Member

bryce-b commented Dec 9, 2024

@JustasL I'm having trouble finding where android provides a means to update the headers, could you share it?

@bryce-b
Copy link
Member

bryce-b commented Dec 9, 2024

refined issue: #651

@JustasL
Copy link
Author

JustasL commented Dec 10, 2024

My android colleague is using this method

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

No branches or pull requests

3 participants