Skip to content
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

[SYNPY-1344] Remove return type hinting on decorator #1050

Merged
merged 1 commit into from
Jan 24, 2024
Merged
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
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
Loading