-
Notifications
You must be signed in to change notification settings - Fork 26
docs(samples): Adding snippet to extract SessionInfo #457
Conversation
This snippet provides an example of how to extract SessionInfo from WebhookRequests.
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
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.
LGTM
def log_session_info_for_troubleshooting(request): | ||
"""Webhook will log session id corresponding to request.""" | ||
|
||
req = request.get_json() |
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.
If there's a concern about unhandled exceptions, you might want to wrap this in a try block in case the request does not contain well-formed JSON.
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.
There shouldn't be a concern of incorrect json here. Since the doc indicates that the request will contain JSON data this behavior should be guaranteed.
|
||
|
||
@pytest.fixture | ||
def session_prefix(agent_id): |
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.
This is fine, but I'm not used to seeing so fixtures used only for other fixtures (instead of static constant test strings, for example). Is this to make it easier to add more tests that use these embedded fixtures in other ways?
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 initially tried the constant approach but I liked Nick's suggestion to use fixtures.
I also updated the code in webhook_log_session_info_test.py
with the following summary:
session_id
is what I want to log and check in the tests so this is a good fixture for all testssession_prefix
is a rather long string that in this context does not need a variableagent_id
. So I madesession_prefix
a fixture that I can use for the two types ofsession
strings I needed to test. I also madeagent_id
available only in thesession_prefix
scope.session
andenv_session
are critical to the two tests. They now have the same signature.
Adding a code sample to show how to extract SessionInfo from a WebhookRequest
Fixes #<444> 🦕
BEGIN_COMMIT_OVERRIDE
docs(samples): Adding snippet to extract SessionInfo
END_COMMIT_OVERRIDE