Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ def _agents_apis(self):

def _project_apis(self):
"""Define AIProjectClient APIs to instrument for trace propagation.

:return: A tuple containing sync and async API tuples.
:rtype: Tuple[Tuple, Tuple]
"""
Expand All @@ -1309,7 +1309,7 @@ def _project_apis(self):

def _inject_openai_client(self, f, _trace_type, _name):
"""Injector for get_openai_client that enables trace context propagation if opted in.

:return: The wrapped function with trace context propagation enabled.
:rtype: Callable
"""
Expand All @@ -1331,7 +1331,7 @@ def _agents_api_list(self):

def _project_api_list(self):
"""Generate project API list with custom injector.

:return: A generator yielding API tuples with injectors.
:rtype: Generator
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# Licensed under the MIT License.
# ------------------------------------
import functools
import asyncio # pylint: disable = do-not-import-asyncio
import inspect
from typing import Any, Callable, Optional, Dict

try:
# pylint: disable = no-name-in-module
from opentelemetry import trace as opentelemetry_trace

tracer = opentelemetry_trace.get_tracer(__name__) # type: ignore[attr-defined]
_tracer = opentelemetry_trace.get_tracer(__name__) # type: ignore[attr-defined]
_tracing_library_available = True
except ModuleNotFoundError:
_tracing_library_available = False
Expand Down Expand Up @@ -50,6 +50,7 @@ async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
:return: The result of the decorated asynchronous function.
:rtype: Any
"""
tracer = opentelemetry_trace.get_tracer(__name__) # type: ignore[attr-defined]
name = span_name if span_name else func.__name__
with tracer.start_as_current_span(name) as span:
try:
Expand Down Expand Up @@ -79,6 +80,7 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
:return: The result of the decorated synchronous function.
:rtype: Any
"""
tracer = opentelemetry_trace.get_tracer(__name__) # type: ignore[attr-defined]
name = span_name if span_name else func.__name__
with tracer.start_as_current_span(name) as span:
try:
Expand All @@ -99,7 +101,7 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
raise

# Determine if the function is async
if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):
return async_wrapper
return sync_wrapper

Expand Down Expand Up @@ -134,15 +136,15 @@ def sanitize_parameters(func, *args, **kwargs) -> Dict[str, Any]:
:return: A dictionary of sanitized parameters.
:rtype: Dict[str, Any]
"""
import inspect

params = inspect.signature(func).parameters
sanitized_params = {}

for i, (name, param) in enumerate(params.items()):
if param.default == inspect.Parameter.empty and i < len(args):
if i < len(args):
# Use positional argument if provided
value = args[i]
else:
# Use keyword argument if provided, otherwise fall back to default value
value = kwargs.get(name, param.default)

sanitized_value = sanitize_for_attributes(value)
Expand Down
Loading