Skip to content

Add no_proxy config option in SDK init #4726

@scarletnguyen13

Description

@scarletnguyen13

Problem Statement

The SDK is currently providing initialization options http_proxy,https_proxy and relying on environment variables for fallback. If I want to bypass proxy config altogether, I have to set

sentry_sdk.init(
  https_proxy="",
  http_proxy="",
)

Which requires reading SDK logic for handling proxy (which may change in the future)

The current hack is also subtly different from

sentry_sdk.init(
  https_proxy=None,
  http_proxy=None,
)

(which will fallback to env vars and NOT what I want)

In my use case where sentry_sdk is deployed to many services, I don't have control over environment variables and need an option to disable/bypass proxy in Sentry SDK's internal transport.

Solution Brainstorm

File: sentry_sdk/consts.py

def __init__(
    self,
    # ... other parameters ...
    no_proxy=False,  # type: bool
    # ... other parameters ...
):

File: sentry_sdk/transport.py

def _in_no_proxy(self, parsed_dsn):
    # type: (Self, Dsn) -> bool
    if self.options["no_proxy"]:
        return True
    no_proxy = getproxies().get("no")
    if not no_proxy:
        return False
    # ... existing environment variable logic ...

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions