microsoft.opentelemetry.a365.core package
- class microsoft.opentelemetry.a365.core.OpenTelemetryScope(operation_name, activity_name, agent_details=None, span_details=None)[source]
Bases:
objectBase class for OpenTelemetry tracing scopes in the SDK.
- 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.
- 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.
- 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.
- class microsoft.opentelemetry.a365.core.ApplyGuardrailScope(details, agent_details, request=None, user_details=None, span_details=None)[source]
Bases:
OpenTelemetryScopeProvides OpenTelemetry tracing scope for security guardrail evaluations.
Guardian spans SHOULD be children of the operation span they are protecting (e.g., inference or execute_tool spans). Multiple guardian spans MAY exist under a single operation span if multiple guardians are chained.
Example usage:
from microsoft.opentelemetry.a365.core import ( ApplyGuardrailScope, GuardrailDetails, AgentDetails, GuardrailDecisionType, GuardrailTargetType, GuardrailRiskSeverity, GuardrailFinding, ) details = GuardrailDetails( target_type=GuardrailTargetType.LLM_INPUT, decision_type=GuardrailDecisionType.ALLOW, guardian_name="Azure Content Safety", ) with ApplyGuardrailScope.start(details, agent_details) as scope: # ... run guardrail evaluation ... scope.record_finding(GuardrailFinding( risk_category="hate_speech", risk_severity=GuardrailRiskSeverity.HIGH, risk_score=0.95, )) scope.record_decision(GuardrailDecisionType.DENY, "Blocked by policy")
- static start(details, agent_details, request=None, user_details=None, span_details=None)[source]
Create and start a new scope for guardrail evaluation tracing.
- Parameters:
details (
GuardrailDetails) – Guardrail evaluation details (required).agent_details (
AgentDetails) – Agent identity details (required).request (
Request|None) – Optional request context (conversation ID, channel, content).user_details (
UserDetails|None) – Optional human user details.span_details (
SpanDetails|None) – Optional span configuration (parent context, timing, kind).
- Return type:
- Returns:
A new ApplyGuardrailScope instance.
- record_decision(decision_type, reason=None)[source]
Update the guardrail decision on the span.
Use this to update the decision mid-flight if the initial decision changes after evaluation completes.
- record_content_output(output_value)[source]
Record the sanitized/modified output content (opt-in).
This is an opt-in field for recording output content after guardrail processing. Only set this when content capture is explicitly enabled.
- record_content_input(input_value)[source]
Record the input content being evaluated (opt-in).
This is an opt-in field for recording input content sent to the guardrail. Only set this when content capture is explicitly enabled.
Accepts plain strings or structured
InputMessagescontainers. Structured messages are normalized and serialized to a JSON string before being set as an attribute.- Parameters:
input_value (
Union[str,list[str],InputMessages]) – The input content as a string or InputMessagesParam.- Return type:
- record_finding(finding)[source]
Record a security finding as a span event.
Each call adds a separate
microsoft.security.findingevent to the span. Multiple findings can be recorded for a single guardrail evaluation.- Parameters:
finding (
GuardrailFinding) – The security finding to record.- Return type:
- class microsoft.opentelemetry.a365.core.ExecuteToolScope(request, details, agent_details, user_details=None, span_details=None)[source]
Bases:
OpenTelemetryScopeProvides OpenTelemetry tracing scope for AI tool execution operations.
- static start(request, details, agent_details, user_details=None, span_details=None)[source]
Creates and starts a new scope for tool execution tracing.
- Parameters:
request (
Request) – Request details for the tool executiondetails (
ToolCallDetails) – The details of the tool callagent_details (
AgentDetails) – The details of the agent making the calluser_details (
UserDetails|None) – Optional human user detailsspan_details (
SpanDetails|None) – Optional span configuration (parent context, timing, kind)
- Return type:
- Returns:
A new ExecuteToolScope instance
- class microsoft.opentelemetry.a365.core.InvokeAgentScope(request, scope_details, agent_details, caller_details=None, span_details=None)[source]
Bases:
OpenTelemetryScopeProvides OpenTelemetry tracing scope for AI agent invocation operations.
- static start(request, scope_details, agent_details, caller_details=None, span_details=None)[source]
Create and start a new scope for agent invocation tracing.
- Parameters:
request (
Request) – Request details for the invocationscope_details (
InvokeAgentScopeDetails) – Scope-level configuration (endpoint)agent_details (
AgentDetails) – The details of the agent being invokedcaller_details (
CallerDetails|None) – Optional composite caller details (human user and/or calling agent for A2A scenarios)span_details (
SpanDetails|None) – Optional span configuration (parent context, timing, kind)
- Return type:
- Returns:
A new InvokeAgentScope instance
- record_input_messages(messages)[source]
Record the input messages for telemetry tracking.
Accepts plain strings (auto-wrapped as OTEL ChatMessage with role
user) or a structuredInputMessagescontainer.- Parameters:
messages (
Union[str,list[str],InputMessages]) – List of input message strings or an InputMessages container- Return type:
- record_output_messages(messages)[source]
Record the output messages for telemetry tracking.
Accepts plain strings (auto-wrapped as OTEL OutputMessage with role
assistant) or a structuredOutputMessagescontainer.- Parameters:
messages (
Union[str,list[str],OutputMessages]) – List of output message strings or an OutputMessages container- Return type:
- class microsoft.opentelemetry.a365.core.InferenceScope(request, details, agent_details, user_details=None, span_details=None)[source]
Bases:
OpenTelemetryScopeProvides 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 inferencedetails (
InferenceCallDetails) – The details of the inference callagent_details (
AgentDetails) – The details of the agent making the calluser_details (
UserDetails|None) – Optional human user detailsspan_details (
SpanDetails|None) – Optional span configuration (parent context, timing)
- Return type:
- 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 structuredInputMessagescontainer.- Parameters:
messages (
Union[str,list[str],InputMessages]) – List of input message strings or an InputMessages container- Return type:
- 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 structuredOutputMessagescontainer.- Parameters:
messages (
Union[str,list[str],OutputMessages]) – List of output message strings or an OutputMessages container- Return type:
- record_input_tokens(input_tokens)[source]
Records the number of input tokens for telemetry tracking.
- record_output_tokens(output_tokens)[source]
Records the number of output tokens for telemetry tracking.
- class microsoft.opentelemetry.a365.core.OutputScope(request, response, agent_details, user_details=None, span_details=None)[source]
Bases:
OpenTelemetryScopeProvides OpenTelemetry tracing scope for output messages.
Output messages are set once (via the constructor or
record_output_messages) rather than accumulated. For streaming scenarios, the agent developer should collect all output (e.g. via a list or string builder) and pass the final result toOutputScope.- static start(request, response, agent_details, user_details=None, span_details=None)[source]
Creates and starts a new scope for output tracing.
- Parameters:
request (
Request) – Request details for the outputresponse (
Response) – The response details from the agentagent_details (
AgentDetails) – The details of the agentuser_details (
UserDetails|None) – Optional human user detailsspan_details (
SpanDetails|None) – Optional span configuration (parent context, timing)
- Return type:
- Returns:
A new OutputScope instance
- record_output_messages(messages)[source]
Records the output messages for telemetry tracking.
Overwrites any previously set output messages. Accepts a single string, a list of strings (auto-wrapped as OTEL OutputMessage), a structured
OutputMessagescontainer, or adict[str, object]for tool call results (per OTEL spec).
- class microsoft.opentelemetry.a365.core.GuardrailDecisionType[source]
Bases:
objectWell-known guardrail decision type values.
- ALLOW = 'allow'
- AUDIT = 'audit'
- DENY = 'deny'
- MODIFY = 'modify'
- WARN = 'warn'
- class microsoft.opentelemetry.a365.core.GuardrailDetails(target_type, decision_type, guardian_name=None, guardian_id=None, guardian_provider_name=None, guardian_version=None, target_id=None, decision_reason=None, decision_code=None, policy_id=None, policy_name=None, policy_version=None, content_input_hash=None, content_modified=None, external_event_id=None)[source]
Bases:
objectImmutable input contract describing a guardrail evaluation.
- Variables:
target_type – What content is being guarded (e.g., “llm_input”, “tool_call”).
decision_type – The guardian’s decision (e.g., “allow”, “deny”).
guardian_name – Human-readable guardian name.
guardian_id – Unique guardian identifier.
guardian_provider_name – Provider name (e.g., “azure.ai.content_safety”).
guardian_version – Guardian version string.
target_id – ID of the targeted content.
decision_reason – Human-readable decision reason.
decision_code – Machine-readable decision code.
policy_id – Triggered policy ID.
policy_name – Triggered policy name.
policy_version – Policy version.
content_input_hash – Hash of input content for forensic correlation.
content_modified – Whether the content was altered by the guardrail.
external_event_id – External event ID for SIEM correlation.
- class microsoft.opentelemetry.a365.core.GuardrailFinding(risk_category, risk_severity, policy_decision_type=None, policy_id=None, policy_name=None, policy_version=None, risk_score=None, risk_metadata=None)[source]
Bases:
objectA single security finding from a guardrail evaluation.
- Variables:
risk_category – Category of risk detected (e.g., “hate_speech”, “pii”, “jailbreak”).
risk_severity – Severity level (use GuardrailRiskSeverity constants).
policy_decision_type – Per-finding decision override.
policy_id – Policy that triggered this finding.
policy_name – Policy name.
policy_version – Policy version.
risk_score – Confidence score from 0.0 to 1.0.
risk_metadata – Non-PII structural metadata about the finding.
- class microsoft.opentelemetry.a365.core.GuardrailRiskSeverity[source]
Bases:
objectWell-known risk severity level values.
- NONE = 'none'
- LOW = 'low'
- MEDIUM = 'medium'
- HIGH = 'high'
- CRITICAL = 'critical'
- class microsoft.opentelemetry.a365.core.GuardrailTargetType[source]
Bases:
objectWell-known guardrail target type values.
Users may also supply custom string values not listed here.
- LLM_INPUT = 'llm_input'
- LLM_OUTPUT = 'llm_output'
- TOOL_CALL = 'tool_call'
- TOOL_DEFINITION = 'tool_definition'
- MEMORY_STORE = 'memory_store'
- MEMORY_RETRIEVE = 'memory_retrieve'
- KNOWLEDGE_QUERY = 'knowledge_query'
- KNOWLEDGE_RESULT = 'knowledge_result'
- MESSAGE = 'message'
- class microsoft.opentelemetry.a365.core.BaggageBuilder[source]
Bases:
objectPer request baggage builder.
This class provides a fluent API for setting baggage values that will be propagated in the OpenTelemetry context.
Example
builder = (BaggageBuilder() .tenant_id("tenant-123") .agent_id("agent-456")) with builder.build(): # Baggage is set in this context pass # Baggage is restored after exiting the context
- operation_source(value)[source]
Set the operation source baggage value.
This captures the name of the service using the SDK.
- tenant_id(value)[source]
Set the tenant ID baggage value.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- agent_id(value)[source]
Set the agent ID baggage value.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- agentic_user_id(value)[source]
Set the agentic user ID baggage value.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- agentic_user_email(value)[source]
Set the agentic user email baggage value.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- agent_blueprint_id(value)[source]
Set the agent blueprint ID baggage value.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- user_id(value)[source]
Set the user ID baggage value.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- invoke_agent_server(address, port=None)[source]
Set the invoke agent server address and port baggage values.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- channel_name(value)[source]
Sets the channel name baggage value (e.g., ‘Teams’, ‘msteams’).
- Return type:
- class microsoft.opentelemetry.a365.core.InvokeAgentScopeDetails(endpoint=None)[source]
Bases:
objectScope-level configuration for agent invocation tracing.
- endpoint: ServiceEndpoint | None = None
- class microsoft.opentelemetry.a365.core.AgentDetails(agent_id, agent_name=None, agent_description=None, agentic_user_id=None, agentic_user_email=None, agent_blueprint_id=None, agent_platform_id=None, tenant_id=None, icon_uri=None, provider_name=None, agent_version=None)[source]
Bases:
objectDetails about an AI agent in the system.
- class microsoft.opentelemetry.a365.core.CallerDetails(user_details=None, caller_agent_details=None)[source]
Bases:
objectComposite caller details for agent-to-agent (A2A) scenarios.
Groups the human caller identity and the calling agent identity together.
- user_details: UserDetails | None = None
Details about the human user in the call chain.
- caller_agent_details: AgentDetails | None = None
Details about the calling agent in A2A scenarios.
- class microsoft.opentelemetry.a365.core.UserDetails(user_id=None, user_email=None, user_name=None, user_client_ip=None)[source]
Bases:
objectDetails about the human user that invoked an agent.
- class microsoft.opentelemetry.a365.core.ToolCallDetails(tool_name, arguments=None, tool_call_id=None, description=None, tool_type=None, endpoint=None)[source]
Bases:
objectDetails of a tool call made by an agent in the system.
- endpoint: ServiceEndpoint | None = None
- class microsoft.opentelemetry.a365.core.Channel(name=None, link=None)[source]
Bases:
objectChannel information for agent execution context.
- class microsoft.opentelemetry.a365.core.Request(content=None, session_id=None, channel=None, conversation_id=None)[source]
Bases:
objectRequest details for agent execution.
- class microsoft.opentelemetry.a365.core.Response(messages)[source]
Bases:
objectResponse details from agent execution.
Accepts plain strings (backward compat), structured
OutputMessages, or adictfor tool call results (per OTEL spec).
- class microsoft.opentelemetry.a365.core.SpanDetails(span_kind=None, parent_context=None, start_time=None, end_time=None, span_links=None)[source]
Bases:
objectGroups span configuration for scope construction.
- class microsoft.opentelemetry.a365.core.InferenceCallDetails(operationName, model, providerName, inputTokens=None, outputTokens=None, finishReasons=None, thoughtProcess=None, endpoint=None)[source]
Bases:
objectDetails of an inference call for generative AI operations.
- operationName: InferenceOperationType
- endpoint: ServiceEndpoint | None = None
- class microsoft.opentelemetry.a365.core.ServiceEndpoint(hostname, port=None)[source]
Bases:
objectRepresents a service endpoint with hostname and optional port.
- class microsoft.opentelemetry.a365.core.InferenceOperationType(value)[source]
Bases:
EnumSupported inference operation types for generative AI.
- CHAT = 'Chat'
- TEXT_COMPLETION = 'TextCompletion'
- GENERATE_CONTENT = 'GenerateContent'
- class microsoft.opentelemetry.a365.core.ToolType(value)[source]
Bases:
EnumEnumeration for different tool types for execute tool contexts.
- FUNCTION = 'function'
- EXTENSION = 'extension'
- DATASTORE = 'datastore'
- class microsoft.opentelemetry.a365.core.MessageRole(value)[source]
Bases:
EnumRole of a message participant per OTEL gen-ai semantic conventions.
- SYSTEM = 'system'
- USER = 'user'
- ASSISTANT = 'assistant'
- TOOL = 'tool'
- class microsoft.opentelemetry.a365.core.FinishReason(value)[source]
Bases:
EnumReason a model stopped generating per OTEL gen-ai semantic conventions.
- STOP = 'stop'
- LENGTH = 'length'
- CONTENT_FILTER = 'content_filter'
- TOOL_CALL = 'tool_call'
- ERROR = 'error'
- class microsoft.opentelemetry.a365.core.Modality(value)[source]
Bases:
EnumMedia modality for blob, file, and URI parts.
- IMAGE = 'image'
- VIDEO = 'video'
- AUDIO = 'audio'
- class microsoft.opentelemetry.a365.core.TextPart(content)[source]
Bases:
objectPlain text content.
- class microsoft.opentelemetry.a365.core.ToolCallRequestPart(name, id=None, arguments=None)[source]
Bases:
objectA tool call requested by the model.
- class microsoft.opentelemetry.a365.core.ToolCallResponsePart(id=None, response=None)[source]
Bases:
objectResult of a tool call.
- class microsoft.opentelemetry.a365.core.ReasoningPart(content)[source]
Bases:
objectModel reasoning / chain-of-thought content.
- class microsoft.opentelemetry.a365.core.BlobPart(modality, content, mime_type=None)[source]
Bases:
objectInline binary data (base64-encoded).
- class microsoft.opentelemetry.a365.core.FilePart(modality, file_id, mime_type=None)[source]
Bases:
objectReference to a pre-uploaded file.
- class microsoft.opentelemetry.a365.core.UriPart(modality, uri, mime_type=None)[source]
Bases:
objectExternal URI reference.
- class microsoft.opentelemetry.a365.core.ServerToolCallPart(name, server_tool_call, id=None)[source]
Bases:
objectServer-side tool invocation.
- class microsoft.opentelemetry.a365.core.ServerToolCallResponsePart(server_tool_call_response, id=None)[source]
Bases:
objectServer-side tool response.
- class microsoft.opentelemetry.a365.core.GenericPart(type, data=<factory>)[source]
Bases:
objectExtensible part for custom / future types.
- class microsoft.opentelemetry.a365.core.ChatMessage(role, parts=<factory>, name=None)[source]
Bases:
objectAn input message sent to a model (OTEL gen-ai semantic conventions).
- role: MessageRole
- parts: list[TextPart | ToolCallRequestPart | ToolCallResponsePart | ReasoningPart | BlobPart | FilePart | UriPart | ServerToolCallPart | ServerToolCallResponsePart | GenericPart]
- class microsoft.opentelemetry.a365.core.OutputMessage(role, parts=<factory>, name=None, finish_reason='stop')[source]
Bases:
ChatMessageAn output message produced by a model (OTEL gen-ai semantic conventions).
finish_reasondefaults to"stop"per OTel spec when not provided.
- class microsoft.opentelemetry.a365.core.InputMessages(messages=<factory>)[source]
Bases:
objectContainer for input messages. Serializes as a plain JSON array per OTel spec.
- messages: list[ChatMessage]
- class microsoft.opentelemetry.a365.core.OutputMessages(messages=<factory>)[source]
Bases:
objectContainer for output messages. Serializes as a plain JSON array per OTel spec.
- messages: list[OutputMessage]
Subpackages
- microsoft.opentelemetry.a365.core.exporters package
- Submodules
- microsoft.opentelemetry.a365.core.exporters.agent365_exporter module
- microsoft.opentelemetry.a365.core.exporters.agent365_exporter_options module
- microsoft.opentelemetry.a365.core.exporters.enriched_span module
- microsoft.opentelemetry.a365.core.exporters.enriching_span_processor module
- microsoft.opentelemetry.a365.core.exporters.span_processor module
- microsoft.opentelemetry.a365.core.exporters.spectra_exporter_options module
- microsoft.opentelemetry.a365.core.exporters.utils module
hex_trace_id()hex_span_id()kind_name()status_name()truncate_span()filter_and_partition_by_identity()get_validated_domain_override()build_export_url()parse_retry_after()is_agent365_exporter_enabled()estimate_value_bytes()estimate_span_bytes()chunk_by_size()A365Handlersis_a365_enabled()create_a365_components()
- Submodules
- microsoft.opentelemetry.a365.core.middleware package
BaggageBuilderBaggageBuilder.operation_source()BaggageBuilder.tenant_id()BaggageBuilder.agent_id()BaggageBuilder.agentic_user_id()BaggageBuilder.agentic_user_email()BaggageBuilder.agent_blueprint_id()BaggageBuilder.user_id()BaggageBuilder.agent_name()BaggageBuilder.agent_description()BaggageBuilder.agent_version()BaggageBuilder.user_name()BaggageBuilder.user_email()BaggageBuilder.user_client_ip()BaggageBuilder.invoke_agent_server()BaggageBuilder.conversation_id()BaggageBuilder.conversation_item_link()BaggageBuilder.session_id()BaggageBuilder.session_description()BaggageBuilder.channel_name()BaggageBuilder.channel_links()BaggageBuilder.set_pairs()BaggageBuilder.build()
- Submodules
- microsoft.opentelemetry.a365.core.models package
- Submodules
- microsoft.opentelemetry.a365.core.models.caller_details module
- microsoft.opentelemetry.a365.core.models.messages module
- microsoft.opentelemetry.a365.core.models.response module
- microsoft.opentelemetry.a365.core.models.service_endpoint module
- microsoft.opentelemetry.a365.core.models.user_details module
- Submodules
- microsoft.opentelemetry.a365.core.spans_scopes package
Submodules
- microsoft.opentelemetry.a365.core.agent_details module
- microsoft.opentelemetry.a365.core.apply_guardrail_scope module
- microsoft.opentelemetry.a365.core.channel module
- microsoft.opentelemetry.a365.core.constants module
- microsoft.opentelemetry.a365.core.enricher_utils module
- microsoft.opentelemetry.a365.core.execute_tool_scope module
- microsoft.opentelemetry.a365.core.guardrail_decision_type module
- microsoft.opentelemetry.a365.core.guardrail_details module
GuardrailDetailsGuardrailDetails.target_typeGuardrailDetails.decision_typeGuardrailDetails.guardian_nameGuardrailDetails.guardian_idGuardrailDetails.guardian_provider_nameGuardrailDetails.guardian_versionGuardrailDetails.target_idGuardrailDetails.decision_reasonGuardrailDetails.decision_codeGuardrailDetails.policy_idGuardrailDetails.policy_nameGuardrailDetails.policy_versionGuardrailDetails.content_input_hashGuardrailDetails.content_modifiedGuardrailDetails.external_event_id
- microsoft.opentelemetry.a365.core.guardrail_finding module
- microsoft.opentelemetry.a365.core.guardrail_risk_severity module
- microsoft.opentelemetry.a365.core.guardrail_target_type module
- microsoft.opentelemetry.a365.core.inference_call_details module
- microsoft.opentelemetry.a365.core.inference_operation_type module
- microsoft.opentelemetry.a365.core.inference_scope module
- microsoft.opentelemetry.a365.core.invoke_agent_details module
- microsoft.opentelemetry.a365.core.invoke_agent_scope module
- microsoft.opentelemetry.a365.core.message_utils module
- microsoft.opentelemetry.a365.core.opentelemetry_scope module
OpenTelemetryScopeOpenTelemetryScope.record_error()OpenTelemetryScope.record_response()OpenTelemetryScope.record_cancellation()OpenTelemetryScope.set_tag_maybe()OpenTelemetryScope.record_attributes()OpenTelemetryScope.set_end_time()OpenTelemetryScope.get_context()OpenTelemetryScope.inject_context_to_headers()OpenTelemetryScope.dispose()
- microsoft.opentelemetry.a365.core.request module
- microsoft.opentelemetry.a365.core.span_details module
- microsoft.opentelemetry.a365.core.tool_call_details module
- microsoft.opentelemetry.a365.core.tool_type module
- microsoft.opentelemetry.a365.core.utils module