-
Notifications
You must be signed in to change notification settings - Fork 572
feat(stdlib): Handle proxy tunnels in httlib integration #5303
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,9 +69,19 @@ def _install_httplib() -> None: | |
| def putrequest( | ||
| self: "HTTPConnection", method: str, url: str, *args: "Any", **kwargs: "Any" | ||
| ) -> "Any": | ||
| host = self.host | ||
| port = self.port | ||
| # proxy info is in _tunnel_host/_tunnel_port | ||
| tunnel_host = getattr(self, "_tunnel_host", None) | ||
| host = tunnel_host or self.host | ||
|
|
||
| default_port = self.default_port | ||
| tunnel_port = getattr(self, "_tunnel_port", None) | ||
| if tunnel_port: | ||
| port = tunnel_port | ||
| # need to override default_port for correct url recording | ||
| if tunnel_port == 443: | ||
| default_port = 443 | ||
| else: | ||
| port = self.port | ||
|
Comment on lines
+77
to
+84
This comment was marked as outdated.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proxy port used when tunnel port is unspecifiedLow Severity When |
||
|
|
||
| client = sentry_sdk.get_client() | ||
| if client.get_integration(StdlibIntegration) is None or is_sentry_url( | ||
|
|
@@ -104,6 +114,11 @@ def putrequest( | |
| span.set_data(SPANDATA.HTTP_QUERY, parsed_url.query) | ||
| span.set_data(SPANDATA.HTTP_FRAGMENT, parsed_url.fragment) | ||
|
|
||
| if tunnel_host: | ||
| # for proxies, these point to the proxy host/port | ||
| span.set_data(SPANDATA.NETWORK_PEER_ADDRESS, self.host) | ||
| span.set_data(SPANDATA.NETWORK_PEER_PORT, self.port) | ||
|
|
||
| rv = real_putrequest(self, method, url, *args, **kwargs) | ||
|
|
||
| if should_propagate_trace(client, real_url): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest changing the url recording logic instead.
Otherwise, looks good to me!