Skip to content

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
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

wrisa
Copy link
Contributor

@wrisa wrisa commented Jul 30, 2025

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • From test folder /opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-langchain/tests run pytest -rP test_llm_call.py

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@wrisa wrisa marked this pull request as ready for review August 1, 2025 01:50
@wrisa wrisa requested a review from a team as a code owner August 1, 2025 01:50
Copy link
Member

@pmcollins pmcollins left a 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.

@wrisa wrisa force-pushed the genai-instrumentation-langchain-spans branch from 3940934 to 072b0fd Compare August 4, 2025 21:43
@wrisa wrisa force-pushed the genai-instrumentation-langchain-spans branch from 3ee1d40 to 8723786 Compare August 12, 2025 04:43
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.

8 participants