Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3,13 +3,12 @@
# 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]
_tracing_library_available = True
except ModuleNotFoundError:
Expand Down Expand Up @@ -50,6 +49,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 +79,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 +100,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 @@ -140,10 +141,15 @@ def sanitize_parameters(func, *args, **kwargs) -> Dict[str, Any]:
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]
elif name in kwargs:
# Use keyword argument if provided
value = kwargs[name]
else:
value = kwargs.get(name, param.default)
# Fall back to default value
value = param.default

sanitized_value = sanitize_for_attributes(value)
# Check if the collection has nested collections
Expand Down
Loading
Loading