services
Get a key

library / Integrations / Search and time series / I0128

Jaeger CPI call traces

A Node script reads the newest transaction of a program through Carbium RPC, rebuilds its cross-program invocation tree from the inner instructions, and writes an OpenTelemetry trace file you can load into Jaeger.

By Carbium · Search and time series · I0128 · updated 2026-11-23

01

What the trace file holds

A transaction that calls a program often runs more programs than the one you named. A top-level instruction can call a second program, and that call can call a third. The node records each of those calls in the transaction's inner instructions, as a flat list per top-level instruction, which makes the tree hard to see in raw output. This script rebuilds the tree for the newest successful transaction of one program and writes it as an OpenTelemetry trace with one span per call.

Each top-level instruction becomes a root span. Each inner call becomes a child span of the call that made it, and its name is the program address that ran. The file uses the OTLP/JSON layout, so an OpenTelemetry Collector can receive it on its OTLP input and forward it to a Jaeger backend, or post it to a collector's OTLP/HTTP /v1/traces route.

Span fieldWhat it holds
nameThe program address that ran that instruction
parentThe span of the call that invoked it, empty for a top-level instruction
depth1 for a top-level instruction, 2 for a call it makes, and so on
statusError when the transaction failed, ok otherwise

The trace ID is a SHA-256 of the signature, and each span ID hashes the signature with the span's position. The same transaction therefore always gets the same IDs.

02

Two calls and what they cost

The script makes two reads through the RPC endpoint. The first, getSignaturesForAddress, asks for the five newest signatures of the program and keeps the first one that did not fail. The second, getTransaction, reads that signature with JSON encoding.

Both calls set commitment to confirmed. A call that leaves commitment out gets confirmed from @solana/kit 8.6.0, but writing the value out keeps the level visible in the code. Both reads use the same level, so the signature list and the transaction come from the same view of the chain.

getTransaction sets maxSupportedTransactionVersion to 1. Mainnet carries v1 transactions, and a call that leaves the field out, or sets it to 0, gets -32015 for one of them, as the version error entry explains.

A v0 transaction with address lookup tables keeps some account keys outside its message. The code appends the loaded writable addresses and then the loaded readonly addresses after the static keys, because an index in an inner instruction counts them in that order. Without that step, an index can point past the static list and the name lookup fails.

CallCellsUsed for
getSignaturesForAddress50The newest signature of the program
getTransaction50The transaction and its inner instructions

One run costs 100 cells. Limits are per account, so every key on the account shares that budget. A rate class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. A loop over many signatures multiplies the 50-cell read, so size the loop to the budget before you widen it.

03

Reading depth from inner instructions

The inner instruction list is flat. Each group names the top-level instruction it belongs to through its index, and the depth of each entry comes from stackHeight. A top-level instruction runs at height 1, a call it makes runs at height 2, and a call that call makes runs at height 3.

  • Each top-level instruction opens a root span at depth 1.
  • Each inner call attaches to the open span one depth above it.
  • The call then opens its own depth, closing any deeper span left from an earlier call.

A node that leaves stackHeight out gives no depth at all. The code then treats every inner call as a direct call from its top-level instruction, so the tree comes out flatter than the real one. The names and the count of calls stay correct.

04

The exporter

Install the one dependency with npm install @solana/[email protected], set type to module in package.json, and run the file from a folder you own, since it writes cpi-trace.json into the working directory. The key comes from CARBIUM_KEY, and the script exits with a message when that is unset. The first argument is a program address. With no argument, the script uses a busy aggregator program.

main.ts
// I0128 · Jaeger CPI call traces// https://carbium.sh/library/integrate/jaeger-cpi-call-traces// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";import { createHash } from "node:crypto";import { writeFile } from "node:fs/promises";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium key."); process.exit(1); }const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key } }));type Ix = { programIdIndex: number; stackHeight?: number };type Tx = { transaction: { message: { accountKeys: string[]; instructions: Ix[] } }; blockTime?: number | null; meta: { err: unknown; innerInstructions?: { index: number; instructions: Ix[] }[] | null; loadedAddresses?: { writable: string[]; readonly: string[] } } | null };const sha = (s: string) => createHash("sha256").update(s).digest("hex");async function main() {  const program = process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";  const sigs = await rpc.getSignaturesForAddress(address(program), { limit: 5, commitment: "confirmed" }).send();  const newest = sigs.find((s) => s.err === null);  if (!newest) { console.log("No successful signature among the 5 newest for", program); return; }  const sig = String(newest.signature);  const t = (await rpc.getTransaction(newest.signature, { commitment: "confirmed", encoding: "json", maxSupportedTransactionVersion: 1 }).send()) as unknown as Tx | null;  if (!t || !t.meta) { console.log("No transaction data for", sig); return; }  const keys = [...t.transaction.message.accountKeys, ...(t.meta.loadedAddresses?.writable ?? []), ...(t.meta.loadedAddresses?.readonly ?? [])];  const name = (i: number) => keys[i] ?? "unknown";  const inner = new Map((t.meta.innerInstructions ?? []).map((g) => [g.index, g.instructions] as const));  const spans: { name: string; parent: number; depth: number }[] = [];  t.transaction.message.instructions.forEach((ix, i) => {    const root = spans.push({ name: name(ix.programIdIndex), parent: -1, depth: 1 }) - 1;    const open = [-1, root]; // span index open at each depth    for (const c of inner.get(i) ?? []) {      const depth = Math.max(2, c.stackHeight ?? 2);      open.length = depth;      spans.push({ name: name(c.programIdIndex), parent: open[depth - 1] ?? root, depth });      open[depth] = spans.length - 1;    }  });  for (const s of spans) console.log(`${"  ".repeat(s.depth - 1)}- ${s.name}`);  console.log(`status ${t.meta.err ? "failed" : "ok"}, ${spans.length} calls, signature ${sig}`);  const traceId = sha(sig).slice(0, 32);  const startNs = `${t.blockTime ?? 0}000000000`;  const otlp = spans.map((s, i) => ({    traceId,    spanId: sha(`${sig}:${i}`).slice(0, 16),    ...(s.parent >= 0 ? { parentSpanId: sha(`${sig}:${s.parent}`).slice(0, 16) } : {}),    name: s.name,    kind: 1,    startTimeUnixNano: startNs,    endTimeUnixNano: startNs,    attributes: [{ key: "solana.program", value: { stringValue: s.name } }, { key: "solana.depth", value: { intValue: String(s.depth) } }],    status: { code: t.meta?.err ? 2 : 1 },  }));  const doc = { resourceSpans: [{ resource: { attributes: [{ key: "service.name", value: { stringValue: "solana-cpi" } }] }, scopeSpans: [{ scope: { name: "carbium-cpi" }, spans: otlp }] }] };  await writeFile("cpi-trace.json", JSON.stringify(doc, null, 2));  console.log(`wrote cpi-trace.json with ${spans.length} spans`);}main().catch((err: unknown) => {  console.error("failed:", err instanceof Error ? err.message : err);  process.exit(1);});

run: node main.ts

05

Run it and load the file

Run node main.ts with the key set. The terminal prints the tree first, one call per line and indented by depth, so you can check the shape before anything is loaded. The script then writes cpi-trace.json, which holds one resource named solana-cpi.

Each span carries solana.program and solana.depth attributes, so a search in Jaeger on a program address lists every call that program made inside the transaction. Jaeger receives the trace only after a collector takes the file in, since the file is an OTLP payload and not a Jaeger upload.

06

Where it ends

  • Every span starts and ends at the block time, because the response gives one time per transaction. Jaeger shows the call tree with no duration for any call.
  • The script reads the five newest signatures of one program. If all five failed, it stops and says so.
  • Each span takes the transaction's error as its status, since the response carries no error per call.
  • The file holds no logs, compute units or account data. It is a view of structure only.
  • Nothing is sent to Jaeger. The script writes a file, and a collector has to receive it.
  • The signature list reaches back 30 days at most, and this script reads only its newest entries.
07

When it goes wrong

what goes wrongwhat to do
The run stops with -32015 on getTransaction.The call lost maxSupportedTransactionVersion set to 1. Put the field back, since mainnet v1 transactions need it, and leave the other fields as they are.
The run prints a 401 and names an unknown key.Set CARBIUM_KEY to the complete key from your account, with no characters trimmed, and run again.
The output says No transaction data for the signature it picked.The node returned null for that signature, which can happen for an entry in the older part of the index. Run the script again so it picks the newest signatures, or pass another busy program.
The run prints No successful signature among the 5 newest for the default program.The program was quiet, or its newest five signatures all failed. Pass another busy program address as the first argument.
The tree is flat, with every inner call under its top-level instruction.The response had no stackHeight for those calls. The names and counts are still right. To read the depths, fetch the same transaction again and check whether the field is present in the raw response.
Jaeger shows nothing after the file is written.Jaeger does not read this file directly. Send the JSON to an OpenTelemetry Collector with an OTLP receiver, or post it to the collector's /v1/traces route, then search for the service name solana-cpi.
08

Questions

Does the trace show how long each cross-program call took?

No. The response gives one block time per transaction, so every span has the same start and end, and Jaeger shows only the structure. Timing per call needs data this script does not read.

Can it trace more than one transaction in a run?

Yes, by reading more entries from the same signature list and running the two reads for each one. Each transaction read costs 50 cells, so check the account's budget before you widen the loop.

Why does the trace ID come from the signature?

A SHA-256 of the signature gives the same trace and span IDs on every run. Running the script again on the same transaction does not create a second trace under new IDs.

Does this need a Jaeger account or a Jaeger key?

No. The script reads from Carbium with your key and writes a file to disk. The Jaeger side is whichever collector and backend you already run.