Add OTEL gen-ai message format for auto-instrumented message tracing#231
Add OTEL gen-ai message format for auto-instrumented message tracing#231
Conversation
There was a problem hiding this comment.
Pull request overview
Adds OTEL gen-ai (version: "0.1.0") structured message recording across core scopes and the OpenAI/LangChain observability extensions, with gating via isContentRecordingEnabled and expanded compatibility for LangChain v1/LangGraph shapes.
Changes:
- Introduces structured
gen_ai.input.messages/gen_ai.output.messagesrecording (versioned envelope) and exports related message utilities/types from core. - Updates LangChain extension attribute extraction for v1 formats (tool outputs/call IDs, system instructions, token usage, model name, message detection).
- Adds a shared message schema validator helper plus new contract tests and updated unit tests for new serialization/overwrite semantics.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/observability/tracing/message-utils.test.ts | Removes isStringArray tests; focuses on wrapper detection/normalization behavior. |
| tests/observability/extension/openai/OpenAIMessageContract.test.ts | Adds OpenAI OTEL message contract tests for structured input/output builders and edge cases. |
| tests/observability/extension/openai/OpenAIAgentsTraceProcessor.test.ts | Updates OpenAI trace processor tests to assert versioned message envelopes + schema validation. |
| tests/observability/extension/langchain/LangChainObservabilityAttributes.test.ts | Updates expected message attributes to versioned envelopes; adds v1 coverage for tool/system/tokens. |
| tests/observability/extension/langchain/LangChainMessageContract.test.ts | Adds LangChain message contract tests using real LangChain message types + LangGraph path. |
| tests/observability/extension/hosting/TurnContextUtils.test.ts | Removes execution-type baggage tests consistent with removed API/constant. |
| tests/observability/extension/hosting/scope-utils.test.ts | Removes tenant-details derivation tests aligned with API removal. |
| tests/observability/extension/helpers/message-schema-validator.ts | Adds shared test helper for validating serialized OTEL message envelopes/parts. |
| tests/observability/core/scopes.test.ts | Refactors exporter setup; adds tests for request content → input messages + safe JSON serialization. |
| tests/observability/core/output-scope.test.ts | Updates OutputScope to overwrite semantics; adds tests for dict outputs and single-string paths. |
| tests/observability/core/agent365-exporter.test.ts | Adds truncation coverage for raw-dict gen_ai.output.messages vs versioned wrappers. |
| packages/agents-a365-observability/src/tracing/util.ts | Adds safeSerializeToJson helper for consistent JSON-safe span attributes. |
| packages/agents-a365-observability/src/tracing/scopes/OutputScope.ts | Changes output message recording to overwrite semantics; supports raw dict outputs. |
| packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts | Updates docs/behavior to accept single-string message params (input/output). |
| packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts | Auto-records Request.content as input messages; simplifies response recording API usage. |
| packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts | Allows spanKind override; serializes tool args/results via safeSerializeToJson. |
| packages/agents-a365-observability/src/tracing/message-utils.ts | Supports single-string message params; removes isStringArray guard. |
| packages/agents-a365-observability/src/tracing/exporter/utils.ts | Tightens “versioned wrapper” detection; improves shrink-action control flow; adds raw-JSON sentinel behavior. |
| packages/agents-a365-observability/src/tracing/contracts.ts | Removes ExecutionType/TenantDetails; widens message/tool argument types; introduces ResponseMessagesParam. |
| packages/agents-a365-observability/src/tracing/constants.ts | Removes GEN_AI_EXECUTION_TYPE_KEY. |
| packages/agents-a365-observability/src/index.ts | Updates public exports (types removed/added; exports message utilities). |
| packages/agents-a365-observability/docs/design.md | Removes ExecutionType enum from design docs. |
| packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts | Removes execution type extraction logic and related imports. |
| packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts | Removes tenant-details derivation helper and import. |
| packages/agents-a365-observability-hosting/src/utils/BaggageBuilderUtils.ts | Removes execution-type baggage population. |
| packages/agents-a365-observability-hosting/src/middleware/BaggageMiddleware.ts | Removes execution-type baggage injection in middleware. |
| packages/agents-a365-observability-hosting/docs/design.md | Updates hosting design docs to remove execution-type references. |
| packages/agents-a365-observability-extensions-openai/src/Utils.ts | Adds OTEL structured message builders/wrappers for OpenAI input/output formats. |
| packages/agents-a365-observability-extensions-openai/src/OpenAIAgentsTraceProcessor.ts | Auto-records structured input/output messages on response spans; removes execution-type filtering. |
| packages/agents-a365-observability-extensions-langchain/src/Utils.ts | Adds structured message attribute builders + v1-compatible extraction for tool/system/tokens/model. |
| .codereviews/claude-pr-toolupdate-20260408_154355.md | Adds consolidated external review artifact documenting prior findings/resolutions. |
…tput message tracing - OpenAI extension: Auto-record structured InputMessages/OutputMessages on response, generation, and function spans via OpenAIAgentsTraceProcessor with isContentRecordingEnabled option - LangChain extension: Auto-record structured InputMessages/OutputMessages on chat, invoke_agent, and execute_tool spans via LangChainTracer with isContentRecordingEnabled option - LangChain v1 support: Fix setToolAttributes to handle plain string tool results (v1 format), fix tool_call_id extraction from inputs, fix setSystemInstructionsAttribute to use getMessageType() for all message formats, fix setTokenAttributes to check last message for usage_metadata, fix getModel to check v1 direct response_metadata path - Add message-schema-validator test helper for validating OTEL gen-ai message contract - Add LangChainMessageContract and OpenAIMessageContract test suites Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CRM-001: Move GEN_AI_TOOL_TYPE_KEY setAttribute outside forEach loop - CRM-002: Wrap string output/input fallbacks in versioned OTEL message envelope - CRM-003: Support tokenUsage shape (promptTokens/completionTokens) in setTokenAttributes - CRM-009: Remove unused getAttributesFromInput export - CRM-010: Replace dead extractMessageContent with extractStringContent delegating to extractRawContent - CRM-011: Fix self-referential comment - CRM-006: Add direct v1 constructor format tests for input/output messages - CRM-007: Add response span content-gating suppression test - CRM-008: Add empty array and null entry edge case tests - CRM-013: Add function_call, input_file, malformed JSON, and unknown block type tests - Fix getMessageType to skip v1 'constructor' type and check id array for message class Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
928a65b to
4115a64
Compare
d66e8d4 to
45dd931
Compare
…tensions, align tool serialization - Remove isContentRecordingEnabled toggle: content recording is now ON by default (aligned with Python/.NET SDKs). suppressInvokeAgentInput remains. - Remove truncateValue from both extensions: truncation now happens at the span/exporter level in core, not pre-truncated in extensions. - Use safeSerializeToJson for tool arguments/results in both extensions, matching the core ExecuteToolScope pattern from PR #228. - Export safeSerializeToJson from core index.ts. - Add tool argument validation tests for both OpenAI and LangChain extensions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45dd931 to
22c0127
Compare
…JSDoc - processResponseSpanData: add else fallback for non-array output via wrapRawContentAsOutputMessages (handles object output) - mapInputContentBlock: map input_image to type 'blob' (matches BlobPart contract) instead of non-standard 'image' - Remove stale @param options JSDoc from LangChainTraceInstrumentor.instrument Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
packages/agents-a365-observability-extensions-openai/src/OpenAIAgentsTraceInstrumentor.ts:1
- Removing
isContentRecordingEnabledfrom the publicOpenAIAgentsInstrumentationConfig(and related constructor options) is a breaking API change for consumers. Consider keeping the option (even if ignored) and deprecating it first, or bump the major version and clearly document the behavioral change.
// ------------------------------------------------------------------------------
…ility, add missing expect import
- Replace hardcoded 1024 with MAX_SPAN_SIZE_BYTES in OpenAI extensions Utils
- Export MAX_SPAN_SIZE_BYTES from observability package
- Add missing `import { expect } from '@jest/globals'` to test helper
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7d13038 to
15fc5b7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
packages/agents-a365-observability-extensions-openai/src/OpenAIAgentsTraceInstrumentor.ts:1
- The public
OpenAIAgentsInstrumentationConfigoptionisContentRecordingEnabledwas removed, which is a breaking change for downstream consumers (and also changes behavior since content is now recorded unconditionally elsewhere in this PR). To avoid an unexpected breaking change, either (mandatory) reintroduce the option with the previous default (false) and keep the gating behavior, or (alternative) treat this as a major version change and document the behavioral/API change in release notes and package versioning.
// ------------------------------------------------------------------------------
nikhilNava
left a comment
There was a problem hiding this comment.
You can consider adding integration tests will get the exact structure from of input and output messages for auto instrumentation.
This might not cover scenarios like audio/file part etc
Summary
version: "0.1.0") for both OpenAI and LangChain extensions — content attributes are recorded unconditionally (no opt-in gating)MAX_SPAN_SIZE_BYTESconstant for binary field truncation instead of hardcoded valuesChanges
OpenAI Extension
OpenAIAgentsTraceProcessor: Auto-records structuredInputMessages/OutputMessageson response, generation, and function spans; all string fallbacks now use versioned envelopeUtils.ts: NewbuildStructuredInputMessages()andbuildStructuredOutputMessages()for OTEL gen-ai schema conversion; removed unusedgetAttributesFromInput; usesMAX_SPAN_SIZE_BYTESfor truncationLangChain Extension
LangChainTracer: Content attributes are recorded unconditionally — removedisContentRecordingEnabledoptionUtils.ts: New structured message builders (setInputMessagesAttribute,setOutputMessagesAttribute); v1 fixes forsetToolAttributes,setSystemInstructionsAttribute,setTokenAttributes,getModel,getMessageTypeCore
index.tsMAX_SPAN_SIZE_BYTESfrom observability packageTest plan
🤖 Generated with Claude Code