AbstractSpan Class

Wraps a span from a distributed tracing implementation.

Inheritance
AbstractSpan

Constructor

AbstractSpan(*args, **kwargs)

Methods

add_attribute

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

change_context

Change the context for the life of this context manager.

finish

Set the end time for a span.

get_current_span

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

get_current_tracer

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

get_trace_parent

Return traceparent string.

link

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

link_from_headers

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

set_current_span

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

set_current_tracer

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

set_http_attributes

Add correct attributes for a http client span.

span

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

Set the start time for a span.

to_header

Returns a dictionary with the header labels and values.

with_current_context

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

add_attribute

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

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

Parameters

key
str
Required

The key of the key value pair

value
str
Required

The value of the key value pair

change_context

Change the context for the life of this context manager.

change_context(span: AbstractSpan) -> ContextManager

Parameters

cls
Required
span
Required

Return type

<xref:contextmanager>

finish

Set the end time for a span.

finish() -> None

get_current_span

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

get_current_span() -> Any

Parameters

cls
Required

get_current_tracer

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

get_current_tracer() -> Any

Parameters

cls
Required

get_trace_parent

Return traceparent string.

get_trace_parent() -> str

Returns

a traceparent string

Return type

str

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

link(traceparent: str, attributes: Attributes = None) -> None

Parameters

traceparent
str
Required

A string representing a traceparent

traceparent
Required
attributes
default value: None

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

link_from_headers(headers: Dict[str, str], attributes: Attributes = None) -> None

Parameters

headers
dict
Required

A dictionary of the request header as key value pairs.

headers
Required
attributes
default value: None

set_current_span

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

set_current_span(span: Any) -> None

Parameters

cls
Required
span
Required

set_current_tracer

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

set_current_tracer(tracer: Any) -> None

Parameters

cls
Required
tracer
Required

set_http_attributes

Add correct attributes for a http client span.

set_http_attributes(request: HttpRequest, response: Optional[HttpResponseType] = None) -> None

Parameters

request
HttpRequest
Required

The request made

response
HttpResponse or AsyncHttpResponse
default value: None

The response received by the server. Is None if no response received.

span

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

span(name: Optional[str] = 'child_span', **kwargs: Any) -> AbstractSpan

Parameters

name
default value: child_span

start

Set the start time for a span.

start() -> None

to_header

Returns a dictionary with the header labels and values.

to_header() -> Dict[str, str]

with_current_context

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

with_current_context(func: Callable) -> Callable

Parameters

func
Required

The function that will be run in the new context

func
Required

Returns

The target the pass in instead of the function

Return type

Attributes

kind

Get the span kind of this span.

Return type

span_instance

Returns the span the class is wrapping.