Conversation
| @@ -51,6 +53,7 @@ def rollbar_tween_factory(pyramid_handler, registry): | |||
|
|
|||
| def rollbar_tween(request): | |||
| # for testing out the integration | |||
There was a problem hiding this comment.
Looks like this comment got separated from the try block it references.
| break | ||
|
|
||
| if not baggage_header: | ||
| return _build_new_session_attributes() |
There was a problem hiding this comment.
This layer should not try to create a session id if not present in the header.
There was a problem hiding this comment.
Ah yes, when I updated the ticket & dmed you I included that change, apologies for not calling it out more:
If a baggage header is not present, one should be created, and a rollbar.execution.scope.id should be created as a hex representation of a 128 bit number. If rollbar.session.id is not present, the key should not be created.
It'd be the rollbar.execution.scope.id that would be created on the fly, rollbar.session.id can be null
| request = _session_data_from_request(data) | ||
| if request is None: | ||
| return | ||
| set_current_session(request.get('headers', None)) |
There was a problem hiding this comment.
It looks like we get here because no middleware had set a current session, but the request is present via the rollbar payload, so we look at the headers there. That makes sense, though I'm curious whether this is to cover unsupported frameworks, or supported ones when the middleware wasn't installed.
I think calling set_current_session here introduces a bug though. Unlike in the middleware, nothing calls reset_current_session, and on the next request (from a different session) get_current_session above will succeed with the stale session that was set here.
This can be avoided if session.py provides a method to return the session_data from the headers without needing to set and get current session.
| headers = request.get('headers', {}) | ||
| elif hasattr(request, 'headers'): | ||
| headers = request.headers | ||
| set_current_session(headers) |
There was a problem hiding this comment.
Ideally this could go in middleware.py, allowing reset_current_session to be used, and keeping the responsibility of store_current_request more focused.
This function already returns request, so it seems straightforward to move this logic.
|
@danielmorell nice PR! I'll defer to @shankj3 on approval. |
Description of the change
Adds support for the
baggagerequest header, enabling propagation ofrollbar.session.idandrollbar.execution.scope.id.Frameworks included are:
The
session_idattribute is persisted across the entire request. Every log message, trace, or exception reported will include the samesession_id.If the
baggagehearder is not included in a request, a newsession_idwill be generated, and will persist for the lifecycle of the request.The
session_idis stored in either thread local or an async safecontextvardepending on the framework.Type of change
Related issues
Checklists
Development
Code review