Skip to content

Instantly share code, notes, and snippets.

@kaenova
Created November 21, 2025 04:30
Show Gist options
  • Select an option

  • Save kaenova/7edd356730416eb983cdbff9d01d349b to your computer and use it in GitHub Desktop.

Select an option

Save kaenova/7edd356730416eb983cdbff9d01d349b to your computer and use it in GitHub Desktop.
Agent App Insight Langgraph

How to Install Langgraph App Insights

This will add Agent observability on Application Insights - Tested on Langgraph<1.0.0

uv pip install "opentelemetry-instrumentation-langchain>=0.48.1" "langchain-azure-ai==0.1.8" "azure-monitor-opentelemetry==1.8.0"

Prepare the utils function

# utils/tracers.py
import os
from dotenv import load_dotenv
from langchain_azure_ai.callbacks.tracers import AzureAIOpenTelemetryTracer
from opentelemetry.instrumentation.langchain import LangchainInstrumentor

load_dotenv()

def get_microsoft_tracer(trace_name: str) -> list:
    if not os.environ.get("APPLICATION_INSIGHTS_CONNECTION_STRING"):
        return []
    instrumentor = LangchainInstrumentor()
    if not instrumentor.is_instrumented_by_opentelemetry:
        instrumentor.instrument()
    azure_tracer = AzureAIOpenTelemetryTracer(
        connection_string=os.environ.get("APPLICATION_INSIGHTS_CONNECTION_STRING"),
        enable_content_recording=True,
        name=trace_name,
    )
    return azure_tracer

Add it to CompiledGraph callback

...
...
    callbacks = []
    tracer = get_microsoft_tracer("DeepAgentEvaluation")
    if tracer:
        callbacks.append(tracer)

    compiled_agent = agent_builder.compile().with_config({'recursion_limit': 50, 'callbacks': callbacks})
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment