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

Replace opentracing with opentelemetry #465

Closed
wants to merge 4 commits into from
Closed
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
29 changes: 14 additions & 15 deletions faust/utils/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from functools import wraps
from typing import Any, Callable, Optional, Tuple

import opentracing
from mode import shortlabel
from opentelemetry.trace.span import Span

__all__ = [
"current_span",
Expand All @@ -20,28 +20,29 @@
]

if typing.TYPE_CHECKING:
_current_span: ContextVar[opentracing.Span]
_current_span: ContextVar[Span]
_current_span = ContextVar("current_span")


def current_span() -> Optional[opentracing.Span]:
def current_span() -> Optional[Span]:
"""Get the current span for this context (if any)."""
return _current_span.get(None)


def set_current_span(span: opentracing.Span) -> None:
def set_current_span(span: Span) -> None:
"""Set the current span for the current context."""
_current_span.set(span)


def noop_span() -> opentracing.Span:
"""Return a span that does nothing when traced."""
return opentracing.Tracer()._noop_span
def noop_span() -> Span:
"""
Return a span that does nothing when traced.
OpenTelemetry Spans function as no-ops when not recording.
"""
return Span


def finish_span(
span: Optional[opentracing.Span], *, error: BaseException = None
) -> None:
def finish_span(span: Optional[Span], *, error: BaseException = None) -> None:
"""Finish span, and optionally set error tag."""
if span is not None:
if error:
Expand All @@ -65,7 +66,7 @@ def operation_name_from_fun(fun: Any) -> str:


def traced_from_parent_span(
parent_span: opentracing.Span = None,
parent_span: Span = None,
callback: Optional[Callable] = None,
**extra_context: Any,
) -> Callable:
Expand Down Expand Up @@ -97,16 +98,14 @@ def _inner(*args: Any, **kwargs: Any) -> Any:
return _wrapper


def _restore_span(
span: opentracing.Span, expected_current_span: opentracing.Span
) -> None:
def _restore_span(span: Span, expected_current_span: Span) -> None:
current = current_span()
assert current is expected_current_span
set_current_span(span)


def call_with_trace(
span: opentracing.Span,
span: Span,
fun: Callable,
callback: Optional[Tuple[Callable, Tuple[Any, ...]]],
*args: Any,
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ aiohttp_cors>=0.7,<2.0
aiokafka>=0.8.0,<0.9.0
click>=6.7,<8.2
mode-streaming>=0.3.0
opentracing>=1.3.0,<=2.4.0
opentelemetry-api==1.16.0
terminaltables>=3.1,<4.0
yarl>=1.0,<2.0
croniter>=0.3.16
Expand Down