---
title: "02 Tracing"
description: "Learner guide: 02 Tracing"
---
# 02 Tracing

Workshop material is maintained in the public [`langfuse/langfuse-workshop`](https://github.com/langfuse/langfuse-workshop) repository. Use the repository for the runnable app, checkpoint branches, and local setup.

[View this Markdown file](https://github.com/langfuse/langfuse-workshop/blob/main/docs/instructor/02-tracing.md)

Learner guide: [02 Tracing](/workshop/learner/02-tracing)

## Instructor notes

- Teach the progression in three visible layers: OpenAI generations, one agent root, then tool observations.
- Keep the code changes small and local. The point is to show that Langfuse wraps existing app boundaries instead of forcing an architecture rewrite.
- The user/session propagation section is optional live, but later checkpoints include it so the following chapters have attribution available.

## Demo rhythm

1. Add `LangfuseSpanProcessor` and `observeOpenAI`, run one turn, show separate generation traces.
2. Wrap `runSupportConversationInner` with `observe(...)`, run again, show nested generations.
3. Wrap the two local tool helpers, run again, show the full tree.

## Watch for

- An occasional blank parent container around `dad-it-support-chat-turn` right after Step 2. Refresh once before treating it as a code bug; if it persists every turn, check for accidental extra tracing wrappers beyond the single `observe(...)` in the lesson.
- Learners wrapping the OpenAI client in a separate factory. The workshop intentionally keeps the wrapper inline.
- Learners pasting the Step 3 block above the existing `executeTool` instead of replacing it. The server exits with `Multiple exports with the same name "executeTool"`; the leftover copy is further down `tools.ts`.
- Missing shutdown flush in `index.ts`; traces can arrive late without it.

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/workshop/instructor/02-tracing.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx langfuse-cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
