Skip to content

feat(langchain): emit GenAI request attributes - #213

Merged
Jackson Weber (JacksonWeber) merged 9 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/langchain-genai-request-attributes
Aug 11, 2026
Merged

feat(langchain): emit GenAI request attributes#213
Jackson Weber (JacksonWeber) merged 9 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/langchain-genai-request-attributes

Conversation

@JacksonWeber

@JacksonWeber Jackson Weber (JacksonWeber) commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • emit available GenAI request parameters from LangChain extra.invocation_params on chat spans
  • derive gen_ai.output.type from explicit output types and structured response formats, restricted to the documented text, json, and image values
  • accept OpenAI-style snake_case and provider/LangChain camelCase input aliases while emitting only OpenTelemetry gen_ai.* attribute names
  • preserve typed provider values without coercing numeric or boolean strings

Attributes

  • gen_ai.output.type
  • gen_ai.request.temperature
  • gen_ai.request.top_p
  • gen_ai.request.top_k
  • gen_ai.request.max_tokens
  • gen_ai.request.frequency_penalty
  • gen_ai.request.presence_penalty
  • gen_ai.request.seed
  • gen_ai.request.stop_sequences
  • gen_ai.request.stream

Input normalization

  • supports OpenAI-style keys such as top_p, max_completion_tokens, frequency_penalty, and response_format
  • supports camelCase keys exposed by LangChain provider integrations, including Google's documented maxOutputTokens, topK, topP, and stopSequences
  • maps provider response-format aliases such as json_object and json_schema to json, and b64_json and url to image
  • ignores unsupported output types, malformed values, non-integer integer attributes, and string representations of numeric or boolean values

Validation

  • LangChain unit, tracer, and functional suites pass
  • A365 exporter and span-processor suites pass
  • lint, formatting, and build pass
  • live Azure OpenAI invocation validated against Application Insights using @langchain/openai 1.5.5 and @langchain/core 1.2.3; the ingested span retained expected typed values for temperature, top-p, max tokens, penalties, seed, stop sequences, stream, and JSON output type

A365 compatibility

  • the Agent365 exporter copies span attributes into its OTLP-like payload without renaming or coercion
  • added a regression test proving the complete new attribute set retains its string, number, boolean, and string-array types in the A365 payload
  • gen_ai.request.temperature, gen_ai.request.top_p, and gen_ai.request.max_tokens are already defined by the upstream Agent365 JS constants
  • all emitted keys and types follow the current OpenTelemetry GenAI semantic conventions; A365 identity partitioning and message truncation behavior are unchanged

Upstream assessment

Current LangChain.js exposes these values as raw callback invocation_params but does not map them to OpenTelemetry gen_ai.* attributes, so the distro remains the appropriate implementation layer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JacksonWeber
Jackson Weber (JacksonWeber) force-pushed the jacksonweber/langchain-genai-request-attributes branch from eb3eb7d to 02f1d14 Compare August 6, 2026 17:41
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

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 setRequestAttributes to 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.

Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/instrumentations/langchain/utils.ts Outdated
Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/instrumentations/langchain/utils.ts Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rads-1996

Copy link
Copy Markdown
Member
image

where did the other checks go? Is it a github issue?

Comment thread CHANGELOG.md Outdated
@JacksonWeber

Copy link
Copy Markdown
Contributor Author
image where did the other checks go? Is it a github issue?

Interesting, yeah. There were issues with github actions yesterday. Let me fix this one.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/genai/instrumentations/langchain/utils.ts Outdated
Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/instrumentations/langchain/utils.ts Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/genai/instrumentations/langchain/utils.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
@JacksonWeber
Jackson Weber (JacksonWeber) marked this pull request as draft August 8, 2026 22:22
@JacksonWeber
Jackson Weber (JacksonWeber) marked this pull request as ready for review August 8, 2026 22:30
@JacksonWeber
Jackson Weber (JacksonWeber) marked this pull request as draft August 8, 2026 22:58
@JacksonWeber
Jackson Weber (JacksonWeber) marked this pull request as ready for review August 10, 2026 19:07
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@rads-1996 Radhika Gupta (rads-1996) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. The entire test suite is however not being run still.

@JacksonWeber

Copy link
Copy Markdown
Contributor Author

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.

@JacksonWeber
Jackson Weber (JacksonWeber) merged commit f876546 into microsoft:main Aug 11, 2026
4 checks passed
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.

3 participants