Skip to main content

path-c

Last updated on

Path C: Framework-Specific Instrumentation

Use this path if an orchestration framework (LangChain, LlamaIndex, OpenAI Agents SDK, Google ADK) runs your calls and has built-in OpenTelemetry support or official instrumentation libraries. This captures the full workflow: tool calls, retries, and loops.

note

The Harness SDK (Path B) also works if your framework routes through LiteLLM, but it captures only the LLM call, not the surrounding workflow.

Shared OpenTelemetry Setup

Every framework tab below uses the same OpenTelemetry exporter setup. Run it once at application startup, then add the framework-specific instrumentor from the matching tab. Replace <YOUR_TOKEN> with your service account token (generated in Path A, Step 1) and adjust the endpoint for your Harness cluster.

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

provider = TracerProvider()
provider.add_span_processor(
BatchSpanProcessor(
OTLPSpanExporter(
endpoint="https://app.harness.io/udp-ingest/otel/v1/traces",
headers={"Authorization": "Bearer <YOUR_TOKEN>"},
)
)
)

# Register `provider` as the global tracer provider so instrumentors and
# `trace.get_tracer(...)` calls below pick it up.
trace.set_tracer_provider(provider)

Best for: LangChain or LangGraph applications without LiteLLM.

LangChain and LangGraph can export traces through LangSmith's OpenTelemetry support or the OpenInference LangChain instrumentation.

Option 1: LangSmith OTel (official)

Set these environment variables:

export LANGSMITH_OTEL_ENABLED=true
export LANGSMITH_TRACING=true
export OTEL_EXPORTER_OTLP_ENDPOINT=https://app.harness.io/udp-ingest/otel
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <YOUR_TOKEN>"

Note: LangSmith appends /v1/traces to the endpoint, so use the base path (/udp-ingest/otel) here.

Option 2: OpenInference LangChain instrumentation (community)

Install the instrumentation library:

pip install openinference-instrumentation-langchain \
opentelemetry-sdk opentelemetry-exporter-otlp

Complete the shared OpenTelemetry setup once, then add the framework instrumentor:

from openinference.instrumentation.langchain import LangChainInstrumentor

# `provider` comes from the shared setup above
LangChainInstrumentor().instrument(tracer_provider=provider)

What this produces:

  • One trace per LangChain invocation (chain, agent, tool)
  • Nested spans for each step (LLM call, tool use, retrieval)
  • GenAI semantic conventions on LLM spans
  • Cost calculated from token counts