feat(langchain): emit GenAI request attributes - #213
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eb3eb7d to
02f1d14
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds LangChain instrumentation support for emitting GenAI request-related OpenTelemetry attributes (including output type) from extra.invocation_params, with validation/normalization and expanded unit test coverage.
Changes:
- Introduces new GenAI semantic convention constants for request parameters and
gen_ai.output.type. - Adds
setRequestAttributesto LangChain utils and wires it into the LangChain tracer. - Expands unit tests to cover mapping/normalization and exporter payload preservation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/internal/unit/genai/langchain/utils.test.ts | Adds focused unit tests for setRequestAttributes mapping/validation behavior. |
| test/internal/unit/genai/langchain/tracer.test.ts | Verifies tracer emits request attributes/output type onto spans. |
| test/internal/unit/a365/agent365Exporter.test.ts | Ensures A365 exporter payload preserves new GenAI attributes. |
| src/genai/semconv.ts | Defines new gen_ai.* attribute constants used by instrumentation. |
| src/genai/instrumentations/langchain/utils.ts | Implements request attribute extraction, normalization, and type validation. |
| src/genai/instrumentations/langchain/tracer.ts | Hooks request attribute setting into span creation flow. |
| CHANGELOG.md | Documents the new instrumentation feature under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 0110be1.
Match upstream OpenTelemetry GenAI instrumentations by accepting typed provider parameters without coercing numeric or boolean strings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Radhika Gupta (rads-1996)
left a comment
There was a problem hiding this comment.
LGTM. The entire test suite is however not being run still.
We don't currently have perf or integration tests for this project. Need to migrate them over from others. Have a follow up task for this. |


Summary
extra.invocation_paramson chat spansgen_ai.output.typefrom explicit output types and structured response formats, restricted to the documentedtext,json, andimagevaluesgen_ai.*attribute namesAttributes
gen_ai.output.typegen_ai.request.temperaturegen_ai.request.top_pgen_ai.request.top_kgen_ai.request.max_tokensgen_ai.request.frequency_penaltygen_ai.request.presence_penaltygen_ai.request.seedgen_ai.request.stop_sequencesgen_ai.request.streamInput normalization
top_p,max_completion_tokens,frequency_penalty, andresponse_formatmaxOutputTokens,topK,topP, andstopSequencesjson_objectandjson_schematojson, andb64_jsonandurltoimageValidation
@langchain/openai1.5.5 and@langchain/core1.2.3; the ingested span retained expected typed values for temperature, top-p, max tokens, penalties, seed, stop sequences, stream, and JSON output typeA365 compatibility
gen_ai.request.temperature,gen_ai.request.top_p, andgen_ai.request.max_tokensare already defined by the upstream Agent365 JS constantsUpstream assessment
Current LangChain.js exposes these values as raw callback
invocation_paramsbut does not map them to OpenTelemetrygen_ai.*attributes, so the distro remains the appropriate implementation layer.