---
title: Inspect agents written in other languages
description: Point a Python or TypeScript agent's OTLP trace exporter at Studio's /v1/traces and give its spans the OTel GenAI names; Studio derives a run per invoke_agent span with a conversation id — steps, tools, usage and cost, but no events or transcript.
url: https://weftgo.dev/docs/observe/other-languages/
type: how-to
sources:
  - 'weft/docs/record-contract.md (§9: which spans make a run: a conversation id or a top-level agent; a nested agent folds; the late parent and the removed row; no invoke_agent, no run)'
  - 'weft/CHANGELOG.md:41 (0.20.0: derived runs from the producer''s content, message_count, steps args and result, the story from gen_ai messages, the header''s fix said once, the chip, hidden verbs, run_ids, not_run, ?not_run=1), 42 (GenAI log events; derived sessions, turns 1..n), 66 (setup B''s Python line), 81 (a read-scoped panel token''s stock spans without the system prompt), 91-92 (SQLite 0026 / ClickHouse 0031 re-derive only the stored stock traces the new rule changes, once, on the first open — v0.20.2)'
  - weft/studio/README.md:60-80 (the Python line, the bare origin, http/protobuf, what makes a run, derived sessions)
  - 'docs-site/examples/otherlang/otherlang_test.go: TestNoConversationIDIsARunWithNoSession (passes against ../weft-rc020 through a scratch go.work)'
  - weft/docs/record-contract.md:46-76 (§1 transport, attribute value forms), 1652-1886 (§9 deriving a run from stock spans)
  - weft/studio/README.md:1792-1814 (Derived runs), 3477-3480 (OTLP ingest)
  - weft/studio/ingest/ingest.go:1-17 (the receiver), 37-39 (MaxBody 16 MiB), 41-73 (Traces, Logs)
  - weft/studio/studio.go:81-87 (IngestToken), 346-379 (ingest auth, loopback peers only without a token)
  - weft/cmd/weft/main.go:863-875 (weft studio sets no ingest token)
  - weft/obsdb/stock.go (DeriveStockRuns); weft/obsdb/stock_test.go:20 (ExampleDeriveStockRuns)
  - weft/obsdb/testdata/contract/stock_genai/traces.json, expect.json
  - weft/CHANGELOG.md:544, 566, 567, 569, 570, 571, 572, 574, 575, 577-583, 609, 4127
  - docs-site/examples/otherlang/stock-spans.json, otherlang_test.go TestStockSpansMakeADerivedRun, TestNoConversationIDNoRun, TestIngestToken
---

# Inspect agents written in other languages

Studio reads stock OpenTelemetry spans, not only weft's. Export your agent's traces over OTLP/HTTP to Studio's ingest, `POST /v1/traces`, and name the spans by the OTel GenAI conventions: an `invoke_agent` span carrying `gen_ai.conversation.id`, with `chat` spans for model calls and `execute_tool` spans for tool calls under it. Studio derives one run per such span: its steps, tools, usage and cost. It has no events, transcript or requests, and says so with the `derived` badge.

In Python, with the OpenTelemetry SDK and its OTLP/HTTP exporter (`opentelemetry-sdk`, `opentelemetry-exporter-otlp-proto-http`), against a `weft studio` on its default address:

```python
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

provider = TracerProvider(resource=Resource.create({"service.name": "py-support"}))
provider.add_span_processor(
    BatchSpanProcessor(OTLPSpanExporter(endpoint="http://127.0.0.1:7331/v1/traces")))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("support-agent")

def handle(conversation_id, prompt):
    with tracer.start_as_current_span("invoke_agent support", attributes={
        "gen_ai.operation.name": "invoke_agent",
        "gen_ai.agent.name": "support",
        "gen_ai.conversation.id": conversation_id,   # without it: a trace, no run
    }):
        with tracer.start_as_current_span("chat gpt-5", kind=trace.SpanKind.CLIENT, attributes={
            "gen_ai.operation.name": "chat",
            "gen_ai.provider.name": "openai",
            "gen_ai.request.model": "gpt-5",
        }) as chat:
            reply = call_model(prompt)               # your model call
            chat.set_attribute("gen_ai.usage.input_tokens", reply.input_tokens)
            chat.set_attribute("gen_ai.usage.output_tokens", reply.output_tokens)
        with tracer.start_as_current_span("execute_tool lookup_order", attributes={
            "gen_ai.operation.name": "execute_tool",
            "gen_ai.tool.name": "lookup_order",
            "gen_ai.tool.call.id": reply.call_id,
        }):
            run_tool(reply)                          # your tool call

# at exit: the batch processor exports in the background; flush what is queued
provider.shutdown()
```

In TypeScript the OTLP/HTTP trace exporter takes the same URL, `new OTLPTraceExporter({ url: 'http://127.0.0.1:7331/v1/traces' })` from `@opentelemetry/exporter-trace-otlp-proto` or `@opentelemetry/exporter-trace-otlp-http`, and the spans take the same names and attributes. A GenAI instrumentation library that already emits `chat` spans for your model calls needs only the enclosing `invoke_agent` span with a conversation id, provided it writes `gen_ai.provider.name` (semconv 1.37 and later). Studio reads the provider from that key only; a span with the older `gen_ai.system` gives a run with no provider, which reads unpriced.

## Send spans to Studio

Studio's receiver takes OTLP/HTTP at `POST /v1/traces` and `POST /v1/logs`: protobuf or JSON, optionally gzip, at most 16 MiB per request after decompression. A write failure answers 503, so the exporter retries; a retried export lands on the same rows. OTLP over gRPC is not served.

| Studio | Ingest URL | Auth |
|---|---|---|
| `weft studio` or `weft dev` | `http://127.0.0.1:7331/v1/traces` (or the port it printed) | none: loopback peers only |
| embedded under `/studio/` | `<app>/studio/v1/traces` | as the Studio was built |
| built with [`studio.IngestToken(tok)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#IngestToken) | its address | `Authorization: Bearer <tok>` |

Without an ingest token, ingest answers only peers on the same machine, and refuses a request a proxy forwarded (`Forwarded`, `X-Forwarded-For`, `X-Real-IP`) and a browser page from an origin nobody allowed. A browser exporter sends an `Origin`, which loopback ingest refuses unless it is a localhost origin or one the Studio's `AllowOrigins` names.

A Studio reachable from other hosts needs an ingest token. `weft studio` has no option for one, so it takes exports from this machine only; an app on another host exports to an embedded or hosted Studio built with `studio.IngestToken(tok)` ([Run Studio](https://weftgo.dev/docs/observe/studio/setup/)). The ingest token is separate from the Studio's API token (`studio.Token`). Your exporter sends it as a header:

- Python: `OTLPSpanExporter(endpoint=…, headers={"Authorization": "Bearer <tok>"})`
- TypeScript: `new OTLPTraceExporter({ url: …, headers: { Authorization: 'Bearer <tok>' } })`
- Either SDK, from the environment: `OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20<tok>`

A Python agent instrumented by the OpenTelemetry GenAI contrib packages exports to a local `weft studio` with:

```sh
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:7331 OTEL_METRICS_EXPORTER=none OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true opentelemetry-instrument python app.py
```

The endpoint is the bare origin: the exporter adds `/v1/traces` and `/v1/logs` itself. Python's exporter defaults to gRPC, so it needs `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf`; the JavaScript one defaults to HTTP. `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` turns content capture on, which the story and the tool calls below read. A stock `invoke_agent` span makes a run; any other GenAI span is a trace.

Log records your agent exports to `/v1/logs` are stored as app logs. Those emitted under the run's spans show on the run's logs view, as a weft run's [bridged lines](https://weftgo.dev/docs/observe/app-logs/#in-studio) do.

### Check it with an OTLP/JSON body

This body is a two-step run of a Python agent, in `otherlang/stock-spans.json`:

```json title="otherlang/stock-spans.json"
{
  "resourceSpans": [{
    "resource": {"attributes": [
      {"key": "service.name", "value": {"stringValue": "py-support"}}
    ]},
    "scopeSpans": [{
      "scope": {"name": "support-agent"},
      "spans": [
        {
          "traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "00f067aa0ba902b7",
          "name": "invoke_agent support", "kind": 1,
          "startTimeUnixNano": "1790848800000000000", "endTimeUnixNano": "1790848803200000000",
          "attributes": [
            {"key": "gen_ai.operation.name", "value": {"stringValue": "invoke_agent"}},
            {"key": "gen_ai.agent.name", "value": {"stringValue": "support"}},
            {"key": "gen_ai.conversation.id", "value": {"stringValue": "conv_7f3a"}}
          ],
          "status": {"code": 1}
        },
        {
          "traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "a1b2c3d4e5f60001",
          "parentSpanId": "00f067aa0ba902b7", "name": "chat gpt-5", "kind": 3,
          "startTimeUnixNano": "1790848800050000000", "endTimeUnixNano": "1790848801250000000",
          "attributes": [
            {"key": "gen_ai.operation.name", "value": {"stringValue": "chat"}},
            {"key": "gen_ai.provider.name", "value": {"stringValue": "openai"}},
            {"key": "gen_ai.request.model", "value": {"stringValue": "gpt-5"}},
            {"key": "gen_ai.usage.input_tokens", "value": {"intValue": "812"}},
            {"key": "gen_ai.usage.output_tokens", "value": {"intValue": "41"}}
          ]
        },
        {
          "traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "a1b2c3d4e5f60002",
          "parentSpanId": "00f067aa0ba902b7", "name": "execute_tool lookup_order", "kind": 1,
          "startTimeUnixNano": "1790848801300000000", "endTimeUnixNano": "1790848801420000000",
          "attributes": [
            {"key": "gen_ai.operation.name", "value": {"stringValue": "execute_tool"}},
            {"key": "gen_ai.tool.name", "value": {"stringValue": "lookup_order"}},
            {"key": "gen_ai.tool.call.id", "value": {"stringValue": "call_abc"}}
          ]
        },
        {
          "traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "a1b2c3d4e5f60003",
          "parentSpanId": "00f067aa0ba902b7", "name": "chat gpt-5", "kind": 3,
          "startTimeUnixNano": "1790848801500000000", "endTimeUnixNano": "1790848803100000000",
          "attributes": [
            {"key": "gen_ai.operation.name", "value": {"stringValue": "chat"}},
            {"key": "gen_ai.provider.name", "value": {"stringValue": "openai"}},
            {"key": "gen_ai.request.model", "value": {"stringValue": "gpt-5"}},
            {"key": "gen_ai.usage.input_tokens", "value": {"intValue": "905"}},
            {"key": "gen_ai.usage.output_tokens", "value": {"intValue": "37"}}
          ]
        }
      ]
    }]
  }]
}
```

[otherlang/stock-spans.json on GitHub](https://github.com/weftgo/weftgo.dev/blob/main/docs-site/examples/otherlang/stock-spans.json)

Post it to a running `weft studio` from `docs-site/examples`; the run appears in Studio's runs list as agent `support`, started 1 Oct 2026 (the list is ordered by start time):

```sh
curl -sS -X POST http://127.0.0.1:7331/v1/traces \
  -H 'Content-Type: application/json' --data @otherlang/stock-spans.json
```

`TestStockSpansMakeADerivedRun` posts the same file to a Studio and reads the row back. It reads id `otel-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7`, `derived: true`, agent `support`, service `py-support`, provider `openai`, model `gpt-5`. It has session `conv_7f3a`, status `succeeded`, 2 steps, 1,717 input and 78 output tokens, and a known cost priced from the shipped table's `gpt-5` row like any run. Its page has one hole, `derived`, reason `derived from spans · no events`, and its transcript is empty with that badge.

## Derived runs

A derived run is listed and searched with your weft runs. What Studio shows for it:

![A run Studio derived from stock OpenTelemetry GenAI spans: agent support on openai/gpt-5, 2 steps, 1,717 in · 78 out, the derived badge with its reason and fix, replay, save as test, open in app and compare hidden, and its chat and execute_tool spans on the waterfall](https://weftgo.dev/docs/_astro/studio-run-derived.light.05cM8ifq.webp)

*A run derived from stock OTel GenAI spans: the derived badge and its fix, the weft-only actions hidden, its spans on the waterfall.*

| Surface | A derived run |
|---|---|
| runs list, search, live | a row badged `derived`, searchable by agent, model and error text |
| sessions | its turns grouped under `gen_ai.conversation.id`, the conversation as the session; a session every turn of which is derived is marked "derived (stock OTel)" (`derived: true`) and numbers its turns 1..n by start order |
| run page | the span waterfall; a story of per-step cards, one per `chat` span, each with its USER, ASSISTANT and tool-call rows read from the span's `gen_ai.input.messages`, `gen_ai.output.messages` and `gen_ai.system_instructions` when the producer captured content |
| a step (`/api/runs/{id}/steps/{n}`) | the `chat` span's times and usage, priced like any step (unknown, never a known $0, when the span has no `gen_ai.usage.*`). Its `execute_tool` spans become calls, with `args` and `result` from `gen_ai.tool.call.arguments` and `gen_ai.tool.call.result` when the producer captured them (else `args` `null` and no `result`), and `call_id` `""` for a span without `gen_ai.tool.call.id` |
| logs | the app log records under its spans; a GenAI log event (`gen_ai.<role>.message`, `gen_ai.choice`) is drawn as that message, and the story lists such messages below the step cards as "messages the app logged" |
| export | `json`, `jsonl` and `otlp`: the row and the spans, every other block badged |

Not derivable, and shown as missing with the `derived` badge rather than as empty: events (`event_count` 0, no event stream), the transcript, the request and catalog, the turn, public id, stop reason and pending calls. A derived row's `message_count` counts its `chat` spans that carry message content. The run header says the badge's reason and fix once, for a Python or TypeScript developer: turn content capture on (`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true`), set `gen_ai.conversation.id` for a session, and "weft's own records need a weft SDK (Go today)" ([the record contract](https://github.com/weftgo/weft/blob/v0.20.2/docs/record-contract.md) gives events, the transcript and requests). Every block read off the spans then carries the chip "derived · from span attributes" alone.

What a derived run cannot do, because there is no transcript to replay:

- The playground's run, preview and fixtures routes refuse a derived source run with 400 and the badge, after authentication and before any check of the command's content, so no command reaches a runtime. Studio and the devtools panel hide replay, save as test, open in app and compare on a derived run, and say why once: "they need weft's records".
- `export?format=wefttest` is 400 with the badge.
- `diff` against a derived side marks every column `unknown`; only unequal step counts show.
- A panel token never reads a derived run: it has no public id. A read-scoped panel token is served stock spans without their system prompt (`gen_ai.system_instructions`, system-role messages, `gen_ai.prompt`).

**A trace that makes no run says why.** `GET /api/traces` and `/api/traces/{id}` name a trace's derived runs in `run_ids`. `/api/traces/{id}` answers `not_run` `{reason, fix}` when the trace makes none: "model or tool calls only: no invoke_agent span opens a run" (a model-call instrumentation under an HTTP handler), or "its agent span has not arrived". `/api/traces?not_run=1` lists the GenAI traces that make no run, and the runs page says how many arrived over the last 7 days, linking that list.

## How Studio derives a run

The derivation is one function in `obsdb`, [`obsdb.DeriveStockRuns`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DeriveStockRuns), used by both backends ([`ExampleDeriveStockRuns`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#example-DeriveStockRuns)). Its rules, summarised from [§9 of the record contract], which is the reference(https://github.com/weftgo/weft/blob/v0.20.2/docs/record-contract.md#9-deriving-a-run-from-stock-spans):

- **A root is one run.** A root is a span whose operation is `invoke_agent` and that has no `weft.run.id`. It must also either carry `gen_ai.conversation.id`, the run's session, or have no other `invoke_agent` span stored above it in its trace: a top-level agent, a run with no session. An `invoke_agent` span without a conversation id nested under another agent span is not a root; its `chat` and `execute_tool` spans count toward the enclosing root's run. Whether an agent is top-level is read from the stored spans. When an enclosing agent arrives in a later export, the trace is derived again: the inner run's row is deleted (its spans stay, now the enclosing run's) and announced on the live lane as a removed row, so an open list drops it. A trace whose GenAI spans include no `invoke_agent` span makes no run.
- **The operation comes from the attribute, else the name.** `gen_ai.operation.name` decides; an empty value counts as unset. Without it, a name starting `invoke_agent` or `execute_tool`, or `chat` alone or followed by a space, decides. A `chatbot` span is not a model call.
- **The subtree stops at nested roots and at weft spans.** A root inside another root's subtree is its own run, a child linked by the `gen_ai.tool.call.id` of the nearest `execute_tool` above it. A span with `weft.run.id` is never derived, so weft's own runs never get a derived twin; a stock agent called from a weft tool is a top-level run in its own conversation, and deleting the weft run deletes it too.
- **Runs converge across exports.** A span counts only through a complete chain of stored parents, and a trace is derived again from all its spans whenever an export brings a GenAI span. A batch processor that exports children before their root still ends with the whole run.
- **Fields come from the root, then the `chat` spans.** The id is `otel-<trace id>-<root span id>`, the same on every retry. Agent from `gen_ai.agent.name`, provider and model from the root or the first `chat` span, service from the resource's `service.name`. Status is `failed` with the root's status description when the root's status is `Error`, else `succeeded`; a failed root with no description reads "the root span's status is Error (no description)".
- **Usage is the run's own.** The root's `gen_ai.usage.*`, when present, taken as given; else the sum over the subtree's `chat` spans, nested roots excluded. No correction either way: a producer whose root totals include its children's usage counts them twice. Steps are the `chat` spans in start order; tools the `execute_tool` spans, each on the latest step that started before it.

Attribute values may be integers, doubles or decimal strings: a reader takes `"812"` as 812. The run's spans, read back, carry `weft.step.index` and `weft.tool.seq` stamped by the reader and `gen_ai.operation.name` as the derivation resolved it.

## Complete example

The test that checks this page, in `otherlang/otherlang_test.go`, starts a Studio on a loopback port over a fresh database, posts `stock-spans.json` to `/v1/traces` and reads `/api/runs`, the run document and its transcript back. It also strips the conversation id and finds a derived run with no session, and checks that a Studio built with `studio.IngestToken` answers 401 to an export without the bearer.

```sh
go test ./otherlang
```

## Best practices & gotchas

- **Set `gen_ai.conversation.id` on the agent span to group runs into a session.** Without it a top-level agent is still a run, with no session; a nested agent without it folds into its parent. (Source: record contract §9; `TestNoConversationIDIsARunWithNoSession`)
- **Capture content to read a derived run's story.** Without `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` the steps have no messages and the calls no arguments or results. (Source: CHANGELOG.md:41)
- **Report usage on the `chat` spans.** A run whose spans carry no `gen_ai.usage.*` key reads zero tokens and an unknown cost, never a known $0. (Source: record contract §9, usage)
- **Give the root its own usage, not a total.** A root's usage is taken as given; totals that include nested agents count them twice in the parent's cost. (Source: record contract §9, "Usage and cost of derived children")
- **Use an ingest token beyond loopback.** Without one, Studio's ingest answers peers on the same machine only. (Source: `studio.IngestToken` godoc; `studio/studio.go:346-379`)
- **Do not start a [`weft.RunID`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#RunID) with `otel-`.** Derived ids use that prefix. This is a convention of the record contract; nothing in the core enforces it. (Source: record contract §9, `id`; `core/run.go:232`)

## See also

- [Use your own OpenTelemetry SDK](https://weftgo.dev/docs/observe/opentelemetry/#genai-semantic-conventions): the GenAI attributes weft writes
- [Run Studio: embedded, local binary or hosted](https://weftgo.dev/docs/observe/studio/setup/)
- [Read a run in Studio](https://weftgo.dev/docs/observe/studio/run-page/)
- [The record contract](https://github.com/weftgo/weft/blob/v0.20.2/docs/record-contract.md): emit weft's records from any language for a full run

Symbols used: [`studio.IngestToken`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#IngestToken) · [`obsdb.DeriveStockRuns`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DeriveStockRuns) · [`ExampleDeriveStockRuns`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#example-DeriveStockRuns)
