azure.core.tracing¶
-
class
azure.core.tracing.
AbstractSpan
(span: Optional[SpanType] = None, name: Optional[str] = None, **kwargs: Any)[source]¶ Wraps a span from a distributed tracing implementation.
If a span is given wraps the span. Else a new span is created. The optional argument name is given to the new span.
- Parameters
span (Any) – The span to wrap
name (str) – The name of the span
-
add_attribute
(key: str, value: Union[str, int]) → None[source]¶ Add attribute (key value pair) to the current span.
-
classmethod
change_context
(span: SpanType) → ContextManager[SpanType][source]¶ Change the context for the life of this context manager.
- Parameters
span (Any) – The span to run in the new context
- Return type
contextmanager
- Returns
A context manager that will run the given span in the new context
-
classmethod
get_current_span
() → SpanType[source]¶ Get the current span from the execution context. Return None otherwise.
- Returns
The current span
- Return type
-
classmethod
get_current_tracer
() → Any[source]¶ Get the current tracer from the execution context. Return None otherwise.
- Returns
The current tracer
- Return type
Any
-
get_trace_parent
() → str[source]¶ Return traceparent string.
- Returns
a traceparent string
- Return type
-
classmethod
link
(traceparent: str, attributes: Optional[Dict[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]] = None) → None[source]¶ Given a traceparent, extracts the context and links the context to the current tracer.
-
classmethod
link_from_headers
(headers: Dict[str, str], attributes: Optional[Dict[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]] = None) → None[source]¶ Given a dictionary, extracts the context and links the context to the current tracer.
-
classmethod
set_current_span
(span: SpanType) → None[source]¶ Set the given span as the current span in the execution context.
- Parameters
span (Any) – The span to set as the current span
-
classmethod
set_current_tracer
(tracer: Any) → None[source]¶ Set the given tracer as the current tracer in the execution context.
- Parameters
tracer (Any) – The tracer to set as the current tracer
-
set_http_attributes
(request: Union[azure.core.pipeline.transport._base.HttpRequest, azure.core.rest._rest_py3.HttpRequest], response: Optional[Union[azure.core.pipeline.transport._base.HttpResponse, azure.core.pipeline.transport._base_async.AsyncHttpResponse, azure.core.rest._rest_py3.HttpResponse, azure.core.rest._rest_py3.AsyncHttpResponse]] = None) → None[source]¶ Add correct attributes for a http client span.
- Parameters
request (HttpRequest) – The request made
response (HttpResponse or AsyncHttpResponse) – The response received by the server. Is None if no response received.
-
span
(name: str = 'child_span', **kwargs: Any) → azure.core.tracing._abstract_span.AbstractSpan[SpanType][source]¶ Create a child span for the current span and append it to the child spans list. The child span must be wrapped by an implementation of AbstractSpan
- Parameters
name (str) – The name of the child span
- Returns
The child span
- Return type
-
to_header
() → Dict[str, str][source]¶ Returns a dictionary with the header labels and values.
- Returns
A dictionary with the header labels and values
- Return type
-
classmethod
with_current_context
(func: Callable) → Callable[source]¶ Passes the current spans to the new context the function will be run in.
- Parameters
func (callable) – The function that will be run in the new context
- Returns
The target the pass in instead of the function
- Return type
callable
-
property
kind
¶ Get the span kind of this span.
- Return type
- Returns
The span kind of this span
-
property
span_instance
¶ Returns the span the class is wrapping.
-
class
azure.core.tracing.
HttpSpanMixin
[source]¶ Can be used to get HTTP span attributes settings for free.
-
set_http_attributes
(request: Union[azure.core.pipeline.transport._base.HttpRequest, azure.core.rest._rest_py3.HttpRequest], response: Optional[Union[azure.core.pipeline.transport._base.HttpResponse, azure.core.pipeline.transport._base_async.AsyncHttpResponse, azure.core.rest._rest_py3.HttpResponse, azure.core.rest._rest_py3.AsyncHttpResponse]] = None) → None[source]¶ Add correct attributes for a http client span.
- Parameters
request (HttpRequest) – The request made
response (HttpResponse or AsyncHttpResponse) – The response received from the server. Is None if no response received.
-
-
class
azure.core.tracing.
Link
(headers: Dict[str, str], attributes: Optional[Dict[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]] = None)[source]¶ This is a wrapper class to link the context to the current tracer. :param headers: A dictionary of the request header as key value pairs. :type headers: dict :param attributes: Any additional attributes that should be added to link :type attributes: dict
-
class
azure.core.tracing.
SpanKind
(value)[source]¶ An enumeration.
-
CLIENT
= 3¶
-
CONSUMER
= 5¶
-
INTERNAL
= 6¶
-
PRODUCER
= 4¶
-
SERVER
= 2¶
-
UNSPECIFIED
= 1¶
-
Submodules¶
azure.core.tracing.common¶
Common functions shared by both the sync and the async decorators.
-
azure.core.tracing.common.
change_context
(span: Optional[azure.core.tracing._abstract_span.AbstractSpan]) → Generator[source]¶ Execute this block inside the given context and restore it afterwards.
This does not start and ends the span, but just make sure all code is executed within that span.
If span is None, no-op.
- Parameters
span (AbstractSpan) – A span
- Return type
contextmanager
- Returns
A context manager that will run the given span in the new context
azure.core.tracing.decorator¶
The decorator to apply if you want the given function traced.
-
azure.core.tracing.decorator.
distributed_trace
(__func: Callable[[P], T]) → Callable[[P], T][source]¶ -
azure.core.tracing.decorator.
distributed_trace
(**kwargs: Any) → Callable[[Callable[[P], T]], Callable[[P], T]] Decorator to apply to function to get traced automatically.
Span will use the func name or “name_of_span”.
azure.core.tracing.decorator_async¶
The decorator to apply if you want the given function traced.
-
azure.core.tracing.decorator_async.
distributed_trace_async
(__func: Callable[[P], Awaitable[T]]) → Callable[[P], Awaitable[T]][source]¶ -
azure.core.tracing.decorator_async.
distributed_trace_async
(**kwargs: Any) → Callable[[Callable[[P], Awaitable[T]]], Callable[[P], Awaitable[T]]] Decorator to apply to function to get traced automatically.
Span will use the func name or “name_of_span”.