Skip to content

Commit

Permalink
Remove return type hinting on decorator (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Jan 24, 2024
1 parent 93e1b9a commit cec3aa4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions synapseclient/core/async_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""This utility class is to hold any utilities that are needed for async operations."""
from typing import Any, Callable, Coroutine, Union
from typing import Callable, Union
from opentelemetry import trace


tracer = trace.get_tracer("synapseclient")


def otel_trace_method(
method_to_trace_name: Union[Callable[..., str], None] = None
) -> Callable[..., Callable[..., Coroutine[Any, Any, None]]]:
def otel_trace_method(method_to_trace_name: Union[Callable[..., str], None] = None):
"""
Decorator to trace a method with OpenTelemetry in an async environment. This function
is specifically written to be used on a method within a class.
Expand All @@ -31,7 +29,7 @@ async def store(self):
A callable decorator that will trace the method with OpenTelemetry.
"""

def decorator(f) -> Callable[..., Coroutine[Any, Any, None]]:
def decorator(func):
"""Function decorator."""

async def wrapper(self, *arg, **kwargs) -> None:
Expand All @@ -41,8 +39,10 @@ async def wrapper(self, *arg, **kwargs) -> None:
if method_to_trace_name
else None
)
with tracer.start_as_current_span(trace_name or f"Synaspse::{f.__name__}"):
return await f(self, *arg, **kwargs)
with tracer.start_as_current_span(
trace_name or f"Synaspse::{func.__name__}"
):
return await func(self, *arg, **kwargs)

return wrapper

Expand Down

0 comments on commit cec3aa4

Please sign in to comment.