-
Notifications
You must be signed in to change notification settings - Fork 18
feat(sdk): [Enterprise Integration]: Add provider agnostic traceing #145
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
Merged
namrataghadi-galileo
merged 5 commits into
main
from
feature/59789-add-provider-agnostic-tracing
Mar 27, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
58eb627
Add provider agnostic traceing
namrataghadi-galileo 3d39706
fix linting
namrataghadi-galileo c3241c1
add test
namrataghadi-galileo 61cd788
address comments
namrataghadi-galileo 8d4ef62
remove event sink in this PR
namrataghadi-galileo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """Telemetry interfaces for provider-agnostic tracing.""" | ||
|
|
||
| from .trace_context import ( | ||
| TraceContext, | ||
| TraceContextProvider, | ||
| clear_trace_context_provider, | ||
| get_trace_context_from_provider, | ||
| set_trace_context_provider, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "TraceContext", | ||
| "TraceContextProvider", | ||
| "clear_trace_context_provider", | ||
| "get_trace_context_from_provider", | ||
| "set_trace_context_provider", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| """Provider-agnostic trace context interface for external tracing systems.""" | ||
|
|
||
| from collections.abc import Callable | ||
| from typing import TypedDict | ||
|
|
||
|
|
||
| class TraceContext(TypedDict): | ||
| """Resolved trace context for a control evaluation.""" | ||
|
|
||
| trace_id: str | ||
| span_id: str | ||
|
|
||
|
|
||
| TraceContextProvider = Callable[[], TraceContext | None] | ||
|
|
||
| _trace_context_provider: TraceContextProvider | None = None | ||
|
|
||
|
|
||
| def set_trace_context_provider(provider: TraceContextProvider | None) -> None: | ||
| """Register a provider that returns the current trace context.""" | ||
| global _trace_context_provider | ||
| _trace_context_provider = provider | ||
|
|
||
|
|
||
| def get_trace_context_from_provider() -> TraceContext | None: | ||
| """Return trace context from the registered provider, if any.""" | ||
| if _trace_context_provider is None: | ||
| return None | ||
|
|
||
| try: | ||
| trace_context = _trace_context_provider() | ||
| except Exception: | ||
| # Provider failures should not break control evaluation. | ||
| return None | ||
|
|
||
| if trace_context is None: | ||
| return None | ||
|
|
||
| trace_id = trace_context.get("trace_id") | ||
| span_id = trace_context.get("span_id") | ||
| if not isinstance(trace_id, str) or not isinstance(span_id, str): | ||
| return None | ||
| if not trace_id or not span_id: | ||
| return None | ||
|
|
||
| return { | ||
| "trace_id": trace_id, | ||
| "span_id": span_id, | ||
| } | ||
|
|
||
|
|
||
| def clear_trace_context_provider() -> None: | ||
| """Clear the registered trace context provider.""" | ||
| global _trace_context_provider | ||
| _trace_context_provider = None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Tests for the telemetry trace context provider interface.""" | ||
|
|
||
| from agent_control.telemetry.trace_context import ( | ||
| clear_trace_context_provider, | ||
| get_trace_context_from_provider, | ||
| set_trace_context_provider, | ||
| ) | ||
|
|
||
|
|
||
| def teardown_function() -> None: | ||
| clear_trace_context_provider() | ||
|
|
||
|
|
||
| def test_get_trace_context_from_provider_returns_registered_context() -> None: | ||
| set_trace_context_provider( | ||
| lambda: { | ||
| "trace_id": "a" * 32, | ||
| "span_id": "b" * 16, | ||
| } | ||
| ) | ||
|
|
||
| assert get_trace_context_from_provider() == { | ||
| "trace_id": "a" * 32, | ||
| "span_id": "b" * 16, | ||
| } | ||
|
|
||
|
|
||
| def test_get_trace_context_from_provider_returns_none_when_unset() -> None: | ||
| assert get_trace_context_from_provider() is None | ||
|
|
||
|
|
||
| def test_get_trace_context_from_provider_returns_none_when_provider_returns_none() -> None: | ||
| set_trace_context_provider(lambda: None) | ||
|
|
||
| assert get_trace_context_from_provider() is None | ||
|
|
||
|
|
||
| def test_get_trace_context_from_provider_swallows_provider_failures() -> None: | ||
| def _raising_provider(): | ||
| raise RuntimeError("boom") | ||
|
|
||
| set_trace_context_provider(_raising_provider) | ||
|
|
||
| assert get_trace_context_from_provider() is None | ||
|
|
||
|
|
||
| def test_get_trace_context_from_provider_returns_none_for_invalid_shape() -> None: | ||
| set_trace_context_provider( # type: ignore[arg-type] | ||
| lambda: { | ||
| "trace_id": "a" * 32, | ||
| } | ||
| ) | ||
|
|
||
| assert get_trace_context_from_provider() is None | ||
|
|
||
|
|
||
| def test_get_trace_context_from_provider_returns_none_for_empty_ids() -> None: | ||
| set_trace_context_provider( | ||
| lambda: { | ||
| "trace_id": "", | ||
| "span_id": "", | ||
| } | ||
| ) | ||
|
|
||
| assert get_trace_context_from_provider() is None |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.