Tracepanel

How it works

What the SDK does inside your app, what the agent does beside it, where traces live, and how Tracepanel keeps your data local.

Tracepanel has two parts. An SDK runs inside your app and records traces. The agent is a separate program that analyzes and stores them, and serves the console.

The SDK

The SDK is a library you add to your app. When your app starts, the SDK reads its settings and decides whether to turn on. If it is off, it stops there and changes nothing in your app.

When it is on, the SDK hooks into your web framework and into the libraries it supports. Each request opens a trace, and everything the request runs records into it. The trace collects these parts:

  • SQL queries and transactions.
  • The view, templates and cache calls.
  • Calls to Redis, HTTP APIs, MongoDB and other systems.
  • Sent emails.
  • Log records.
  • Errors, with their stack and the source of your frames.

When the response is ready, the SDK adds the route, the view and the status to the trace. It adds the user only if the view already loaded one, and it never queries for the user. Then a background thread sends the trace to the agent.

The SDK also adds headers to the response: Tracepanel-Id, Tracepanel-Url and Server-Timing. The badge reads them. For an HTML page, the SDK also adds the panel's script.

A background task run and a command each become a trace of their own. A task queued during a request shows in the request's call tree, and its run links back to that request.

In the Python SDK

The SDK is the tracepanel package, and it installs the agent with it. Where a framework has a hook, the SDK uses it. Where there is none, it wraps a few methods, such as the view call and template rendering. The trace lives in a context variable, so async code records into it too. Tracepanel skips servers, shells and workers among management commands. See Integrations and ignore_commands in Configuration.

In the JavaScript SDK

The SDK is the @tracepanel/js package, and it installs the agent with it. It loads before your app and records through OpenTelemetry's instrumentations, which come with it. See Integrations.

In the Go SDK

The SDK is the github.com/tracepanel/tracepanel-go module, and it downloads the agent the first time it runs. It wraps your handler and the database/sql driver, and finds the trace in each call's context, so pass the request's context down. The agent serves the console on a port of its own, not on your app's. See Integrations.

The browser

A page can record itself in the browser too, with the JavaScript SDK. Each view of the page and each action on it, such as a click that called the API, becomes a trace with its calls, errors and console output. The page sends it to the console on its own origin, at /__tracepanel__/api/ingest, and the console passes it on to the agent. The console takes these traces as JSON from this machine only, so a page on another site can't send to it. See Pages in the browser.

The agent

tracepanel-agent is a separate program. Each project has one agent. The first trace starts it, and it exits after 30 minutes unused. The agent keeps running across the reloads of your dev server and across workers, so every process of the project sends to the same agent. Several apps can share one agent, each under its own service name.

The agent does the work your app doesn't:

  • It finds the issues in each trace.
  • It stores the traces.
  • It serves the console, its API and the panel's script.

The badge shows a request's status and time at once. It shows the request's issues a moment later, once the agent has found them.

To run the agent in the foreground, with the console on http://127.0.0.1:8765/, start it from your project's directory:

tracepanel-agent --serve 127.0.0.1:8765

tracepanel dev does the same, from the Python, JavaScript and Go SDKs. See the commands of Python, JavaScript and Go.

Use it to watch the agent's output, or to read the traces after your app has stopped. If the agent can't run, the SDK prints the reason in the terminal. Requests still get their headers, but Tracepanel stores nothing.

Where your app serves the console, as the Python SDK does and the JavaScript SDK's Vite plugin and Next.js integration do, /__tracepanel__/ then answers 503 with the reason and what to do. The agent is off, runs without its console because it was started without --serve, wasn't found, or didn't start and its agent.log says why; or a named agent or console address doesn't answer. In the browser, the answer is a page that reloads itself every 2 seconds and shows the console once it answers. The API's calls get the reason as JSON.

OpenTelemetry

The agent also takes OpenTelemetry spans over OTLP/HTTP, on 127.0.0.1:4318 by default. That is where OpenTelemetry's exporters send spans unless told otherwise. A service that exports its traces with any OpenTelemetry SDK shows in the console with no Tracepanel SDK in it. The agent reads the spans by OpenTelemetry's semantic conventions and finds the same issues in them. It names the service's language and framework from the spans, such as Java and Spring Boot, .NET and ASP.NET Core, Ruby and Rails, or Go and Gin. A model call that a GenAI instrumentation records, with OpenTelemetry's gen_ai.* attributes, is an LLM call with its tokens and estimated cost. See LLM calls.

Point such a service's exporter at the agent's OTLP address, such as OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318. A client span that names only a URL, in url.full or http.url, carries the trace on. The service it called links its trace to it.

A browser's CORS preflight is no trace: an OPTIONS request that asks for another method in its Access-Control-Request-Method header. When the instrumentation didn't record the header, an OPTIONS with no spans under it, no error and a 2xx status, or none, is taken for one. Any other OPTIONS request, such as a handler that did work or failed, is a trace.

A span from OpenTelemetry ends its details with As received over OTLP, collapsed. One line says how the agent understood the span. It is a call, and whether it links the trace of the service it called, or a step, and why. Under it are the span's name, kind, scope and attributes as they came. It tells why a span did or didn't become a call. The console and the panel show it.

The OTLP port

TRACEPANEL_OTLP sets the address, as HOST:PORT, and off turns OTLP off. The SDKs start the agent in your app's environment, so set it there. The agent's --otlp flag wins over it.

Only one agent on a machine can hold a port. With several projects running at once, the first project's agent takes 127.0.0.1:4318. Give each other project a port of its own, and point its exporters there:

export TRACEPANEL_OTLP=127.0.0.1:4319
export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4319

The agent writes the address it serves OTLP on to .tracepanel/otlp.addr. The console's sidebar shows it at its foot, such as OTLP · 127.0.0.1:4318. When the port is taken, the sidebar says who holds it: the agent of another project, by its name, an older Tracepanel agent or another program. It also gives the setting to use, with a free port, such as TRACEPANEL_OTLP=127.0.0.1:4319. The agent's log says the same. The agent tries the port again every 10 seconds and takes it over once it is free.

Apollo Router

Apollo Router sends its traces over OTLP, with no Tracepanel SDK. Point its exporter at the agent's OTLP address in router.yaml, and turn on the W3C trace context:

telemetry:
  exporters:
    tracing:
      propagation:
        trace_context: true
      otlp:
        enabled: true
        protocol: http
        endpoint: http://127.0.0.1:4318

The endpoint is the address alone. The Router adds /v1/traces itself. Add a Tracepanel SDK to each subgraph.

Each request the Router makes to a subgraph is a POST call to the subgraph's URL, and the subgraph's trace links to it. The Router's own stages, such as supergraph, execution and fetch, fold into the request, their time in it. Parsing and planning a query show when they take 5 ms or more. The trace is named after the operation, such as GraphQL query Books. When the Router sends its document, with graphql.document turned on in its supergraph span, the trace's Request tab shows it. A browser's CORS preflight and the Router's own work outside a request, such as its start, are no traces.

Other GraphQL gateways

The traces of other GraphQL gateways read as Apollo Router's do: WunderGraph Cosmo Router, Hive Gateway, GraphQL Mesh through The Guild's OpenTelemetry plugin, Hive Router and Grafbase Gateway. Point the gateway's OTLP exporter at the agent's address, over HTTP, and add a Tracepanel SDK to each subgraph.

The gateway's request is the trace, named after its operation, such as GraphQL query Books. Its requests to subgraphs are calls that link the subgraphs' traces. Its own stages, such as parse, normalize, validate, plan, execute and the fetch around each request, are left out, their time still in the request. Parsing and planning show when they take 5 ms or more. Hive Gateway's start and its schema loads are no traces. Hive Gateway is told by its span names and attributes too, so its stages fold under a tracer you named otherwise.

Grafbase Gateway records its request to a subgraph as an internal span, and it is a call too. Its calls link the subgraphs' traces once its W3C trace context propagation is on. It is off by default:

[telemetry.tracing.propagation]
trace_context = true

Traces across apps

A call from one app to another carries the W3C trace context. The agent links the caller's trace to the trace of the app it reached, whether each app uses a Tracepanel SDK or OpenTelemetry, in any language. The call tree shows the reached app's trace under the call, opened: its own spans, queries and calls, with the app's name.

The apps can share one agent or each run their own. Each agent with a console lists itself in your user's cache directory, with a token. An agent asks the other agents on the machine for the traces it doesn't hold, and a link opens that project's console. With one shared agent, the Services page also draws an arrow from app to app.

The store

The agent keeps the traces in a SQLite file under .tracepanel/ in your project, traces.v24.sqlite3. The number in the name is the store's format. When a new version of the agent changes the format, it starts a new, empty file, and the traces in the old one aren't carried over.

The agent keeps the newest 2000 traces and deletes older ones. One trace keeps at most 2000 spans and 1000 log records: its earliest spans, each with its parent, and its first records. The Request tab shows how many it didn't keep, under Not recorded. An issue keeps its count and the time it was first seen after its traces are deleted. The SDK's settings change that number and move the store. The trash button in the console deletes everything in it.

What runs in your app's process

Your app's process records the trace and sends it. It does no analysis and keeps no store. Collecting a trace adds little to a request, and a background thread sends the trace after the response is made. Tracepanel collects nothing when it is off.

Requests under /__tracepanel__/ go to the agent. Two need your app, because it has the database connections and the sessions:

  • EXPLAIN of a query. The agent asks the app that recorded the query, over the connection that app sends traces on, and the app runs it on the database the query ran on. So it works in any console: your app's, the agent's own, or the one a frontend in front of your API serves.
  • Switching the user from the panel, in a Django project. Your app handles it itself, so it shows in the console your app serves, at /__tracepanel__/.

Several projects on one machine

Each agent lists itself in a file in your user's cache directory, readable by you only. When your app calls another app on the same machine, and that app's project runs its own agent, the trace's Request tab links to the call's trace in the other project's console. The agents match the call by the W3C trace context the SDKs send with each outgoing HTTP call.

Clocks

The agent notes when each trace arrives. When the app's clock is more than 10 seconds ahead of the agent's, or a minute behind, the Request tab shows a Clock note, since the trace's times may not line up with other apps or with since:. A note for a clock behind can also mean the app sent the trace late.

Privacy and safety

Tracepanel is a development tool, and its defaults keep it local.

It stays on your machine. The agent stores traces in .tracepanel/ in your project and sends nothing anywhere. By default the console and the OTLP intake listen on 127.0.0.1, and the agent takes traces from this machine only.

Add the store to .gitignore. The traces hold development data, so keep them out of your repository:

echo ".tracepanel/" >> .gitignore

It masks secret-looking values. To help you debug, traces keep SQL parameters for EXPLAIN, local variables in errors, email bodies and task arguments. Tracepanel masks a value as ******** when its name looks secret: in what a request carried, local variables, task arguments, the fields of log records and dumps. Each kind of data has a setting that turns it off.

Every SDK reads a name the same way, word by word. It splits the name at _, -, ., [ and ] and where camelCase turns, and a secret's word must be whole: password, secret, token, api_key, auth, cookie, session, csrf, signature or private, among others. So authToken, AUTH_HEADER, x-api-key, csrftoken and sessionid are masked, and author, tokenizer, max_tokens, password_length and is_private aren't. tokens that holds numbers, such as a model's token counts, is shown.

It is off outside development by default. The SDK turns on in development, or when you turn it on yourself. Otherwise it installs nothing. Python and Java follow the framework's debug or dev mode. JavaScript is on unless NODE_ENV is production, so set it in production. Go has no debug mode, so it records when the app runs under go run, and a binary built with go build records nothing.

In the Python SDK

The settings capture_sql_params, capture_locals, capture_mail_body and capture_task_args turn off each kind of data. Tracepanel turns on only with DEBUG or the framework's debug mode, under tracepanel run, or with TRACEPANEL_ENABLED=1. See Configuration.

In Django, switching the user needs DEBUG = True, even when you turned Tracepanel on another way. It also needs django.contrib.auth and sessions. The request must come from this machine or from an address in INTERNAL_IPS, and from the page itself, as a same-origin call with Tracepanel's header. The user_switch setting turns it off.

In the Go SDK

TRACEPANEL_CAPTURE_REQUEST=0 keeps no headers, query, cookies or body. A name is read word by word, as the other SDKs read it: authToken, AUTH_HEADER and X-Api-Key are masked, Author, tokenizer, token_type and hasPassword aren't, and tokens holding numbers, a model's counts, is shown. Tracepanel turns on only under go run, under tracepanel run, with TRACEPANEL_ENABLED=1, or with Config.Enabled. In a binary built with go build, WrapHandler, Driver and the rest hand back what they were given, and no agent is downloaded or started. See Configuration.

On this page