Commit aa92006
feat(local): render OTel semantic attributes in transaction output (#1015)
## Summary
Enhance `sentry local` for the agent monitoring launch with OTel
semantic attribute rendering, JSON output, SSE reconnection, and several
quality improvements.
### OTel Semantic Display
Port `trace-semantic-display` from sentry-mcp ([PR
#981](getsentry/sentry-mcp#981)) to enrich tail
output with OTel semantic attribute rendering. Transactions with GenAI,
MCP, HTTP, database, and other OTel attributes now show rich labels:
```
[gen_ai] chat anthropic/claude-4-sonnet [1200ms] [5 spans]
[mcp] tools/call search_files [320ms]
[db] SELECT users [postgresql] [12ms]
```
Covers 15 attribute families: GenAI, MCP, HTTP, database, GraphQL,
RPC/cloud, messaging, FaaS, object stores, CloudEvents, CICD, feature
flags, process, exception, and error types. Falls back to existing
behavior when no semantic attributes are present.
### `--format json` (NDJSON)
New `--format json` / `-F json` flag for machine-readable output. Each
envelope item produces one JSON line with structured fields including
semantic labels, stack frames, and source detection:
```json
{"type":"transaction","op":"gen_ai","label":"chat anthropic/claude-4-sonnet","duration_ms":1200,"source":"server"}
{"type":"error","error_type":"TypeError","message":"x is not a function","filename":"app.ts","lineno":42,"source":"server"}
```
### `--filter ai`
New filter value that matches transactions with GenAI or MCP OTel
attributes, so you can focus on agent activity: `sentry local -f ai`
### SSE Reconnection
The SSE consumer now reconnects automatically with exponential backoff
on connection loss, using `Last-Event-ID` to resume from where the
stream left off. Retry counter resets after successful reconnection.
Transient HTTP errors after a previous successful session are retried
rather than treated as fatal.
### Quality Improvements
- **Signal handler leak fixed** in `run.ts` — named handler refs,
cleanup in `finally`, settled flag for close/error race
- **`parsePort` deduplicated** — single implementation exported from
`server.ts`
- **`SENTRY_TRACES_SAMPLE_RATE`** preserved when already set (uses `??`
fallback)
- **Startup banner** with ingest URL, SSE endpoint, and connection hints
- **Agent monitoring docs** with GenAI/MCP examples and JSON output
section
## Files Changed
| File | Change |
|------|--------|
| `src/lib/formatters/semantic-display.ts` | **New** — OTel semantic
attribute rendering (15 families) |
| `src/lib/formatters/local.ts` | Semantic display integration, JSON
formatters, `--filter ai`, `inferSourceName` |
| `src/commands/local/server.ts` | SSE reconnection, `--format json`,
`--filter ai`, `parsePort` export, `feedSSELine` id tracking, startup
banner |
| `src/commands/local/run.ts` | Signal handler fix, `parsePort` import,
env var preservation |
| `docs/src/fragments/commands/local.md` | Agent monitoring section,
JSON output section |
| `test/lib/formatters/semantic-display.test.ts` | **New** — 70+ tests
for all semantic formatters |
| `test/lib/formatters/local.test.ts` | AI transaction tests, JSON
format tests |
| `test/commands/local/server.test.ts` | **New** — parsePort,
feedSSELine, buildApp, CORS, isServerRunning |
| `test/commands/local/run.test.ts` | Expanded — ENOENT, env
preservation, separator handling |
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent 8edfa2a commit aa92006
10 files changed
Lines changed: 2525 additions & 69 deletions
File tree
- docs/src/fragments/commands
- plugins/sentry-cli/skills/sentry-cli/references
- src
- commands/local
- lib/formatters
- test
- commands/local
- lib/formatters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 33 | | |
45 | 34 | | |
46 | 35 | | |
| |||
140 | 129 | | |
141 | 130 | | |
142 | 131 | | |
143 | | - | |
| 132 | + | |
| 133 | + | |
144 | 134 | | |
145 | 135 | | |
146 | 136 | | |
| |||
155 | 145 | | |
156 | 146 | | |
157 | 147 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
163 | 153 | | |
164 | 154 | | |
165 | 155 | | |
166 | 156 | | |
167 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
168 | 164 | | |
169 | 165 | | |
170 | 166 | | |
171 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
172 | 171 | | |
173 | 172 | | |
174 | 173 | | |
| 174 | + | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| |||
0 commit comments