Repository navigation
Conversation
Implement text-completion inference spans and keep chat spans when model names are unavailable. Assisted-by: OpenAI Codex Signed-off-by: Amrinder Randhawa <[email protected]>
|
Pull request dashboard statusWaiting on the author · refreshed 2026-11-03 19:18 UTC Two things need attention:
Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
BaseLLM completion spans are not propagated as the current execution context, causing incorrect provider-span parenting, and available text-completion token counts are omitted from usage attributes and metrics.
2 open issues
What changed in this PR
This PR addresses #1023 by extending LangChain callback instrumentation to trace text-completion calls and chat calls without a detectable model name.
Changes:
- Adds
text_completionspans and captures completion content through shared GenAI models. - Preserves chat spans when the request model name is unavailable.
- Adds callback tests and updates agent-span expectations to include newly traced child inference spans.
| File | Description |
|---|---|
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_operation_mapping.py |
Updates expected inference spans and parent relationships. |
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py |
Tests sync/async completions and nameless chat callbacks. |
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_agent_classification_corpus.py |
Includes child chat spans in agent expectations. |
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/conftest.py |
Maps completion operations to duration metrics. |
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/operation_mapping.py |
Adds the semantic-convention completion operation constant. |
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py |
Shares model-start handling and captures text-generation results. |
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/1024.fixed |
Records the expanded inference-span coverage. |
Review effort: Balanced
Comment on lines
+517
to
+520
| self._on_model_start( | ||
| serialized, | ||
| input_messages=input_messages, | ||
| operation_name=OperationName.TEXT_COMPLETION, |
Comment on lines
+828
to
+829
| if finish_reason: | ||
| finish_reasons.append(finish_reason) |
Propagate text-completion invocation context through sync, async, and streaming BaseLLM boundaries. Record token usage reported in LLMResult output without overriding message-level usage. Assisted-by: OpenAI Codex Signed-off-by: Amrinder Randhawa <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #1023. Adds
text_completioninference spans foron_llm_startcallbacks and preserves chat inference spans when the request model name is unavailable. Text-completion inputs and outputs are captured through the shared GenAI content models, and existing agent-span expectations now include the previously missing child inference spans.Tests:
uv run tox -e py311-test-instrumentation-genai-langchain-latestuv run tox -e py311-test-instrumentation-genai-langchain-oldestuv run tox -e typecheckuv run tox -e precommituv run tox -e changelog-preview