opencode-otel-plugin 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +134 -26
  2. package/dist/index.js +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -127,41 +127,149 @@ Use an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) to fa
127
127
 
128
128
  ## What Gets Collected
129
129
 
130
- ### Traces
130
+ ### Span Hierarchy
131
131
 
132
- Each OpenCode session produces a trace tree with parent-child relationships:
132
+ Each OpenCode session produces a trace tree with explicit parent-child relationships:
133
133
 
134
- | Span | Trigger | Key Attributes |
134
+ ```
135
+ invoke_agent opencode ← root span (one per session)
136
+ ├── chat {model} ← child span (one per LLM request)
137
+ ├── execute_tool {tool_name} ← child span (one per tool call)
138
+ └── session_compaction ← child span (one per compaction)
139
+ ```
140
+
141
+ ### Trace Attributes
142
+
143
+ #### `invoke_agent opencode` — Session Root Span
144
+
145
+ Created when a session starts, ended on `session.idle`. One per coding session.
146
+
147
+ | Attribute | Type | Description |
135
148
  |---|---|---|
136
- | `invoke_agent opencode` | Session start | `gen_ai.agent.name`, `gen_ai.conversation.id` |
137
- | `chat {model}` | LLM request | `gen_ai.request.model`, `gen_ai.provider.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` |
138
- | `execute_tool {name}` | Tool call | `gen_ai.tool.name`, `gen_ai.tool.call.id`, `code.language` (edit/write tools) |
139
- | `session_compaction` | Context compaction | `gen_ai.conversation.id` |
149
+ | `gen_ai.operation.name` | string | Always `"invoke_agent"` |
150
+ | `gen_ai.agent.name` | string | Always `"opencode"` |
151
+ | `gen_ai.conversation.id` | string | OpenCode session ID |
152
+ | `service.version` | string | OpenCode version (set when `installation.updated` fires) |
153
+ | `vcs.repository.ref.name` | string | Current git branch |
154
+ | `enduser.id` | string | Git author email (`git config user.email`) |
155
+ | `vcs.repository.url.full` | string | Git remote URL |
156
+ | `opencode.session.request_count` | number | Total LLM requests in session (set when span ends) |
157
+
158
+ #### `chat {model}` — LLM Request Span
159
+
160
+ Created on `chat.params` hook, ended when the assistant message arrives with token counts.
161
+
162
+ | Attribute | Type | Description |
163
+ |---|---|---|
164
+ | `gen_ai.operation.name` | string | Always `"chat"` |
165
+ | `gen_ai.request.model` | string | Model ID sent in the request (e.g., `claude-sonnet-4-20250514`) |
166
+ | `gen_ai.provider.name` | string | Provider identifier (e.g., `anthropic`, `openai`) |
167
+ | `gen_ai.conversation.id` | string | OpenCode session ID |
168
+ | `vcs.repository.ref.name` | string | Current git branch |
169
+ | `enduser.id` | string | Git author email |
170
+ | `vcs.repository.url.full` | string | Git remote URL |
171
+ | `gen_ai.usage.input_tokens` | number | Input tokens consumed (set on completion) |
172
+ | `gen_ai.usage.output_tokens` | number | Output tokens generated (set on completion) |
173
+ | `gen_ai.response.model` | string | Model ID from the response |
174
+ | `gen_ai.response.finish_reasons` | string[] | Finish reasons array (e.g., `["end_turn"]`) |
175
+ | `error.type` | string | Error class name (set only on failure) |
176
+
177
+ #### `execute_tool {name}` — Tool Execution Span
178
+
179
+ Created on `tool.execute.before`, ended on `tool.execute.after`. Includes flattened tool output metadata.
180
+
181
+ | Attribute | Type | Description |
182
+ |---|---|---|
183
+ | `gen_ai.operation.name` | string | Always `"execute_tool"` |
184
+ | `gen_ai.tool.name` | string | Tool name (e.g., `edit`, `write`, `bash`, `glob`) |
185
+ | `gen_ai.tool.call.id` | string | Unique tool call identifier |
186
+ | `gen_ai.conversation.id` | string | OpenCode session ID |
187
+ | `vcs.repository.ref.name` | string | Current git branch |
188
+ | `enduser.id` | string | Git author email |
189
+ | `vcs.repository.url.full` | string | Git remote URL |
190
+ | `gen_ai.tool.output.title` | string | Tool output title (set on completion) |
191
+ | `gen_ai.tool.output.metadata.*` | string | Flattened tool output metadata (max 32 keys, depth 3, strings truncated to 256 chars) |
192
+ | `code.language` | string | Detected programming language (edit, write, and apply_patch tools only; derived from file extension) |
193
+
194
+ #### `session_compaction` — Context Compaction Span
195
+
196
+ Created as an instant span when OpenCode compacts the conversation context.
197
+
198
+ | Attribute | Type | Description |
199
+ |---|---|---|
200
+ | `gen_ai.conversation.id` | string | OpenCode session ID |
201
+ | `vcs.repository.ref.name` | string | Current git branch |
202
+ | `enduser.id` | string | Git author email |
203
+ | `vcs.repository.url.full` | string | Git remote URL |
140
204
 
141
205
  ### Metrics
142
206
 
143
- | Metric | Type | Unit | Description |
144
- |---|---|---|---|
145
- | `gen_ai.client.token.usage` | Histogram | `{token}` | Input/output tokens per LLM call |
146
- | `gen_ai.client.operation.duration` | Histogram | `s` | LLM call duration |
147
- | `opencode.session.request.count` | Counter | `{request}` | LLM requests per session |
148
- | `opencode.session.compaction.count` | Counter | `{compaction}` | Context compactions |
149
- | `opencode.file.changes` | Counter | `{line}` | Lines added/removed |
150
- | `opencode.tool.invocations` | Counter | `{invocation}` | Tool calls |
207
+ #### `gen_ai.client.token.usage` Token Usage
208
+
209
+ Histogram measuring token consumption per LLM call. Unit: `{token}`.
210
+
211
+ | Attribute | Type | Description |
212
+ |---|---|---|
213
+ | `gen_ai.operation.name` | string | Always `"chat"` |
214
+ | `gen_ai.provider.name` | string | Provider identifier |
215
+ | `gen_ai.request.model` | string | Model ID |
216
+ | `gen_ai.token.type` | string | `"input"` or `"output"` — recorded as two separate data points per call |
217
+
218
+ #### `gen_ai.client.operation.duration` — LLM Call Duration
219
+
220
+ Histogram measuring LLM request latency. Unit: `s` (seconds).
221
+
222
+ | Attribute | Type | Description |
223
+ |---|---|---|
224
+ | `gen_ai.operation.name` | string | Always `"chat"` |
225
+ | `gen_ai.provider.name` | string | Provider identifier |
226
+ | `gen_ai.request.model` | string | Model ID |
227
+ | `error.type` | string | Error class name (present only on failed requests) |
228
+
229
+ #### `opencode.session.request.count` — LLM Request Count
230
+
231
+ Counter tracking total LLM requests. Unit: `{request}`.
232
+
233
+ | Attribute | Type | Description |
234
+ |---|---|---|
235
+ | `gen_ai.request.model` | string | Model ID |
236
+ | `gen_ai.provider.name` | string | Provider identifier |
237
+
238
+ #### `opencode.session.compaction.count` — Compaction Count
239
+
240
+ Counter tracking context compaction events. Unit: `{compaction}`. No attributes.
241
+
242
+ #### `opencode.file.changes` — File Change Lines
243
+
244
+ Counter tracking lines of code added or removed by edit, write, and apply_patch tools. Unit: `{line}`.
245
+
246
+ | Attribute | Type | Description |
247
+ |---|---|---|
248
+ | `code.language` | string | Detected programming language (omitted for unknown file extensions) |
249
+ | `opencode.change.type` | string | `"added"` or `"removed"` |
250
+
251
+ #### `opencode.tool.invocations` — Tool Invocation Count
252
+
253
+ Counter tracking tool executions. Unit: `{invocation}`.
254
+
255
+ | Attribute | Type | Description |
256
+ |---|---|---|
257
+ | `gen_ai.tool.name` | string | Tool name (e.g., `edit`, `bash`, `glob`, `read`) |
151
258
 
152
259
  ### Resource Attributes
153
260
 
154
- Attached to all signals, identifying the session:
261
+ Attached to all exported signals (traces and metrics), identifying the session environment. Set once at plugin initialization.
155
262
 
156
- | Attribute | Source |
157
- |---|---|
158
- | `service.name` | Always `"opencode"` |
159
- | `service.version` | OpenCode version (set when available) |
160
- | `enduser.id` | `git config user.email` |
161
- | `host.name` | Machine hostname |
162
- | `opencode.project.name` | Project identifier |
163
- | `vcs.repository.url.full` | Git remote URL |
164
- | `vcs.repository.ref.name` | Current branch |
263
+ | Attribute | Type | Description |
264
+ |---|---|---|
265
+ | `service.name` | string | Always `"opencode"` |
266
+ | `host.name` | string | Machine hostname |
267
+ | `enduser.id` | string | Git author email (`git config user.email`) |
268
+ | `opencode.project.name` | string | Project identifier from OpenCode |
269
+ | `vcs.repository.url.full` | string | Git remote URL |
270
+ | `vcs.repository.ref.name` | string | Current git branch |
271
+ | `opencode.worktree` | string | Git worktree path |
272
+ | `opencode.directory` | string | Current working directory |
165
273
 
166
274
  ## Troubleshooting
167
275
 
@@ -209,7 +317,7 @@ This plugin follows [OpenTelemetry GenAI Semantic Conventions](https://opentelem
209
317
  git clone https://github.com/felixti/opencode-otel-plugin.git
210
318
  cd opencode-otel-plugin
211
319
  bun install
212
- bun test # 55 tests, 96 assertions
320
+ bun test # 62 tests, 103 assertions
213
321
  bun run typecheck # tsc --noEmit
214
322
  bun run build # dist/index.js + dist/index.d.ts
215
323
  ```