# Add Custom Span Attributes with OpenTelemetry from a Linear Issue

An agent adds two order attributes to a Go checkout span, registers them in the telemetry schema, and adds a test that fails without them.

[Run this on Rush](https://cloud.getrush.ai/run/add-custom-span-attributes/opentelemetry/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads `PlaceOrder` in `src/checkout/main.go` and the existing `main_test.go` first. The span already carries `demo.order.amount` and `demo.order.items.count`, so it adds `app.order.amount` and `app.order.items.count` beside them from the same `totalPriceFloat` and `len(prep.orderItems)`, leaving the old keys for whatever already reads them.

The repository has no fixtures for checkout's gRPC clients, so `TestPlaceOrderSetsOrderSpanAttributes` brings small stubs for cart, catalog, currency and payment, a fake HTTP transport for shipping and email, and a `tracetest.SpanRecorder`. It expects an amount of 35 and a count of 2. The agent also declares both keys in `telemetry-schema/attributes/order.yaml` and `telemetry-schema/services/checkout.yaml`.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Add Custom Span Attributes with OpenTelemetry. In the checkout service, add app.order.amount and app.order.items.count attributes to the PlaceOrder span and a test that asserts they are set.\" Do the work in this repository, add tests for it, run docker compose build for the touched services, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on open-telemetry/opentelemetry-demo at 33bd8231: 4 files changed, 117 insertions(+): `src/checkout/main.go` (+2), `src/checkout/main_test.go` (+101) and the two schema files (+12, +2). The issue text was written for the trial and had no ID. `go test ./...` passed before and after, ending `ok  	github.com/open-telemetry/opentelemetry-demo/src/checkout	0.012s`. With the two new lines removed the test failed with `app.order.amount = -1, want 35`; restored, it printed `--- PASS: TestPlaceOrderSetsOrderSpanAttributes (0.00s)`.

Not verified: `docker compose build checkout` exited 127 with `docker: command not found`, and no schema validation was run on the YAML. For the reviewer: whether the issue meant a rename, in which case the `demo.*` lines and their schema entries go.

## Run it on every Linear issue labeled agent

An automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` runs the `linear-label-to-pr` recipe's prompt when someone in your Rush org labels an observability request. An issue that says whether the `demo.order.*` keys should be renamed rather than joined by `app.*` ones settles the decision this run left to a reviewer.

## Why run it on Rush?

A span attribute test is easy to write so it passes either way. This run proved the test bites by deleting the two attributes and watching it fail with both missing, and it noticed the span already had `demo.*` equivalents, which a reviewer has to rule on before dashboards split across two names.

## Frequently asked questions

### Why not just rename the demo.order attributes?

Other services and dashboards may already query `demo.order.amount`. The agent added the `app.*` keys alongside and named the rename as a reviewer's choice rather than breaking existing consumers.

### Was the Docker image built?

No. The sandbox had no `docker`, so `docker compose build checkout` could not run before or after. Only Go source and YAML changed, and the Go module's own tests passed, but CI or a reviewer still needs to build the image.

## More OpenTelemetry jobs

- [Add an OTLP Exporter for Your Own Backend to the OpenTelemetry Collector](https://getrush.ai/run/add-otlp-exporter/opentelemetry/)
- [Add Tail-Based Sampling to an OpenTelemetry Collector Pipeline](https://getrush.ai/run/add-tail-sampling/opentelemetry/)
- [Drop Health Check Spans from OpenTelemetry Traces](https://getrush.ai/run/drop-health-check-spans/opentelemetry/)

## More jobs like this: Turn a Linear label into a PR

- [Add a Customer Lifetime Value Model to a dbt Project from a Linear Issue](https://getrush.ai/run/add-customer-ltv-model/dbt/)
- [Add D1 Migrations to a Cloudflare Worker](https://getrush.ai/run/add-d1-migrations/cloudflare-workers/)
- [Add Dark Mode to a Reflex App](https://getrush.ai/run/add-dark-mode/reflex/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
