microsoft.opentelemetry.a365.core.message_utils module

Conversion and serialization helpers for OTEL gen-ai message format.

Provides normalization from plain list[str] (backward compat) to the versioned wrapper format, and a non-throwing serialize_messages function.

microsoft.opentelemetry.a365.core.message_utils.is_string_list(param)[source]

Return True when param is a plain list[str].

Return type:

bool

microsoft.opentelemetry.a365.core.message_utils.is_wrapped_messages(param)[source]

Return True when param is a versioned wrapper.

Return type:

bool

microsoft.opentelemetry.a365.core.message_utils.to_input_messages(messages)[source]

Convert plain input strings into OTEL ChatMessage objects.

Return type:

list[ChatMessage]

microsoft.opentelemetry.a365.core.message_utils.to_output_messages(messages)[source]

Convert plain output strings into OTEL OutputMessage objects.

Return type:

list[OutputMessage]

microsoft.opentelemetry.a365.core.message_utils.normalize_input_messages(param)[source]

Normalize an InputMessagesParam to a versioned InputMessages wrapper.

  • str -> wrapped in a single-element list, then converted.

  • list[str] -> converted to ChatMessage list and wrapped.

  • InputMessages -> returned as-is.

Return type:

InputMessages

microsoft.opentelemetry.a365.core.message_utils.normalize_output_messages(param)[source]

Normalize an OutputMessagesParam to a versioned OutputMessages wrapper.

  • str -> wrapped in a single-element list, then converted.

  • list[str] -> converted to OutputMessage list and wrapped.

  • OutputMessages -> returned as-is.

Return type:

OutputMessages

microsoft.opentelemetry.a365.core.message_utils.serialize_messages(wrapper)[source]

Serialize a versioned message wrapper to JSON.

The output is the full wrapper object: {"version":"0.1.0","messages":[...]}.

The try/except ensures telemetry recording is non-throwing even when message parts contain non-JSON-serializable values.

Return type:

str