Added session forwarding via baggage headers to httpx and requests - #498
Conversation
|
@codex please review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
| # A client's explicit configuration overrides the global one. | ||
| should_inject = should_inject and client not in cls._clients | ||
| if should_inject: | ||
| cls._inject_propagation_headers(state, args, kwargs) |
There was a problem hiding this comment.
This is one of a few places where it would be good to have a try/except to prevent a possible uncaught exception in the host application's execution.
| # A client's explicit configuration overrides the global one. | ||
| should_inject = should_inject and client not in cls._clients | ||
| if should_inject: | ||
| cls._inject_propagation_headers(state, args, kwargs) |
There was a problem hiding this comment.
Try/except also makes sense here.
| should_inject = should_inject and session not in cls._sessions | ||
|
|
||
| if should_inject: | ||
| cls._inject_propagation_headers( |
There was a problem hiding this comment.
Try/except also makes sense here.
|
Thanks for the review and feedback on the try/except @waltjones. I have added those changes and also test coverage for them. |
|
@danielmorell thank you! |
Description of the change
This PR adds the ability to instrument outgoing request made via HTTPX and requests with the Rollbar session IDs and execution scope IDs in the baggage header.
Propagation of the session and execution scope is controlled with two parameters
enabled_urlsandenabled_headers. By defaultenabled_headersis["baggage"].Only requests to URLs included in the
enabled_urlswill include the propagated session and execution scope IDs.If there is an existing
baggageheader in the request is will be updated to include the new values. All other headers are left untouched. If for some reason the requestbaggageheader already includes Rollbar session and execution scope IDs they will be updated.If both global and client/session instrumentation is enabled, the client/session instrumentation takes precedence over the global.
There are three ways to manage instrumentation:
1. Global instrumentation with
rollbar.init().2. Global instrumentation with the propagation manager
In HTTPX...
In requests...
3. Individual Client/Session instrumentation with the propagation manager
In HTTPX...
In requests...
Type of change
Related issues
Checklists
Development
Code review