-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Multi user context #196
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: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
Introduces multi-user context support to enable tracking and exporting spans with API key overrides, allowing services to handle multiple users with dedicated export instances per API key.
- Added
RoutingSpanProcessor
to route spans based on user-specific API keys instead of using a single BatchSpanProcessor - Introduced
using_api_key()
context manager andapi_key
parameter torun()
for per-user span export control - Enhanced
RunContext
to include export authentication token for cross-thread/process context continuity
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
dreadnode/tracing/span.py | Added export auth token context management and updated RunSpan to support API key overrides |
dreadnode/tracing/processors.py | New RoutingSpanProcessor for multi-user span routing based on API keys |
dreadnode/tracing/constants.py | Added constant for span resource attribute token |
dreadnode/main.py | Replaced BatchSpanProcessor with RoutingSpanProcessor and added using_api_key context manager |
dreadnode/init.py | Exported using_api_key function |
docs/sdk/main.mdx | Updated documentation to reflect new API key functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
class RunContext(te.TypedDict, total=False): | ||
"""Context for transferring and continuing runs in other places.""" | ||
|
||
run_id: str | ||
run_name: str | ||
project: str | ||
trace_context: dict[str, str] | ||
export_auth_token: str | None | ||
|
||
|
Copilot
AI
Oct 3, 2025
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.
Changing RunContext from a required TypedDict to total=False makes all fields optional, which could break existing code that assumes required fields like 'run_id' are always present. Consider using separate required and optional field groups or create a new TypedDict for the optional fields.
class RunContext(te.TypedDict, total=False): | |
"""Context for transferring and continuing runs in other places.""" | |
run_id: str | |
run_name: str | |
project: str | |
trace_context: dict[str, str] | |
export_auth_token: str | None | |
class RunContextBase(te.TypedDict): | |
"""Required fields for RunContext.""" | |
run_id: str | |
run_name: str | |
project: str | |
trace_context: dict[str, str] | |
class RunContext(RunContextBase, total=False): | |
"""Context for transferring and continuing runs in other places, with optional fields.""" | |
export_auth_token: str | None |
Copilot uses AI. Check for mistakes.
server_url: str, | ||
default_token: str, | ||
*, | ||
token_header_name: str = "X-Api-Key", # noqa: S107 |
Copilot
AI
Oct 3, 2025
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.
The noqa comment suggests this is flagged as a security issue. Consider using a constant or configuration value instead of a hardcoded string literal for the API key header name.
Copilot uses AI. Check for mistakes.
Example | ||
|
||
```python | ||
with dreadnode.with_api_key("other_user_api_key"): |
Copilot
AI
Oct 3, 2025
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.
The example code uses dreadnode.with_api_key()
but the actual function name is using_api_key()
. This inconsistency will cause the example to fail.
Copilot uses AI. Check for mistakes.
Example: | ||
~~~ | ||
with dreadnode.with_api_key("other_user_api_key"): |
Copilot
AI
Oct 3, 2025
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.
The documentation example uses with_api_key()
but the actual function name is using_api_key()
. This inconsistency will cause the example to fail.
Copilot uses AI. Check for mistakes.
Support tracking and exporting spans with api key overrides to support multi-user services
Key Changes
dn.run(..., api_key=)
argument andwith dn.using_api_key()
to override this context on demand.get_run_context
carries this override information so if we have a backend stack passing around user-local context, it's reflected in the exports.Example
Generated Summary:
PR Description
This pull request introduces significant modifications to the SDK's tracing mechanism, enhancing support for multi-user scenarios by allowing the use of API keys for span exports.
get_run_context
method to simplify the extraction of run context data.using_api_key
, to facilitate temporary overriding of the API key used for exporting spans during nested operations.api_key
as an optional parameter torun
andinitialize
methods, enabling context-specific tracing.BatchSpanProcessor
with a newRoutingSpanProcessor
that allows spans to be routed based on user-specific tokens.RunContext
structure to includeexport_auth_token
to maintain API key information across different contexts.These changes enable more flexible tracing capabilities and improve the SDK's usability in multi-user applications, allowing for controlled export configurations based on individual API keys.
This summary was generated with ❤️ by rigging