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

feat: honor http_proxy environment variables #1111

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented Jan 9, 2025

Fixes #787

Adds option to read http_proxy from environment (also checks https_proxy and prioritizes this if it exists). If this flag is set to true, it will overwrite any previously set proxies with sentry_options_set_proxy if the environment variables have a value.

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.65%. Comparing base (56198fc) to head (da3c91e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1111      +/-   ##
==========================================
- Coverage   82.68%   82.65%   -0.03%     
==========================================
  Files          53       53              
  Lines        7930     7935       +5     
  Branches     1240     1242       +2     
==========================================
+ Hits         6557     6559       +2     
- Misses       1263     1265       +2     
- Partials      110      111       +1     

Comment on lines 141 to 143
if (options->read_proxy_from_environment) {
sentry__set_proxy_from_environment(options);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this new option, I'm not sure we still need to support no_proxy; if users want to use the environment variable value in their own code, they can just not set this flag to true (which is the default anyway).

Copy link
Collaborator

@supervacuus supervacuus Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. You always have to consider that this is a feature that the users of our users require from them.

So, for instance, if your application ignores the http_proxy env-vars, your users don't care about the topic and accept that they have to manually configure the proxy config for that application (or even have no proxy config at all).

At some point, you might provide a UI to your users that does something like the following:

(   ) direct HTTP connection.
(   ) manually specify HTTP proxy: _________ .
( * ) read proxy from the environment.

You can route this directly to our proposed options interface. However, once your users have configured the app to read from the environment, they will want to stay with it because it allows them to have a centrally managed proxy configuration rather than defining it separately in every application.

This is where no_proxy enters the picture. So, yes, resetting the proxy config of that app solves the problem, but then the users of our users are essentially back to square 1. Again, this is not a requirement for an initial implementation of that feature but a likely follow-up.

@JoshuaMoelans JoshuaMoelans marked this pull request as ready for review January 14, 2025 12:04
src/sentry_options.c Outdated Show resolved Hide resolved
src/sentry_options.c Outdated Show resolved Hide resolved
include/sentry.h Outdated Show resolved Hide resolved
src/transports/sentry_transport_winhttp.c Outdated Show resolved Hide resolved
src/transports/sentry_transport_winhttp.c Outdated Show resolved Hide resolved
src/transports/sentry_transport_winhttp.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@JoshuaMoelans JoshuaMoelans changed the title Honor http_proxy environment variables feat: honor http_proxy environment variables Jan 22, 2025
Copy link

github-actions bot commented Jan 22, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against da3c91e

if proxy_auth == ["on"]:
current_run_arg += "-auth"
if proxy_from_env == ["proxy-from-env"]:
current_run_arg = "proxy-from-env" # overwrite args if proxy-from-env is set (e.g. don't manually set)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cURL transport we don't even need to call our proxy-from-env setter, since it will attempt to read the environment variable automatically https://everything.curl.dev/usingcurl/proxies/env.html .
This kind of makes this feature only really useful for Windows.

Copy link
Collaborator

@supervacuus supervacuus Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also true for the library (i.e., libcurl)? There are a couple of such features where the library only provides the mechanism, but the actual read is then implemented in the application (i.e., curl). The docs you link refer to the CLI utility, not the library.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means our default behavior should be to enable this since curl also enables it by default. There is no way to override reading from env (except for a build flag, which we don't control) except when the proxy is configured explicitly.

Comment on lines 627 to +630
@pytest.mark.parametrize("proxy_status", [(["off"]), (["on"])])
def test_capture_proxy(cmake, httpserver, run_args, proxy_status):
@pytest.mark.parametrize("proxy_auth", [(["off"]), (["on"])])
@pytest.mark.parametrize("proxy_IPv", [(["4"]), (["6"])])
@pytest.mark.parametrize("proxy_from_env", [(["proxy-from-env"]), ([""])])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is becoming exponentially larger. It might make sense to split apart some test cases to not cover the full matrix at once. There are still some untested cases:

  • What if proxy-from-env but the env. variable is empty? -> expected is that if there was a manually set proxy, it gets used.
  • Test whetherproxy-from-env takes precedence over manually set proxy if both are given.

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.

Honor http_proxy environment variables
2 participants