azure.core.tracing.ext.opencensus_span package

Implements azure.core.tracing.AbstractSpan to wrap opencensus spans.

class azure.core.tracing.ext.opencensus_span.OpenCensusSpan(span: Optional[Span] = None, name: Optional[str] = 'span', **kwargs: Any)[source]

Wraps a given OpenCensus Span so that it implements azure.core.tracing.AbstractSpan

If a span is not passed in, creates a new tracer. If the instrumentation key for Azure Exporter is given, will configure the azure exporter else will just create a new tracer.

Parameters
  • span – The OpenCensus span to wrap

  • name (str) – The name of the OpenCensus span to create if a new span is needed

Keyword Arguments
  • kind (SpanKind) – The span kind of this span.

  • links (list[Link]) – The list of links to be added to the span.

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: Span)ContextManager[source]

Change the context for the life of this context manager.

finish()None[source]

Set the end time for a span.

classmethod get_current_span()opencensus.trace.span.Span[source]

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

classmethod get_current_tracer()opencensus.trace.tracer.Tracer[source]

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

get_trace_parent()[source]

Return traceparent string as defined in W3C trace context specification.

Example: Value = 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01 base16(version) = 00 base16(trace-id) = 4bf92f3577b34da6a3ce929d0e0e4736 base16(parent-id) = 00f067aa0ba902b7 base16(trace-flags) = 01 // sampled

Returns

a traceparent string

Return type

str

Links the context to the current tracer.

Parameters

traceparent (str) – A complete traceparent

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

Parameters

headers (dict) – A key value pair dictionary

classmethod set_current_span(span: opencensus.trace.span.Span)None[source]

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

Parameters

span – The span to set the current span as

classmethod set_current_tracer(tracer: opencensus.trace.tracer.Tracer)None[source]

Set the given tracer as the current tracer in the execution context. :param tracer: The tracer to set the current tracer as :type tracer: :class: opencensus.trace.Tracer

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

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] = 'span', **kwargs: Any)OpenCensusSpan[source]

Create a child span for the current span and append it to the child spans list in the span instance. :param name: Name of the child span :type name: str :keyword SpanKind kind: The span kind of this span. :keyword links: The list of links to be added to the span. :paramtype links: list[~azure.core.tracing.Link] :return: The OpenCensusSpan that is wrapping the child span instance

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. :return: A key value pair dictionary

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

property kind

Get the span kind of this span.

property span_instance

The OpenCensus span that is being wrapped.

Type

return