Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Another batch of annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed May 27, 2022
1 parent dda0cc8 commit e726655
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class _WrappedRustReporter(BaseReporter):
def set_process(self, *args, **kwargs):
return self._reporter.set_process(*args, **kwargs)

def report_span(self, span):
def report_span(self, span: "opentracing.Span") -> None:
try:
return self._reporter.report_span(span)
except Exception:
Expand Down Expand Up @@ -537,19 +537,19 @@ def start_active_span_follows_from(


def start_active_span_from_edu(
edu_content,
operation_name,
references: Optional[list] = None,
tags=None,
start_time=None,
ignore_active_span=False,
finish_on_close=True,
):
edu_content: Dict[str, Any],
operation_name: str,
references: Optional[List["opentracing.Reference"]] = None,
tags: Optional[Dict] = None,
start_time: Optional[float] = None,
ignore_active_span: bool = False,
finish_on_close: bool = True,
) -> "opentracing.Scope":
"""
Extracts a span context from an edu and uses it to start a new active span
Args:
edu_content (dict): and edu_content with a `context` field whose value is
edu_content: an edu_content with a `context` field whose value is
canonical json for a dict which contains opentracing information.
For the other args see opentracing.tracer
Expand Down Expand Up @@ -603,7 +603,7 @@ def set_tag(key: str, value: Union[str, bool, int, float]) -> None:


@ensure_active_span("log")
def log_kv(key_values: Dict[str, Any], timestamp=None) -> None:
def log_kv(key_values: Dict[str, Any], timestamp: Optional[float] = None) -> None:
"""Log to the active span"""
assert opentracing.tracer.active_span is not None
opentracing.tracer.active_span.log_kv(key_values, timestamp)
Expand Down Expand Up @@ -636,7 +636,9 @@ def force_tracing(span=Sentinel) -> None:
span.set_baggage_item(SynapseBaggage.FORCE_TRACING, "1")


def is_context_forced_tracing(span_context) -> bool:
def is_context_forced_tracing(
span_context: Optional["opentracing.SpanContext"],
) -> bool:
"""Check if sampling has been force for the given span context."""
if span_context is None:
return False
Expand Down Expand Up @@ -708,13 +710,13 @@ def inject_response_headers(response_headers: Headers) -> None:


@ensure_active_span("get the active span context as a dict", ret={})
def get_active_span_text_map(destination=None):
def get_active_span_text_map(destination: Optional[str] = None) -> Dict[str, str]:
"""
Gets a span context as a dict. This can be used instead of manually
injecting a span into an empty carrier.
Args:
destination (str): the name of the remote server.
destination: the name of the remote server.
Returns:
dict: the active span's context if opentracing is enabled, otherwise empty.
Expand All @@ -733,7 +735,7 @@ def get_active_span_text_map(destination=None):


@ensure_active_span("get the span context as a string.", ret={})
def active_span_context_as_string():
def active_span_context_as_string() -> str:
"""
Returns:
The active span context encoded as a string.
Expand Down

0 comments on commit e726655

Please sign in to comment.