microsoft.opentelemetry.a365.core.utils module

microsoft.opentelemetry.a365.core.utils.extract_context_from_headers(headers)[source]

Extract an OpenTelemetry Context from W3C trace HTTP headers.

Parses traceparent (and optionally tracestate) headers and returns an OpenTelemetry Context that can be passed as parent_context to any scope’s start() method.

Parameters:

headers (dict[str, str]) – Dictionary of HTTP headers containing trace context. Expected keys include traceparent and optionally tracestate.

Return type:

Context

Returns:

An OpenTelemetry Context containing the extracted trace information. If no valid trace context is found, returns an empty context.

microsoft.opentelemetry.a365.core.utils.get_traceparent(headers)[source]

Return the W3C traceparent value from a headers dictionary.

Parameters:

headers (dict[str, str]) – Dictionary of HTTP headers, typically obtained from OpenTelemetryScope.inject_context_to_headers().

Return type:

str | None

Returns:

The traceparent string (e.g. "00-<trace-id>-<span-id>-<flags>"), or None if the key is not present.

microsoft.opentelemetry.a365.core.utils.safe_json_dumps(obj, **kwargs)[source]
Return type:

str

microsoft.opentelemetry.a365.core.utils.as_utc_nano(dt)[source]
Return type:

int

microsoft.opentelemetry.a365.core.utils.get_first_value(mapping, keys)[source]

Returns the first non-null value corresponding to an input key, or None if no non-null value is found.

Return type:

Optional[TypeVar(ValueType)]

microsoft.opentelemetry.a365.core.utils.stop_on_exception(wrapped)[source]
Return type:

Callable[..., Iterator[tuple[str, Any]]]

microsoft.opentelemetry.a365.core.utils.record_exception(span, error)[source]
Return type:

None

microsoft.opentelemetry.a365.core.utils.flatten(*args, **kwargs)[source]
Return type:

Iterator[tuple[str, Any]]

class microsoft.opentelemetry.a365.core.utils.DictWithLock(wrapped=None)[source]

Bases: ObjectProxy, Generic[K, V]

A wrapped dictionary with lock

get(key)[source]
Return type:

Optional[TypeVar(V)]

pop(key, *args)[source]
Return type:

Optional[TypeVar(V)]

microsoft.opentelemetry.a365.core.utils.extract_model_name(span_name)[source]

Extract model name from span names like: - ‘chat.completions gpt-4o-mini’ -> ‘gpt-4o-mini’ - ‘chat.completions gpt-3.5-turbo’ -> ‘gpt-3.5-turbo’ - ‘chat.completions’ -> None

Return type:

str | None

microsoft.opentelemetry.a365.core.utils.deprecated(reason)[source]

Decorator to mark functions as deprecated.

microsoft.opentelemetry.a365.core.utils.get_sdk_version()[source]

Get the SDK version from package metadata.

Return type:

str

Returns:

The SDK version string, or “0.0.0-unknown” if not found

microsoft.opentelemetry.a365.core.utils.validate_and_normalize_ip(ip_string)[source]

Validate and normalize an IP address string.

Parameters:

ip_string (str | None) – The IP address string to validate (IPv4 or IPv6)

Return type:

str | None

Returns:

The normalized IP address string if valid, None if invalid or None input

Logs:

Error message if the IP address is invalid