microsoft.opentelemetry.a365.core.inference_scope module

class microsoft.opentelemetry.a365.core.inference_scope.InferenceScope(request, details, agent_details, user_details=None, span_details=None)[source]

Bases: OpenTelemetryScope

Provides OpenTelemetry tracing scope for generative AI inference operations.

static start(request, details, agent_details, user_details=None, span_details=None)[source]

Creates and starts a new scope for inference tracing.

Parameters:
  • request (Request) – Request details for the inference

  • details (InferenceCallDetails) – The details of the inference call

  • agent_details (AgentDetails) – The details of the agent making the call

  • user_details (UserDetails | None) – Optional human user details

  • span_details (SpanDetails | None) – Optional span configuration (parent context, timing)

Return type:

InferenceScope

Returns:

A new InferenceScope instance

record_input_messages(messages)[source]

Records the input messages for telemetry tracking.

Accepts plain strings (auto-wrapped as OTEL ChatMessage with role user) or a versioned InputMessages wrapper.

Parameters:

messages (Union[str, list[str], InputMessages]) – List of input message strings or an InputMessages wrapper

Return type:

None

record_output_messages(messages)[source]

Records the output messages for telemetry tracking.

Accepts plain strings (auto-wrapped as OTEL OutputMessage with role assistant) or a versioned OutputMessages wrapper.

Parameters:

messages (Union[str, list[str], OutputMessages]) – List of output message strings or an OutputMessages wrapper

Return type:

None

record_input_tokens(input_tokens)[source]

Records the number of input tokens for telemetry tracking.

Parameters:

input_tokens (int) – Number of input tokens

Return type:

None

record_output_tokens(output_tokens)[source]

Records the number of output tokens for telemetry tracking.

Parameters:

output_tokens (int) – Number of output tokens

Return type:

None

record_finish_reasons(finish_reasons)[source]

Records the finish reasons for telemetry tracking.

Parameters:

finish_reasons (List[str]) – List of finish reasons

Return type:

None

record_thought_process(thought_process)[source]

Records the thought process.

Parameters:

thought_process (str) – The thought process to record

Return type:

None