[Feature Request] Support for custom tracing providers
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- observability-sre
Research direction
Start by reading OpenAIAgentsPlugin initialization and the shown TemporalTraceProvider implementation, then determine how a supplied tracing provider can be integrated while preserving Temporal workflow behavior. Done means callers can pass a supported custom provider when creating the plugin and tracing continues to work correctly in workflows.
Written by the indexing model from the issue text.
Description
I'd like to add a custom tracing provider for the OpenAI Agents SDK. Importantly, this tracing provider is supported by the OpenAI Agents SDK itself.
The solution I'd like
I'd like to be able to pass the tracing provider to the OpenAI Agents Plugin when initializing the client e.g.
from temporalio.client import Client
from temporalio.contrib.openai_agents import OpenAIAgentsPlugin
from custom_tracing_provider import CustomTraceProvider
plugin = OpenAIAgentsPlugin(
trace_provider=CustomTraceProvider()
)
client_config = {
"namespace": NAMESPACE,
"plugins": [plugin],
"API_KEY": os.environ.get("TEMPORAL_API_KEY")
}
_client_instance = await Client.connect(ADDRESS, **client_config)
Given the temporal tracing provider today is implemented on top of the DefaultTracingProvider class provided by OpenAI as shown below, perhaps it wouldn't be too hard to just create a factory that takes any supported tracing provider and returns a Temporal supported one.
class TemporalTraceProvider(DefaultTraceProvider):
"""A trace provider that integrates with Temporal workflows."""
def __init__(self, auto_close_in_workflows: bool = False):
"""Initialize the TemporalTraceProvider."""
super().__init__()
self._original_provider = cast(DefaultTraceProvider, get_trace_provider())
self._multi_processor = _TemporalTracingProcessor(
self._original_provider._multi_processor,
auto_close_in_workflows,
)
def time_iso(self) -> str:
"""Return the current deterministic time in ISO 8601 format."""
if workflow.in_workflow():
return workflow.now().isoformat()
return super().time_iso()
def gen_trace_id(self) -> str:
"""Generate a new trace ID."""
if workflow.in_workflow():
try:
"""Generate a new trace ID."""
return f"trace_{_workflow_uuid()}"
except ReadOnlyContextError:
return f"trace_{uuid.uuid4().hex}"
return super().gen_trace_id()
def gen_span_id(self) -> str:
"""Generate a span ID."""
if workflow.in_workflow():
try:
"""Generate a deterministic span ID."""
return f"span_{_workflow_uuid()}"
except ReadOnlyContextError:
return f"span_{uuid.uuid4().hex[:24]}"
return super().gen_span_id()
def gen_group_id(self) -> str:
"""Generate a group ID."""
if workflow.in_workflow():
try:
"""Generate a deterministic group ID."""
return f"group_{_workflow_uuid()}"
except ReadOnlyContextError:
return f"group_{uuid.uuid4().hex[:24]}"
return super().gen_group_id()
def __enter__(self):
"""Enter the context of the Temporal trace provider."""
return self
def __exit__(
self,
exc_type: type[BaseException],
exc_val: BaseException,
exc_tb: TracebackType,
):
"""Exit the context of the Temporal trace provider."""
self._multi_processor.shutdown()
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 241
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 49
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from temporalio/sdk-python
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
temporalio/sdk-python#1517 · 10 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
temporalio/sdk-python#496 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
temporalio/sdk-python#1890 ·
-
[Bug] Local activity resolutions regrouped on replay since 1.32.0, delivering the wrong payload Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
temporalio/sdk-python#1881 · 1 comment ·
-
bug
temporalio/sdk-python#1817 · 1 comment · 1 assignee ·
All issues in temporalio/sdk-python
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100