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

support custom request header from env / config #970

Merged

Conversation

bkotsopoulossc
Copy link
Contributor

@bkotsopoulossc bkotsopoulossc commented Jun 2, 2021

closes: #308

As discussed in the issue above, there are use cases where being able to attach a custom header to every request is useful.

This introduces support for a new env var CUSTOM_HEADER, as well as a config block under defaults called custom_header, that allows you to specify a string that is added directly as a request header to all outgoing requests. Note that this is not a key/value pair - this expects the format key: value as a string.

Testing:

Uploading a lib somewhere where we don't have permission:

$ /docker-entrypoint.sh --log-level DEBUG upload-dif -o 31 -p my_proj /usr/lib/libssl.so.1.1
...
  DEBUG   2021-06-02 18:17:31.558003600 +00:00 > GET /api/0/organizations/31/chunk-upload/ HTTP/1.1
  DEBUG   2021-06-02 18:17:31.558079800 +00:00 > Host: sentry.io
  DEBUG   2021-06-02 18:17:31.558097 +00:00 > Accept: */*
  DEBUG   2021-06-02 18:17:31.558111100 +00:00 > Connection: TE
  DEBUG   2021-06-02 18:17:31.558121500 +00:00 > TE: gzip
  DEBUG   2021-06-02 18:17:31.558214100 +00:00 > User-Agent: sentry-cli/1.65.0
...

Setting the env var:

$ CUSTOM_HEADER="x-request-id: 12345" /docker-entrypoint.sh --log-level DEBUG upload-dif -o 31 -p my_proj /usr/lib/libssl.so.1.1
...
  DEBUG   2021-06-02 18:17:53.609051800 +00:00 > GET /api/0/organizations/31/chunk-upload/ HTTP/1.1
  DEBUG   2021-06-02 18:17:53.609131500 +00:00 > Host: sentry.io
  DEBUG   2021-06-02 18:17:53.609157300 +00:00 > Accept: */*
  DEBUG   2021-06-02 18:17:53.609178300 +00:00 > Connection: TE
  DEBUG   2021-06-02 18:17:53.609194300 +00:00 > TE: gzip
  DEBUG   2021-06-02 18:17:53.609216900 +00:00 > User-Agent: sentry-cli/1.65.0
  DEBUG   2021-06-02 18:17:53.609239700 +00:00 > x-request-id: 12345
...

Setting the config:

$ printf "[defaults]\ncustom_header = x-request-id: 987\n" > ~/.sentryclirc
$ cat ~/.sentryclirc 
[defaults]
custom_header = x-request-id: 987
$ /docker-entrypoint.sh --log-level DEBUG upload-dif -o 31 -p my_proj /usr/lib/libssl.so.1.1
...
  DEBUG   2021-06-02 18:21:21.663774700 +00:00 > GET /api/0/organizations/31/chunk-upload/ HTTP/1.1
  DEBUG   2021-06-02 18:21:21.663855700 +00:00 > Host: sentry.io
  DEBUG   2021-06-02 18:21:21.663881900 +00:00 > Accept: */*
  DEBUG   2021-06-02 18:21:21.663900500 +00:00 > Connection: TE
  DEBUG   2021-06-02 18:21:21.663916600 +00:00 > TE: gzip
  DEBUG   2021-06-02 18:21:21.663939400 +00:00 > User-Agent: sentry-cli/1.65.0
  DEBUG   2021-06-02 18:21:21.664017700 +00:00 > x-request-id: 987
...

PTAL @jan-auer @mitsuhiko

@jan-auer jan-auer requested a review from kamilogorek June 7, 2021 08:20
@kamilogorek
Copy link
Contributor

It's definitely not the perfect solution, but it'll enable more usecases, so +1 from me.

@kamilogorek
Copy link
Contributor

Documentation PR: getsentry/sentry-docs#3696

@bkotsopoulossc bkotsopoulossc deleted the support_custom_req_header branch June 7, 2021 15:20
@bkotsopoulossc
Copy link
Contributor Author

It's definitely not the perfect solution, but it'll enable more usecases, so +1 from me.

Agreed it's not perfect :) thanks for taking a look.

@kamilogorek
Copy link
Contributor

Released in 1.66.0

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.

Support custom headers
2 participants