-
Notifications
You must be signed in to change notification settings - Fork 758
Added span support for genAI langchain llm invocation #3665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wrisa
wants to merge
19
commits into
open-telemetry:main
Choose a base branch
from
wrisa:genai-instrumentation-langchain-spans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added span support for genAI langchain llm invocation #3665
wrisa
wants to merge
19
commits into
open-telemetry:main
from
wrisa:genai-instrumentation-langchain-spans
+1,088
−4
Conversation
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
...ntelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/__init__.py
Outdated
Show resolved
Hide resolved
pmcollins
reviewed
Aug 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together. Added some comments.
...opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/utils.py
Outdated
Show resolved
Hide resolved
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Outdated
Show resolved
Hide resolved
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Outdated
Show resolved
Hide resolved
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Outdated
Show resolved
Hide resolved
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Outdated
Show resolved
Hide resolved
instrumentation-genai/opentelemetry-instrumentation-langchain/pyproject.toml
Outdated
Show resolved
Hide resolved
3940934
to
072b0fd
Compare
singankit
reviewed
Aug 5, 2025
...emetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/span_manager.py
Outdated
Show resolved
Hide resolved
wrisa
commented
Aug 6, 2025
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Outdated
Show resolved
Hide resolved
singankit
reviewed
Aug 6, 2025
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Show resolved
Hide resolved
pmcollins
reviewed
Aug 6, 2025
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Show resolved
Hide resolved
pmcollins
reviewed
Aug 8, 2025
...emetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/span_manager.py
Outdated
Show resolved
Hide resolved
pmcollins
reviewed
Aug 8, 2025
...ry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py
Outdated
Show resolved
Hide resolved
pmcollins
reviewed
Aug 8, 2025
...emetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/span_manager.py
Outdated
Show resolved
Hide resolved
...emetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/span_manager.py
Outdated
Show resolved
Hide resolved
pmcollins
approved these changes
Aug 11, 2025
3ee1d40
to
8723786
Compare
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.
Description
Taking inspiration from traceloop's openllmetry support for langchain instrumentation, added callback handler support for llm start and end to generate span with attributes listed here.
Attributes added on span:
-> gen_ai.operation.name: Str(chat)
-> gen_ai.system: Str(ChatOpenAI)
-> gen_ai.request.model: Str(gpt-3.5-turbo)
-> gen_ai.request.top_p: Double(0.9)
-> gen_ai.request.frequency_penalty: Double(0.5)
-> gen_ai.request.presence_penalty: Double(0.5)
-> gen_ai.request.stop_sequences: Slice(["\n","Human:","AI:"])
-> gen_ai.request.seed: Int(100)
-> gen_ai.request.max_tokens: Int(100)
-> gen_ai.provider.name: Str(openai)
-> gen_ai.request.temperature: Double(0.1)
-> gen_ai.response.finish_reasons: Slice(["stop"])
-> gen_ai.response.model: Str(gpt-3.5-turbo-0125)
-> gen_ai.response.id: Str(chatcmpl-Bz8yrvPnydD9pObv625n2CGBPHS13)
-> gen_ai.usage.input_tokens: Int(24)
-> gen_ai.usage.output_tokens: Int(7)
Please refer complete span attributes o/p: https://docs.google.com/document/d/13SXuf4iZSl2MqWUJtmoDEqFxuHZ1Y8hykW_ctlykcDE/edit?tab=t.0
We have just added span support in this PR for now to keep this PR concise and in future we will have metric and log support PRs.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
pytest -rP test_llm_call.py
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.