Skip to main content

Copy this prompt into Claude Code, Codex, Cursor or another coding agent. The agent asks you before it installs a tool or changes a file.

Open in Cursor
The rest of this page is written for the coding agent. Read it to see each step that the agent runs. You are a coding agent. The user asked you to add Magpie tracing to this project. Magpie is a trace store for AI agents. magpie-server takes OpenTelemetry traces (OTLP) and answers JSON queries over HTTP. It also serves a read-only web viewer. Do the steps below in order.

Rules

  • Ask the user before you install anything (Rust, a package, a tool) and before you create or change a file. Show the command or the change first, then wait for a yes.
  • Ask the user before you run their app. A run can call a paid model.
  • Do not print, copy or store a secret: API keys, tokens, passwords, the values in .env files, Magpie keys (mgp_...). Do not write a secret into a file or a command line.
  • If a step fails, stop. Tell the user the step, the command and the error text. Do not try a way that this page does not show.
  • Use only the commands, flags, routes and JSON shapes on this page and on docs.magpiedb.com. If a page does not show a flag or a field, it does not exist.
  • Magpie is not on crates.io, npm or PyPI yet, and there is no release to download yet. Do not run cargo add magpiedb, npm install magpiedb or pip install magpiedb. Build the server from source (step 3).

The places

Ask the user if they want other folders. Your shell can lose variables between two commands, so the commands below use full paths.

Step 1: Check the tools

Each command must print a version. Magpie needs stable Rust. If cargo is not found, stop and ask the user to install Rust from rustup.rs. Do not install it yourself.

Step 2: Check if a Magpie server runs already

  • An answer like {"diskBytes":59692,"mode":"local","spans":0,"traces":0}: a Magpie server runs on this machine. Tell the user, and go to step 5.
  • No answer (curl exits with code 7): nothing listens on port 4318. Go to step 3.
  • Any other answer, or 401: another program or a server with API keys has the port. Stop and ask the user.

Step 3: Get and build magpie-server

Ask the user first. This step puts the source in ~/src/magpie and builds it. The first build takes some minutes. If ~/src/magpie exists already, ask the user if you can use it as it is.
The last command must print:

Step 4: Start the server

The server must keep running after this step. The best way: ask the user to open a new terminal, run this command there, and keep that terminal open.
If the user wants you to start it, run it in the background with its output in a log file:
The server makes the store folder. It prints one line that starts with magpie-server: store and ends with Viewer: http://127.0.0.1:4318/. Then check it:
The answer must be ok. By default the server listens on 127.0.0.1 only and has no API keys. Ctrl-C stops it; the data stays in the store folder. If the server stops at once, read its line:

Step 5: Send a test trace

This test trace has two steps: a model call, and a tool call that failed. Send it with curl (no file is made):
The answer must be {}: every span is stored.

Step 6: Check that the test trace arrived

Ask for traces with a tool call that failed:
On a new store the answer is:
The trace 5b8efff798038103d269b633813fc60c must be in the list. A store that had data before can show more traces. If count is 0, wait 2 seconds and ask again. If it is still 0, stop and report.

Step 7: Find the language and the framework of the app

Read the files of the project; do not change them. Look at the dependencies in package.json, pyproject.toml, requirements*.txt and the lock files. Pick a row: If no row fits, stop. Tell the user that this page has no setup for the app, and give them the link docs.magpiedb.com/guides/opentelemetry. If more than one row fits, ask the user which one to use. Then tell the user: what you found, the setup you want to use, if it is tested, the packages it adds and the files it changes. Wait for a yes.

Step 8: Add the setup

  • Install the packages with the package manager that the project uses (npm, pnpm, yarn, uv, poetry, pip).
  • Put the setup code where the app starts, before its first model call.
  • A short script must send its spans before it ends: each setup below says how.
  • The setups are from the docs of each project (links). Copy them as they are.

An app with an OpenTelemetry SDK

Most OpenTelemetry SDKs read these environment variables. No code change is needed:
Set them in the shell that runs the app, or where the project keeps its settings (ask the user which). Magpie reads the GenAI attribute names of OpenTelemetry (gen_ai.*), so the spans of the model calls must have them.

Vercel AI SDK

From ai-sdk.dev/docs/ai-sdk-core/telemetry. Tested with ai 7.0.188, @ai-sdk/otel 1.0.188 and @opentelemetry/sdk-node 0.302.0. AI SDK 5 used experimental_telemetry: { isEnabled: true } on each call instead (v5 docs); that way was not tested here. In Next.js, the AI SDK docs use @vercel/otel in instrumentation.ts.
Call await sdk.shutdown() before a short script ends, or its spans are not sent. For this, keep the NodeSDK in a variable sdk.

LangChain and LangGraph (Python)

Through the OpenTelemetry mode of LangSmith (docs.langchain.com/langsmith/trace-with-opentelemetry, section “Configure alternate OTLP endpoints”). LANGSMITH_OTEL_ONLY=true sends to your endpoint only, not to LangSmith. Tested with langsmith 0.14.17, langchain 1.4.10 and langchain-core 1.7.7.
Call provider.force_flush() before a short script ends.

OpenAI Agents SDK (Python)

Not tested. Tell the user. Through the OpenInference instrumentation (its README).

Mastra

Not tested. Tell the user. Through @mastra/otel-exporter (mastra.ai/docs/observability/tracing/exporters/otel, “Custom or generic OTEL endpoints”).

Python with no framework

The app makes its own spans with the OpenTelemetry SDK: an agent span with a model call inside. This example is a whole script. Use it as the pattern: show the user where the spans go in their code before you change it.
Call provider.shutdown() (or force_flush()) before a short script ends. Else the last batch is not sent.

Step 9: Run the app once and find its trace

Ask the user to run the app with one short task, or ask if you can run it. Then wait 2 seconds and list the newest traces:
The newest trace comes first. Its inputPreview holds the first characters of the app’s prompt. To find it by a word of the prompt, put the word in place of parcel:
If the app’s trace is not there:
  • The process of the app did not get OTEL_EXPORTER_OTLP_ENDPOINT. Set it in the same shell or settings that start the app.
  • A short script ended before its spans were sent. Add the shutdown or flush call of its setup.
  • The protocol and the port do not agree: http/protobuf goes to port 4318, grpc to port 4317.
If it is still not there, stop and report what you see.

Step 10: Tell the user

Give the user this report, with the real values:
Also tell the user:
  • Open http://127.0.0.1:4318/ in a browser to see the traces. Click a trace to see its steps; a failed step is red.
  • To start the server again: ~/src/magpie/target/release/magpie-server --dir ~/magpie-traces.
  • The test trace of step 5 stays in the store. To delete it (ask first):
  • The store keeps the prompts and answers of the app as text. To replace private data before it is stored, see masking.
  • Before other machines send to this server, read operations: API keys and TLS.
  • To let an agent query these traces later (for example, to find why a run failed), install the Magpie skill: npx skills add intojhanurag/magpie (AI tools).