Skip to content

feat: Add native LangChain instrumentation support#589

Merged
liustve merged 91 commits intomainfrom
langchain-instrumentor
Mar 11, 2026
Merged

feat: Add native LangChain instrumentation support#589
liustve merged 91 commits intomainfrom
langchain-instrumentor

Conversation

@liustve
Copy link
Copy Markdown
Contributor

@liustve liustve commented Jan 23, 2026

Description of changes:

  • Adds native OTel instrumentation for LangChain following OTel's Gen's AI Agent semantic conventions 1.39

  • Instruments and wraps BaseCallbackManager.__init__ to inject an OpenTelemetry callback handler that captures spans for LLM calls, chains, tools, and agent.

  • Add auto-wiring using OTel's entry points system, so applications using ADOT Python auto-instrumentation will automatically trace LangChain workflows without any code changes.

Testing

  • Unit tests added
  • Contract tests added
  • Manual E2E test with a LangChain sample app, example spans shown below:
image
{
    "resource": {
        "attributes": {
            "aws.local.service": "test-agent",
            "aws.service.type": "gen_ai_agent",
            "telemetry.sdk.language": "python",
            "service.name": "test-agent",
            "telemetry.sdk.version": "1.39.1",
            "telemetry.auto.version": "0.14.2.dev0-aws",
            "telemetry.sdk.name": "opentelemetry"
        }
    },
    "scope": {
        "name": "amazon.opentelemetry.distro.instrumentation.langchain",
        "version": "0.14.2.dev0"
    },
    "traceId": "698a7f1a4b0cc40aec119f69c718c440",
    "spanId": "17fd622727f03922",
    "parentSpanId": "52efbf084ee9c4a7",
    "flags": 256,
    "name": "invoke_agent WeatherMathAgent",
    "kind": "INTERNAL",
    "startTimeUnixNano": 1770684186300891000,
    "endTimeUnixNano": 1770684189493051000,
    "durationNano": 3192160000,
    "attributes": {
        "aws.local.service": "test-agent",
        "gen_ai.operation.name": "invoke_agent",
        "gen_ai.agent.name": "WeatherMathAgent",
        "gen_ai.request.model": "anthropic.claude-3-haiku-20240307-v1:0",
        "PlatformType": "Generic",
        "gen_ai.provider.name": "aws.bedrock",
        "aws.local.environment": "generic:default"
    },
    "status": {
        "code": "UNSET"
    }
}
{
    "resource": {
        "attributes": {
            "aws.local.service": "test-agent",
            "aws.service.type": "gen_ai_agent",
            "telemetry.sdk.language": "python",
            "service.name": "test-agent",
            "telemetry.sdk.version": "1.39.1",
            "telemetry.auto.version": "0.14.2.dev0-aws",
            "telemetry.sdk.name": "opentelemetry"
        }
    },
    "scope": {
        "name": "amazon.opentelemetry.distro.instrumentation.langchain",
        "version": "0.14.2.dev0"
    },
    "traceId": "698a7f1a4b0cc40aec119f69c718c440",
    "spanId": "3ea1452ef68cbaf7",
    "parentSpanId": "56dfee092e1402c0",
    "flags": 256,
    "name": "chat anthropic.claude-3-haiku-20240307-v1:0",
    "kind": "INTERNAL",
    "startTimeUnixNano": 1770684188259781000,
    "endTimeUnixNano": 1770684189492810000,
    "durationNano": 1233029000,
    "attributes": {
        "aws.local.service": "test-agent",
        "gen_ai.operation.name": "chat",
        "gen_ai.usage.input_tokens": 573,
        "gen_ai.usage.output_tokens": 29,
        "gen_ai.request.model": "anthropic.claude-3-haiku-20240307-v1:0",
        "gen_ai.response.model": "anthropic.claude-3-haiku-20240307-v1:0",
        "PlatformType": "Generic",
        "gen_ai.provider.name": "aws.bedrock",
        "aws.local.environment": "generic:default"
    },
    "status": {
        "code": "UNSET"
    }
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@liustve liustve requested a review from a team as a code owner January 23, 2026 23:53
@liustve liustve marked this pull request as draft January 23, 2026 23:54
@liustve liustve force-pushed the langchain-instrumentor branch 4 times, most recently from 16dd32e to 8f5acf4 Compare March 11, 2026 00:46
@liustve liustve force-pushed the langchain-instrumentor branch from f21e98a to 07961b8 Compare March 11, 2026 01:59
wangzlei
wangzlei previously approved these changes Mar 11, 2026
@liustve liustve merged commit f6077cf into main Mar 11, 2026
25 of 27 checks passed
@liustve liustve deleted the langchain-instrumentor branch March 11, 2026 20:18
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