Sentry-python: Send events without proxy when http_proxy is configured as env variable

Created on 24 Nov 2018  路  6Comments  路  Source: getsentry/sentry-python

Hi,
I have problem with configuration of sentry_sdk. My code is behind corporate proxy and http_proxy is configured on machine as env variable (required when I want to install something via pip for example). Also I have env variable no_proxy where I added ip address for host where sentry is working (this ip is inside corporate network). When I try send event to sentry I got return code 403 (proxy refuse request). Probably sentry_sdk automacally fetch proxy from http_proxy env but ignore no_proxy. When I remove http_proxy from env everything is working. How can I configure python_sdk to ignore my http_proxy env variable? My code:

import logging
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration


sentry_logging = LoggingIntegration(
    level=logging.INFO,       
    event_level=logging.ERROR 
)
sentry_sdk.init(
    dsn="<dsn>",
    integrations=[sentry_logging],
    debug=True,
)
SDK-SP enhancement help wanted

Most helpful comment

I would propose that we keep the current, simple, stupid proxying behavior, but add a new flag that disables any access to the process environment. Is this an acceptable fix?

The no_proxy env var is widely used. I strongly feel that if an application reads from http_proxy it should also respect the no_proxy variable. Please consider supporting it, thanks.

All 6 comments

Hi, yes there's currently no way to disable http_proxy if you have an envvar. I am not sure if no_proxy is easy to implement.

The same problem behid proxy. In this situation sentry_sdk is difficult to use. Maybe better solution will be use requests instead urllib3? Requests can handle no_proxy out of the box.

I want to add that switching to requests library can have other benefits like supporting SOCKS proxies. Currently, providing SOCKS proxy to http_proxy parameter results in ProxySchemeUnknown exception. To fix that with urllib3, you should explicitly check for socks:// schemes and use SOCKSProxyManager instead of ProxyManager, but requests handles it seamlessly.

To keep this issue updated: We discussed this internally and decided on a hard rule not to use requests. The reason for this is that we would like to explicitly control which behavior we support (since all of the new SDKs share a single piece of documentation describing that behavior, and the behavior across SDKs and across languages should be the same), and requests ideologically is the opposite of that: I for one was unaware that requests reads environment variables like that, even though I've been using it for quite a while.

I would propose that we keep the current, simple, stupid proxying behavior, but add a new flag that disables any access to the process environment. Is this an acceptable fix?

I would propose that we keep the current, simple, stupid proxying behavior, but add a new flag that disables any access to the process environment. Is this an acceptable fix?

The no_proxy env var is widely used. I strongly feel that if an application reads from http_proxy it should also respect the no_proxy variable. Please consider supporting it, thanks.

838 actually adds support for no_proxy.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aklajnert picture aklajnert  路  6Comments

rollcat picture rollcat  路  3Comments

CasperCL picture CasperCL  路  7Comments

robd003 picture robd003  路  5Comments

steven-murray picture steven-murray  路  3Comments