Skip to content

Conversation

@nagkumar91
Copy link
Contributor

@nagkumar91 nagkumar91 commented Oct 7, 2025

Description

This PR renames the package to opentelemetry-instrumentation-langchain-v2 and updates the collector to the latest spec.
This allows us to release the package as the official opentelemetry package.

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

  • Test A

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

Sample outputs

  1. examples/manual/main.py:
{
  "name": "chat gpt-4.1",
  "context": {
    "trace_id": "1ec262108b837224724eab77bedceaae",
    "span_id": "bc78d3a82d35ca59"
  },
  "parent_id": null,
  "start_time": "2025-10-20T20:06:17.074000Z",
  "end_time": "2025-10-20T20:06:18.047000Z",
  "status": {
    "code": 0,
    "message": null
  },
  "kind": "CLIENT",
  "events": [],
  "attributes": {
    "gen_ai.operation.name": "chat",
    "gen_ai.request.model": "gpt-4.1",
    "gen_ai.provider.name": "openai",
    "gen_ai.request.top_p": "0.9",
    "gen_ai.request.frequency_penalty": "0.5",
    "gen_ai.request.presence_penalty": "0.5",
    "gen_ai.request.stop_sequences": "{\"values\":[{\"stringValue\":\"\\n\",\"value\":\"string_value\"},{\"stringValue\":\"Human:\",\"value\":\"string_value\"},{\"stringValue\":\"AI:\",\"value\":\"string_value\"}]}",
    "gen_ai.request.seed": "100",
    "gen_ai.request.temperature": "0.1",
    "gen_ai.request.max_tokens": "100",
    "gen_ai.input.messages": "[{\"type\": \"system\", \"content\": \"You are a helpful assistant!\", \"additional_kwargs\": {}, \"response_metadata\": {}}, {\"type\": \"human\", \"content\": \"What is the capital of France?\", \"additional_kwargs\": {}, \"response_metadata\": {}}]",
    "gen_ai.usage.input_tokens": "24",
    "gen_ai.usage.output_tokens": "7",
    "gen_ai.response.finish_reasons": "{\"values\":[{\"stringValue\":\"stop\",\"value\":\"string_value\"}]}",
    "gen_ai.response.model": "gpt-4.1-2025-04-14",
    "gen_ai.response.id": "chatcmpl-CSqQzLwwhz6w65N2px0zEtaOESlY8",
    "openai.response.service_tier": "default",
    "openai.response.system_fingerprint": "fp_e24a1fec47",
    "gen_ai.output.messages": "[{\"type\": \"ai\", \"content\": \"The capital of France is Paris.\", \"additional_kwargs\": {\"refusal\": null}, \"response_metadata\": {\"token_usage\": {\"completion_tokens\": 7, \"prompt_tokens\": 24, \"total_tokens\": 31, \"completion_tokens_details\": {\"accepted_prediction_tokens\": 0, \"audio_tokens\": 0, \"reasoning_tokens\": 0, \"rejected_prediction_tokens\": 0}, \"prompt_tokens_details\": {\"audio_tokens\": 0, \"cached_tokens\": 0}}, \"model_name\": \"gpt-4.1-2025-04-14\", \"system_fingerprint\": \"fp_e24a1fec47\", \"id\": \"chatcmpl-CSqQzLwwhz6w65N2px0zEtaOESlY8\", \"service_tier\": \"default\", \"finish_reason\": \"stop\", \"logprobs\": null}, \"tool_calls\": [], \"usage_metadata\": {\"input_tokens\": 24, \"output_tokens\": 7, \"total_tokens\": 31, \"input_token_details\": {\"audio\": 0, \"cache_read\": 0}, \"output_token_details\": {\"audio\": 0, \"reasoning\": 0}}, \"id\": \"run--f1ee6e87-819b-4f9e-b630-708b50c1d101-0\"}]"
  },
  "resource": {
    "attributes": {
      "telemetry.sdk.language": "python",
      "telemetry.sdk.name": "opentelemetry",
      "telemetry.sdk.version": "1.38.0",
      "service.name": "opentelemetry-python-langchain-manual"
    },
    "schema_url": null
  },
  "links": []
}
  1. examples/multi_agent_travel_planner/main.py: to show invoke agent, execute tool :
    root span:
{
  "name": "invoke_agent travel_multi_agent_planner",
  "context": {
    "trace_id": "0b1b755234fb5bd27ddddfc7e357c287",
    "span_id": "3cd74ba3e76a7432"
  },
  "parent_id": null,
  "start_time": "2025-10-20T20:06:50.256000Z",
  "end_time": "2025-10-20T20:07:14.553000Z",
  "status": {
    "code": 0,
    "message": null
  },
  "kind": "CLIENT",
  "events": [],
  "attributes": {
    "gen_ai.operation.name": "invoke_agent",
    "gen_ai.provider.name": "openai",
    "gen_ai.request.model": "gpt-4.1",
    "gen_ai.agent.name": "travel_multi_agent_planner",
    "gen_ai.agent.id": "travel_planner_f07876ef-2f3e-485a-9da6-4fff4b6b234b",
    "gen_ai.conversation.id": "f07876ef-2f3e-485a-9da6-4fff4b6b234b",
    "gen_ai.request.temperature": "0.4",
    "gen_ai.request.top_p": "1",
    "gen_ai.request.max_tokens": "1024",
    "gen_ai.request.frequency_penalty": "0",
    "gen_ai.request.presence_penalty": "0",
    "server.address": "api.openai.com",
    "server.port": "443",
    "service.name": "opentelemetry-python-langchain-multi-agent",
    "gen_ai.input.messages": "[{\"role\": \"user\", \"parts\": [{\"type\": \"text\", \"content\": \"We're planning a romantic long-week trip to Paris from Seattle next month. We'd love a boutique hotel, business-class flights and a few unique experiences.\"}]}]",
    "gen_ai.response.model": "gpt-4.1",
    "gen_ai.output.messages": "[{\"role\": \"assistant\", \"parts\": [{\"type\": \"text\", \"content\": \"**Romantic Paris Itinerary: Seattle to Paris**  \\nDates: November 19\\u201326, 2025 | 2 Travelers\\n\\n---\\n\\n### Flights\\n- **Airline:** CloudNine (Non-stop)\\n- **Class:** Premium Economy (upgrade to business class available upon request)\\n- **Departure:** Nov 19, 09:15 from Seattle\\n- **Arrival:** Nov 19, 17:05 in Paris\\n- **Return:** Nov 26, direct flight to Seattle\\n- **Fare:** $717 per person (return)\\n\\n---\\n\\n### Accommodation\\n- **Hotel:** The Atlas (Boutique hotel near historic centre)\\n- **Room:** Stylish suite with breakfast included\\n- **Features:** Rooftop bar, intimate atmosphere\\n- **Rate:** $370/night\\n\\n---\\n\\n### Unique Experiences\\n1. **Eiffel Tower at Sunset**  \\n   Witness Paris transform as the city lights up\\u2014perfect for a romantic evening.\\n\\n2. **Seine Dinner Cruise**  \\n   Savor gourmet French cuisine while cruising past illuminated landmarks.\\n\\n3. **Day Trip to Versailles**  \\n   Explore the magnificent palace and gardens\\u2014an unforgettable royal escape.\\n\\n---\\n\\n**Summary:**  \\nEnjoy a seamless, romantic week in Paris with non-stop premium flights, a chic boutique hotel, and curated experiences that capture the city\\u2019s magic.\"}], \"finish_reason\": \"stop\"}]",
    "metadata.final_plan.preview": "**Romantic Paris Itinerary: Seattle to Paris**  \nDates: November 19–26, 2025 | 2 Travelers\n\n---\n\n### Flights\n- **Airline:** CloudNine (Non-stop)\n- **Class:** Premium Economy (upgrade to business class available upon request)\n- **Departure:** Nov 19, 09:15 from Seattle\n- **Arrival:** Nov 19, 17:05 in Paris\n- **Return:** Nov 26, direct flight to Seattle\n- **Fare:** $717 per person (return)\n\n---\n\n### Accommodation\n- **Hotel:** The Atlas (Boutique hotel near historic centre)\n- **Room:** Stylish suit...",
    "metadata.session_id": "f07876ef-2f3e-485a-9da6-4fff4b6b234b",
    "metadata.agents_used": "3"
  },
  "resource": {
    "attributes": {
      "telemetry.sdk.language": "python",
      "telemetry.sdk.name": "opentelemetry",
      "telemetry.sdk.version": "1.38.0",
      "service.name": "opentelemetry-python-langchain-multi-agent"
    },
    "schema_url": null
  },
  "links": []
}

chat span:

{
  "name": "chat gpt-4.1",
  "context": {
    "trace_id": "0b1b755234fb5bd27ddddfc7e357c287",
    "span_id": "ea4d36857fec03d4"
  },
  "parent_id": "3cd74ba3e76a7432",
  "start_time": "2025-10-20T20:06:59.323000Z",
  "end_time": "2025-10-20T20:07:00.636000Z",
  "status": {
    "code": 0,
    "message": null
  },
  "kind": "CLIENT",
  "events": [],
  "attributes": {
    "gen_ai.operation.name": "chat",
    "gen_ai.request.model": "gpt-4.1",
    "gen_ai.provider.name": "openai",
    "gen_ai.request.temperature": "0.4",
    "gen_ai.tool.definitions": "[{\"type\": \"function\", \"function\": {\"name\": \"mock_search_flights\", \"description\": \"Return mock flight options for a given origin/destination pair.\", \"parameters\": {\"properties\": {\"origin\": {\"type\": \"string\"}, \"destination\": {\"type\": \"string\"}, \"departure\": {\"type\": \"string\"}}, \"required\": [\"origin\", \"destination\", \"departure\"], \"type\": \"object\"}}}]",
    "gen_ai.input.messages": "[{\"type\": \"human\", \"content\": \"Find an appealing flight from Seattle to Paris departing 2025-11-19 for 2 travellers.\", \"additional_kwargs\": {}, \"response_metadata\": {}, \"id\": \"38d63232-442c-4e80-926d-61aef1a5db04\"}]",
    "gen_ai.usage.input_tokens": "80",
    "gen_ai.usage.output_tokens": "29",
    "gen_ai.response.finish_reasons": "{\"values\":[{\"stringValue\":\"tool_calls\",\"value\":\"string_value\"}]}",
    "gen_ai.response.model": "gpt-4.1-2025-04-14",
    "gen_ai.response.id": "chatcmpl-CSqRf8S10ZfTPRXllsCm5224XOE8k",
    "openai.response.service_tier": "default",
    "openai.response.system_fingerprint": "fp_e24a1fec47",
    "gen_ai.output.messages": "[{\"type\": \"ai\", \"content\": \"\", \"additional_kwargs\": {\"tool_calls\": [{\"id\": \"call_BbDd8whyH8RxFOVOF5LxMkLL\", \"function\": {\"arguments\": \"{\\\"origin\\\":\\\"Seattle\\\",\\\"destination\\\":\\\"Paris\\\",\\\"departure\\\":\\\"2025-11-19\\\"}\", \"name\": \"mock_search_flights\"}, \"type\": \"function\"}], \"refusal\": null}, \"response_metadata\": {\"token_usage\": {\"completion_tokens\": 29, \"prompt_tokens\": 80, \"total_tokens\": 109, \"completion_tokens_details\": {\"accepted_prediction_tokens\": 0, \"audio_tokens\": 0, \"reasoning_tokens\": 0, \"rejected_prediction_tokens\": 0}, \"prompt_tokens_details\": {\"audio_tokens\": 0, \"cached_tokens\": 0}}, \"model_name\": \"gpt-4.1-2025-04-14\", \"system_fingerprint\": \"fp_e24a1fec47\", \"id\": \"chatcmpl-CSqRf8S10ZfTPRXllsCm5224XOE8k\", \"service_tier\": \"default\", \"finish_reason\": \"tool_calls\", \"logprobs\": null}, \"tool_calls\": [{\"name\": \"mock_search_flights\", \"args\": {\"origin\": \"Seattle\", \"destination\": \"Paris\", \"departure\": \"2025-11-19\"}, \"id\": \"call_BbDd8whyH8RxFOVOF5LxMkLL\", \"type\": \"tool_call\"}], \"usage_metadata\": {\"input_tokens\": 80, \"output_tokens\": 29, \"total_tokens\": 109, \"input_token_details\": {\"audio\": 0, \"cache_read\": 0}, \"output_token_details\": {\"audio\": 0, \"reasoning\": 0}}, \"id\": \"run--39786f05-a793-4c60-bbce-ebc40c00a935-0\"}]"
  },
  "resource": {
    "attributes": {
      "telemetry.sdk.language": "python",
      "telemetry.sdk.name": "opentelemetry",
      "telemetry.sdk.version": "1.38.0",
      "service.name": "opentelemetry-python-langchain-multi-agent"
    },
    "schema_url": null
  },
  "links": []
}

execute tool span:

{
  "name": "execute_tool mock_search_flights",
  "context": {
    "trace_id": "0b1b755234fb5bd27ddddfc7e357c287",
    "span_id": "34cf2242947a1664"
  },
  "parent_id": "3cd74ba3e76a7432",
  "start_time": "2025-10-20T20:07:00.639000Z",
  "end_time": "2025-10-20T20:07:00.640000Z",
  "status": {
    "code": 0,
    "message": null
  },
  "kind": "INTERNAL",
  "events": [],
  "attributes": {
    "gen_ai.operation.name": "execute_tool",
    "gen_ai.tool.name": "mock_search_flights",
    "gen_ai.tool.call.arguments": "{\"origin\": \"Seattle\", \"destination\": \"Paris\", \"departure\": \"2025-11-19\"}",
    "gen_ai.tool.call.result": "{\"content\": \"Top choice: CloudNine non-stop service Seattle->Paris, depart 2025-11-19 09:15, arrive 2025-11-19 17:05. Premium economy fare $717 return.\", \"additional_kwargs\": {}, \"response_metadata\": {}, \"type\": \"tool\", \"name\": \"mock_search_flights\", \"id\": null, \"tool_call_id\": \"call_BbDd8whyH8RxFOVOF5LxMkLL\", \"artifact\": null, \"status\": \"success\"}"
  },
  "resource": {
    "attributes": {
      "telemetry.sdk.language": "python",
      "telemetry.sdk.name": "opentelemetry",
      "telemetry.sdk.version": "1.38.0",
      "service.name": "opentelemetry-python-langchain-multi-agent"
    },
    "schema_url": null
  },
  "links": []
}

@nagkumar91 nagkumar91 marked this pull request as ready for review October 8, 2025 17:45
@nagkumar91 nagkumar91 requested a review from a team as a code owner October 8, 2025 17:45
@zhirafovod
Copy link

@wrisa, can you review it and propose the plan to implement in the opentelemetry-util-genai instead?

@wrisa
Copy link
Contributor

wrisa commented Oct 9, 2025

@wrisa, can you review it and propose the plan to implement in the opentelemetry-util-genai instead?

@nagkumar91 we have latest WIP genai utils where all the semantic convention aligned telemetry can be moved.
Please see the proposal here: https://docs.google.com/document/d/1w9TbtKjuRX_wymS8DRSwPA03_VhrGlyx65hHAdNik1E/edit?tab=t.qneb4vabc1wc#heading=h.kh4j6stirken
Here is an example: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3768/files#diff-ceaf683887146bf95f37a7ebb888621d695e881d6e69059e4c7b3a9bc0120f9bR50

@nagkumar91
Copy link
Contributor Author

nagkumar91 commented Oct 13, 2025

@wrisa, can you review it and propose the plan to implement in the opentelemetry-util-genai instead?

@nagkumar91 we have latest WIP genai utils where all the semantic convention aligned telemetry can be moved. Please see the proposal here: https://docs.google.com/document/d/1w9TbtKjuRX_wymS8DRSwPA03_VhrGlyx65hHAdNik1E/edit?tab=t.qneb4vabc1wc#heading=h.kh4j6stirken Here is an example: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3768/files#diff-ceaf683887146bf95f37a7ebb888621d695e881d6e69059e4c7b3a9bc0120f9bR50
@zhirafovod @wrisa
Is there some sample code I can run to see if the spans/traces I care about are captured?
If its still in design/ideation, can we get this change merged? I can help out with implementing changes once the proposal gets merged.

@lmolkova
Copy link
Member

Is there some sample code I can run to see if the spans/traces I care about are captured?
If its still in design/ideation, can we get this change merged? I can help out with implementing changes once the proposal gets merged.

I believe the ask here is to move common parts of content capturing (and anything else common) to https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/util/opentelemetry-util-genai

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.

10 participants