Skip to content

Add OTel-compliant span status to ETW DTO logging path#127

Merged
nikhilNava merged 2 commits into
mainfrom
nikhilNava/etw-span-status
Jun 26, 2026
Merged

Add OTel-compliant span status to ETW DTO logging path#127
nikhilNava merged 2 commits into
mainfrom
nikhilNava/etw-span-status

Conversation

@nikhilNava

Copy link
Copy Markdown
Collaborator

Summary

Records an OTel-spec-compliant span status (and error.type) on the ETW DTO logging path (Path B), which previously dropped status entirely. The Activity-based path (Path A) already emits status via ExportFormatter.FormatSingle; this brings Path B (A365EtwLogger -> *DataBuilder -> BaseData -> ExportFormatter.FormatLogData) to parity.

Ports microsoft/Agent365-dotnet#259 into this distro repo (paths mapped from src/Observability/Runtime/... to src/Microsoft.OpenTelemetry/Agent365/Runtime/...).

What changed

  • New (DTOs/) - SpanStatusCode enum (Unset=0/Ok=1/Error=2, mapping onto OTLP Status.StatusCode), SpanStatus struct, and SpanStatusBuilder (central Exception -> status + error.type mapping, mirroring OpenTelemetryScope.RecordError).
  • BaseData - adds StatusCode/StatusMessage; ToDictionary() now emits Status { code, message }.
  • Builders / logger - optional Exception? error = null threaded through all 5 *DataBuilder.Build methods (via a shared ApplyStatus helper on BaseDataBuilder), plus A365EtwLogger and IA365EtwLogger.
  • ExportFormatter.FormatLogData - emits the Status object (defaults to { code: 0, message: "" } when absent).
  • PublicAPI.Unshipped.txt - new public types/members plus *REMOVED* markers for the modified shipped signatures (PublicApiAnalyzers compliance).

Emitted shape (errored span)

"Attributes": { "...": "...", "error.type": "System.TimeoutException" },
"Status": { "code": 2, "message": "The operation timed out." }

With no error, Status defaults to Unset (code: 0) and error.type is absent. The optional error parameter keeps all existing call sites source-compatible.

Testing

  • dotnet build src/Microsoft.OpenTelemetry/Microsoft.OpenTelemetry.csproj - succeeds (0 errors across net8.0/net10.0/netstandard2.0).
  • dotnet test (Agent365 tests) - 461 passed, 3 skipped, 0 failed, including new SpanStatusBuilderTests, ExportFormatterStatusTests, and added BaseData/InvokeAgentDataBuilder status cases.

Note

The source PR's .github/copilot-instructions.md change is specific to the Agent365-dotnet repo and was intentionally not ported.

Records an OTel-spec-compliant span status (and error.type) on the ETW
DTO logging path (Path B), which previously dropped status entirely.
Brings it to parity with the Activity-based path (FormatSingle).

- New SpanStatusCode enum, SpanStatus struct, and SpanStatusBuilder
  (central Exception -> status + error.type mapping, mirroring
  OpenTelemetryScope.RecordError).
- BaseData: adds StatusCode/StatusMessage; ToDictionary emits Status.
- Optional Exception? error threaded through all 5 *DataBuilder.Build
  methods (via shared ApplyStatus on BaseDataBuilder), A365EtwLogger,
  and IA365EtwLogger.
- ExportFormatter.FormatLogData emits the Status object (defaults to
  { code: 0, message: "" } when absent).

Ports microsoft/Agent365-dotnet#259 into the distro repo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR brings the Agent365 ETW DTO logging path (Path B) up to parity with the Activity-based path by emitting an OpenTelemetry-compliant span Status (and error.type when applicable) for exported log payloads, ensuring errored operations carry status information instead of dropping it.

Changes:

  • Adds DTO types for span status (SpanStatusCode, SpanStatus) and a centralized SpanStatusBuilder to map Exception → status + error.type.
  • Threads an optional Exception? error = null through ETW logger APIs and all *DataBuilder.Build methods, applying status into BaseData.
  • Ensures BaseData.ToDictionary() and ExportFormatter.FormatLogData() include a Status object (defaulting to { code: 0, message: "" }).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/Microsoft.OpenTelemetry.Agent365.Tests/Runtime/DTOs/Builders/SpanStatusBuilderTests.cs Adds unit tests for exception→status mapping and error.type behavior.
test/Microsoft.OpenTelemetry.Agent365.Tests/Runtime/DTOs/Builders/InvokeAgentDataBuilderTests.cs Extends builder tests to cover status/error propagation.
test/Microsoft.OpenTelemetry.Agent365.Tests/Runtime/DTOs/BaseDataTests.cs Verifies BaseData default status and ToDictionary() status shape.
test/Microsoft.OpenTelemetry.Agent365.Tests/Runtime/Common/ExportFormatterStatusTests.cs Adds formatter tests to ensure Status is emitted and defaults correctly.
src/Microsoft.OpenTelemetry/Agent365/Runtime/Etw/IA365EtwLogger.cs Adds optional error parameter to ETW logging interface methods.
src/Microsoft.OpenTelemetry/Agent365/Runtime/Etw/A365EtwLogger.cs Wires error through implementation into DTO builders.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/SpanStatusCode.cs Introduces OTLP-aligned numeric status code enum.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/SpanStatus.cs Adds status value type carrying code + optional message.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/SpanStatusBuilder.cs Centralizes exception→status + error.type mapping for DTO path.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/OutputDataBuilder.cs Threads error into builder and applies status to output telemetry.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/InvokeAgentDataBuilder.cs Threads error into builder and applies status to invoke_agent telemetry.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/ExecuteToolDataBuilder.cs Threads error into builder and applies status to execute_tool telemetry.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/ExecuteInferenceDataBuilder.cs Threads error into builder and applies status to inference telemetry.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/BaseDataBuilder.cs Adds ApplyStatus helper to set status and write error.type.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/Builders/ApplyGuardrailDataBuilder.cs Threads error into builder and applies status to guardrail telemetry.
src/Microsoft.OpenTelemetry/Agent365/Runtime/DTOs/BaseData.cs Adds status fields and emits Status {code,message} in ToDictionary().
src/Microsoft.OpenTelemetry/Agent365/Runtime/Common/ExportFormatter.cs Emits Status in formatted log payload with sensible defaults.
src/Microsoft.OpenTelemetry/.publicApi/PublicAPI.Unshipped.txt Records new public surface area and signature changes for analyzers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Microsoft.OpenTelemetry/Agent365/Runtime/Etw/IA365EtwLogger.cs
Addresses PR feedback: error.type is not part of the reserved-key filter
for extraAttributes, so a caller could pass it through and have it emitted
while status stayed Unset. FromError now removes any pre-existing error.type
attribute on the no-error path, ensuring error.type is never present without
an accompanying error status.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nikhilNava nikhilNava enabled auto-merge (squash) June 26, 2026 19:49
@nikhilNava nikhilNava merged commit 0cac234 into main Jun 26, 2026
10 checks passed
@nikhilNava nikhilNava deleted the nikhilNava/etw-span-status branch June 26, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants