<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie" -->

---
title: How Do You Trace a LangChain Application End to End?
description: A walkthrough of instrumenting LangChain applications with Opik, an open-source LLM observability platform from Comet. Covers what the automatic callback...
canonical: https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How Do You Trace a LangChain Application End to End? | daily.dev
og:description: A walkthrough of instrumenting LangChain applications with Opik, an open-source LLM observability platform from Comet. Covers what the automatic callback...
og:url: https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie
og:image: https://api.daily.dev/og/posts/YWTnKxmiE.png
og:image:alt: How Do You Trace a LangChain Application End to End?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How Do You Trace a LangChain Application End to End?

**[Medium](https://daily.dev/sources/medium_js)** · 8 min read · 1 upvotes · 0 comments

## Summary

A walkthrough of instrumenting LangChain applications with Opik, an open-source LLM observability platform from Comet. Covers what the automatic callback integration captures out of the box (chain, LLM, retriever, and tool spans), how to install and attach the OpikTracer, how traces appear in the Opik UI, and how to add manual spans with the @opik.track decorator for code outside the chain, plus tagging and filtering traces by metadata.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://heartbeat.comet.ml/how-do-you-trace-a-langchain-application-end-to-end-14cb9ad6175c>

## Questions this post answers

### How do I trace a LangChain chain automatically without rewriting my application code?

Attach Opik's OpikTracer callback handler by passing it into the chain's invoke call via config={"callbacks": [tracer]}. This produces a trace per chain.invoke() call with nested spans for every runnable step, LLM call, retriever call, and tool invocation, capturing inputs, outputs, token counts, and latency with no changes to the chain logic itself.

_daily.dev surfaces practical guides like this for developers wiring up LLM observability in LangChain pipelines._

### How do I capture spans for code that runs outside a LangChain chain, like a database lookup before invoking the chain?

Wrap the function with the @opik.track decorator, which works on both synchronous and asynchronous functions. Opik opens a trace and root span for the decorated outer function, turns any nested decorated calls into child spans, and attaches the chain's own spans beneath that root when OpikTracer runs inside it, keeping the whole pipeline as one connected trace instead of two separate entries.

_Developers stitching pre- and post-processing into LLM traces can track patterns like this on daily.dev._

### What span type does Opik assign to a LangChain prompt template versus the model call in a chain?

Opik types the ChatOpenAI model call span as llm, while the ChatPromptTemplate step is recorded with the tool span type because LangChain reports it as a prompt run. Other components, like a retriever or an output parser, are typed as general and named after the LangChain component that produced them.

_daily.dev helps engineers comparing observability tooling keep track of details like span typing conventions._

## Similar posts on daily.dev

- [LLM Observability Tools Compared: LangFuse vs LangSmith vs Opik](https://daily.dev/posts/llm-observability-tools-compared-langfuse-vs-langsmith-vs-opik-qdjdhjilu) · BigData Boutique blog · 0 upvotes · 0 comments
- [Self-Hosted or SaaS: How Should You Deploy Your LLM Observability Platform?](https://daily.dev/posts/self-hosted-or-saas-how-should-you-deploy-your-llm-observability-platform--j6cnqwh3m) · HEARTBEAT · 0 upvotes · 0 comments
- [How Do You Build an LLM Evaluation Dataset from Production Traces?](https://daily.dev/posts/how-do-you-build-an-llm-evaluation-dataset-from-production-traces--pmibina7y) · HEARTBEAT · 2 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#langchain](https://daily.dev/tags/langchain), [#llm-observability](https://daily.dev/tags/llm-observability)

[View this post on daily.dev](https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How Do You Trace a LangChain Application End to End?","url":"https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie"},"datePublished":"2026-08-30T22:35:37.733Z","dateModified":"2026-08-30T22:36:21.463Z","description":"A walkthrough of instrumenting LangChain applications with Opik, an open-source LLM observability platform from Comet. Covers what the automatic callback...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f96136520d5f75c851f393bd2cd43bcd?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f96136520d5f75c851f393bd2cd43bcd?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,langchain,llm-observability","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"How Do You Trace a LangChain Application End to End?"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-do-you-trace-a-langchain-application-end-to-end--ywtnkxmie#faq","mainEntity":[{"@type":"Question","name":"How do I trace a LangChain chain automatically without rewriting my application code?","acceptedAnswer":{"@type":"Answer","text":"Attach Opik's OpikTracer callback handler by passing it into the chain's invoke call via config={\"callbacks\": [tracer]}. This produces a trace per chain.invoke() call with nested spans for every runnable step, LLM call, retriever call, and tool invocation, capturing inputs, outputs, token counts, and latency with no changes to the chain logic itself. daily.dev surfaces practical guides like this for developers wiring up LLM observability in LangChain pipelines."}},{"@type":"Question","name":"How do I capture spans for code that runs outside a LangChain chain, like a database lookup before invoking the chain?","acceptedAnswer":{"@type":"Answer","text":"Wrap the function with the @opik.track decorator, which works on both synchronous and asynchronous functions. Opik opens a trace and root span for the decorated outer function, turns any nested decorated calls into child spans, and attaches the chain's own spans beneath that root when OpikTracer runs inside it, keeping the whole pipeline as one connected trace instead of two separate entries. Developers stitching pre- and post-processing into LLM traces can track patterns like this on daily.dev."}},{"@type":"Question","name":"What span type does Opik assign to a LangChain prompt template versus the model call in a chain?","acceptedAnswer":{"@type":"Answer","text":"Opik types the ChatOpenAI model call span as llm, while the ChatPromptTemplate step is recorded with the tool span type because LangChain reports it as a prompt run. Other components, like a retriever or an output parser, are typed as general and named after the LangChain component that produced them. daily.dev helps engineers comparing observability tooling keep track of details like span typing conventions."}}]}
```

