azure.core.tracing package

class azure.core.tracing.AbstractSpan(*args, **kwargs)[source]

Wraps a span from a distributed tracing implementation.

add_attribute(key: str, value: Union[str, int])None[source]

Add attribute (key value pair) to the current span.

Parameters
  • key (str) – The key of the key value pair

  • value (str) – The value of the key value pair

classmethod change_context(span: AbstractSpan) → ContextManager[source]

Change the context for the life of this context manager.

Return type

contextmanager

finish()None[source]

Set the end time for a span.

classmethod get_current_span() → Any[source]

Get the current span from the execution context. Return None otherwise.

classmethod get_current_tracer() → Any[source]

Get the current tracer from the execution context. Return None otherwise.

get_trace_parent()str[source]

Return traceparent string.

Returns

a traceparent string

Return type

str

Given a traceparent, extracts the context and links the context to the current tracer.

Parameters

traceparent (str) – A string representing a traceparent

Given a dictionary, extracts the context and links the context to the current tracer.

Parameters

headers (dict) – A dictionary of the request header as key value pairs.

classmethod set_current_span(span: Any)None[source]

Set the given span as the current span in the execution context.

classmethod set_current_tracer(tracer: Any)None[source]

Set the given tracer as the current tracer in the execution context.

set_http_attributes(request: HttpRequest, response: Optional[HttpResponseType] = 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: Optional[str] = 'child_span', **kwargs: Any) → AbstractSpan[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

start()None[source]

Set the start time for a span.

to_header() → Dict[str, str][source]

Returns a dictionary with the header labels and values.

classmethod with_current_context(func: Callable) → Callable[source]

Passes the current spans to the new context the function will be run in.

Parameters

func – 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

SpanKind

property span_instance

Returns the span the class is wrapping.

class azure.core.tracing.SpanKind[source]

An enumeration.

CLIENT = 3
CONSUMER = 5
INTERNAL = 6
PRODUCER = 4
SERVER = 2
UNSPECIFIED = 1
class azure.core.tracing.HttpSpanMixin[source]

Can be used to get HTTP span attributes settings for free.

set_http_attributes(request: HttpRequest, response: Optional[HttpResponseType] = 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.

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

Subpackages