microsoft.opentelemetry.a365.core.opentelemetry_scope module

class microsoft.opentelemetry.a365.core.opentelemetry_scope.OpenTelemetryScope(operation_name, activity_name, agent_details=None, span_details=None)[source]

Bases: object

Base class for OpenTelemetry tracing scopes in the SDK.

record_error(exception)[source]

Record an error in the span.

Parameters:

exception (Exception) – The exception that occurred

Return type:

None

record_response(response)[source]

Record an response in the span.

Parameters:

response (str) – The response content to record

Return type:

None

record_cancellation()[source]

Record task cancellation.

Return type:

None

set_tag_maybe(name, value)[source]

Set a tag on the span if the value is not None.

Parameters:
  • name (str) – The name of the tag

  • value (Any) – The value to set (will be skipped if None)

Return type:

None

record_attributes(attributes)[source]

Record multiple attribute key/value pairs for telemetry tracking.

This method allows setting multiple custom attributes on the span at once.

Parameters:

attributes (dict[str, Any] | list[tuple[str, Any]]) – Dictionary or list of tuples containing attribute key-value pairs. Keys that are None or empty will be skipped.

Return type:

None

set_end_time(end_time)[source]

Set a custom end time for the scope.

When set, dispose() will pass this value to span.end() instead of using the current wall-clock time. This is useful when the actual end time of the operation is known before the scope is disposed.

Parameters:

end_time (datetime) – The end time as a datetime object.

Return type:

None

get_context()[source]

Get the OpenTelemetry context for this scope’s span.

This method returns a Context object containing this scope’s span, which can be used to propagate trace context to child operations or downstream services.

Return type:

Context | None

Returns:

A Context containing this scope’s span, or None if telemetry is disabled or no span exists.

inject_context_to_headers()[source]

Inject this span’s trace context into W3C HTTP headers.

Returns a dictionary of headers containing traceparent and optionally tracestate that can be forwarded to downstream services or stored for later context propagation.

Return type:

dict[str, str]

Returns:

A dictionary containing W3C trace context headers. Returns an empty dictionary if telemetry is disabled or no span exists.

dispose()[source]

Dispose the scope and finalize telemetry data collection.

Return type:

None