feat: Add user_id and session_id in traces to track users and sessions#523
Conversation
| @@ -0,0 +1,44 @@ | |||
| """OpenLayer tracing module.""" | |||
There was a problem hiding this comment.
Currently, we don't use this file.
We expose all features in the tracing module in lib/__init__.py (e.g., here.) This way, the user only needs to import from lib. E.g.,
from openlayer.lib import trace # as opposed to from openlayer.lib.tracing.tracer import traceIn my opinion, we should maintain the pattern we're currently following. In that case, you should move the imports to https://github.com/openlayer-ai/openlayer-python/blob/main/src/openlayer/lib/__init__.py, to expose them there.
Open to hear your perspective as well.
There was a problem hiding this comment.
makes sense. updated.
| @@ -0,0 +1,167 @@ | |||
| """ | |||
| Streamlined user and session context management for OpenLayer tracing. | |||
There was a problem hiding this comment.
super nit: in this and other places, you have the "L" capitalized. We go by "Openlayer"
| used. | ||
| """ | ||
|
|
||
| user_id_column_name: Annotated[str, PropertyInfo(alias="userIdColumnName")] |
There was a problem hiding this comment.
This file is auto-generated by Stainless and we shouldn't modify it directly. I'm going to comment in your Linear how to regenerate this file.
For this (and our other SDKs generated by Stainless), we should only edit files inside /lib and /examples. The rest is fully autogenerated from our OpenAPI spec.
6499738 to
03ed5a2
Compare
Pull Request
Summary
Add user and session context tracking to OpenLayer tracing functionality. This enhancement enables developers to associate traces with specific users and sessions, providing better observability and analytics for multi-user applications.
Changes
src/openlayer/lib/tracing/context.pywith user/session context functionsset_user_session_context()- Set default user/session IDs (typically in middleware)update_trace_user_session()- Override user/session IDs for specific tracesget_current_user_id()/get_current_session_id()- Retrieve current contextclear_user_session_context()- Clear all contextuser_idandsession_idin trace datauser_id_column_nameandsession_id_column_namein data stream configurationContext
This addresses the need to track user sessions and individual users within OpenLayer traces.