Skip to content

Commit 8ec7c48

Browse files
Merge pull request #11 from DEVtheOPS/feat/disable-metrics
feat(config): add OPENCODE_DISABLE_METRICS to suppress individual metrics
2 parents 07d130c + 4c87afa commit 8ec7c48

20 files changed

Lines changed: 560 additions & 112 deletions

.markdownlint.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
default: true
2+
MD013: false # line-length — too strict for tables and long URLs
3+
MD024: # no-duplicate-heading
4+
siblings_only: true # allow duplicate headings in different sections (e.g. CHANGELOG)
5+
MD041: false # first-line-heading — not all files need an H1 (e.g. CLAUDE.md)

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-merge-conflict
8+
- id: check-case-conflict
9+
- id: check-json
10+
exclude: tsconfig.json # tsconfig uses JSONC (comments allowed)
11+
- id: pretty-format-json
12+
args: [--autofix, --indent=2]
13+
exclude: ^(bun\.lock|tsconfig\.json)$
14+
- id: check-yaml
15+
- id: mixed-line-ending
16+
args: [--fix=lf]
17+
18+
- repo: https://github.com/igorshubovych/markdownlint-cli
19+
rev: v0.44.0
20+
hooks:
21+
- id: markdownlint
22+
args: [--fix]
23+
24+
- repo: local
25+
hooks:
26+
- id: typecheck
27+
name: TypeScript typecheck
28+
language: system
29+
entry: bun run typecheck
30+
pass_filenames: false
31+
types: [ts]

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bun test
2020

2121
## Project layout
2222

23-
```
23+
```text
2424
src/
2525
├── index.ts — Plugin entrypoint
2626
├── types.ts — Shared types
@@ -52,7 +52,7 @@ src/
5252

5353
All commits must follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/):
5454

55-
```
55+
```text
5656
<type>[optional scope]: <description>
5757
```
5858

@@ -62,7 +62,7 @@ Use `!` or a `BREAKING CHANGE:` footer for breaking changes.
6262

6363
Examples:
6464

65-
```
65+
```text
6666
feat(handlers): add support for file.edited event
6767
fix(probe): handle malformed endpoint URL without throwing
6868
chore(deps): bump @opentelemetry/api to 1.10.0

CHANGELOG.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and
88

99
## [0.3.0](https://github.com/DEVtheOPS/opencode-plugin-otel/compare/v0.2.1...v0.3.0) (2026-03-14)
1010

11-
1211
### Features
1312

1413
* **observability:** add debug logging and enhanced metrics ([a1b0a8c](https://github.com/DEVtheOPS/opencode-plugin-otel/commit/a1b0a8cf5263080cf9623355e5161fb88f20e2f1))
@@ -21,37 +20,37 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and
2120

2221
### Changed
2322

24-
- **BREAKING** — Package renamed to `@devtheops/opencode-plugin-otel`. Update your opencode config from `"opencode-plugin-otel"` to `"@devtheops/opencode-plugin-otel"`.
23+
* **BREAKING** — Package renamed to `@devtheops/opencode-plugin-otel`. Update your opencode config from `"opencode-plugin-otel"` to `"@devtheops/opencode-plugin-otel"`.
2524

2625
---
2726

2827
## [0.1.1] — 2026-03-11
2928

3029
### Fixed
3130

32-
- Release workflow now uses npm trusted publishing (OIDC) with Node 22.14.0 and creates a GitHub release with changelog notes and npm package link.
31+
* Release workflow now uses npm trusted publishing (OIDC) with Node 22.14.0 and creates a GitHub release with changelog notes and npm package link.
3332

3433
---
3534

3635
## [0.1.0] — 2026-03-11
3736

3837
### Added
3938

40-
- **Release workflow**`.github/workflows/release.yml` publishes to npm automatically when a `v*` tag is pushed, gated by typecheck and tests.
41-
- **`OPENCODE_OTLP_HEADERS`** — new env var for comma-separated `key=value` OTLP auth headers (e.g. `x-honeycomb-team=abc,x-tenant=org`). Copied to `OTEL_EXPORTER_OTLP_HEADERS` before the SDK initialises.
42-
- **`OPENCODE_RESOURCE_ATTRIBUTES`** — new env var for comma-separated `key=value` OTel resource attributes (e.g. `service.version=1.2.3,deployment.environment=production`). Copied to `OTEL_RESOURCE_ATTRIBUTES` before the SDK initialises.
43-
- JSDoc on all exported functions, types, and constants.
44-
- Regression tests covering `OTEL_*` passthrough behaviour — pre-existing values are preserved when `OPENCODE_*` vars are unset; `OPENCODE_*` vars overwrite when set.
45-
- README table of contents, usage examples for headers and resource attributes, and a security note advising that `OPENCODE_OTLP_HEADERS` may contain sensitive tokens and should not be committed to version control.
39+
* **Release workflow**`.github/workflows/release.yml` publishes to npm automatically when a `v*` tag is pushed, gated by typecheck and tests.
40+
* **`OPENCODE_OTLP_HEADERS`** — new env var for comma-separated `key=value` OTLP auth headers (e.g. `x-honeycomb-team=abc,x-tenant=org`). Copied to `OTEL_EXPORTER_OTLP_HEADERS` before the SDK initialises.
41+
* **`OPENCODE_RESOURCE_ATTRIBUTES`** — new env var for comma-separated `key=value` OTel resource attributes (e.g. `service.version=1.2.3,deployment.environment=production`). Copied to `OTEL_RESOURCE_ATTRIBUTES` before the SDK initialises.
42+
* JSDoc on all exported functions, types, and constants.
43+
* Regression tests covering `OTEL_*` passthrough behaviour — pre-existing values are preserved when `OPENCODE_*` vars are unset; `OPENCODE_*` vars overwrite when set.
44+
* README table of contents, usage examples for headers and resource attributes, and a security note advising that `OPENCODE_OTLP_HEADERS` may contain sensitive tokens and should not be committed to version control.
4645

4746
### Changed
4847

49-
- `package.json` `main`/`module` now point directly at `src/index.ts`; root `index.ts` re-export removed.
50-
- `files` field added to `package.json` — published package contains only `src/`, reducing install size.
51-
- All user-facing env vars are now consistently `OPENCODE_`-prefixed. `loadConfig` copies `OPENCODE_OTLP_HEADERS``OTEL_EXPORTER_OTLP_HEADERS` and `OPENCODE_RESOURCE_ATTRIBUTES``OTEL_RESOURCE_ATTRIBUTES` so the OTel SDK picks them up natively.
52-
- `parseEnvInt` now rejects partial numeric strings such as `"1.5"` or `"5000ms"`, returning the fallback instead of silently truncating.
48+
* `package.json` `main`/`module` now point directly at `src/index.ts`; root `index.ts` re-export removed.
49+
* `files` field added to `package.json` — published package contains only `src/`, reducing install size.
50+
* All user-facing env vars are now consistently `OPENCODE_`-prefixed. `loadConfig` copies `OPENCODE_OTLP_HEADERS``OTEL_EXPORTER_OTLP_HEADERS` and `OPENCODE_RESOURCE_ATTRIBUTES``OTEL_RESOURCE_ATTRIBUTES` so the OTel SDK picks them up natively.
51+
* `parseEnvInt` now rejects partial numeric strings such as `"1.5"` or `"5000ms"`, returning the fallback instead of silently truncating.
5352

5453
### Removed
5554

56-
- `parseHeaders` removed from `src/otel.ts` — the OTel SDK reads `OTEL_EXPORTER_OTLP_HEADERS` natively once `loadConfig` copies the value across.
57-
- Manual `release:patch` / `release:minor` / `release:major` npm scripts removed in favour of the tag-based CI workflow.
55+
* `parseHeaders` removed from `src/otel.ts` — the OTel SDK reads `OTEL_EXPORTER_OTLP_HEADERS` natively once `loadConfig` copies the value across.
56+
* Manual `release:patch` / `release:minor` / `release:major` npm scripts removed in favour of the tag-based CI workflow.

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ opencode loads TypeScript natively via Bun, so there is no build step required d
3535

3636
## Project structure
3737

38-
```
38+
```text
3939
src/
4040
├── index.ts — Plugin entrypoint, wires everything together
4141
├── types.ts — Shared types (Level, HandlerContext, Instruments, etc.)
@@ -65,7 +65,7 @@ Then set `OPENCODE_ENABLE_TELEMETRY=1` and start opencode. The collector will pr
6565

6666
This project follows [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). All commits must be structured as:
6767

68-
```
68+
```text
6969
<type>[optional scope]: <description>
7070
7171
[optional body]
@@ -91,15 +91,15 @@ This project follows [Conventional Commits](https://www.conventionalcommits.org/
9191

9292
Append `!` after the type or add a `BREAKING CHANGE:` footer:
9393

94-
```
94+
```text
9595
feat!: drop support for OTLP HTTP
9696
9797
BREAKING CHANGE: only OTLP/gRPC is supported going forward
9898
```
9999

100100
### Examples
101101

102-
```
102+
```text
103103
feat(handlers): add support for file.edited event
104104
fix(probe): handle malformed endpoint URL without throwing
105105
docs: update Datadog configuration example

README.md

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ An [opencode](https://opencode.ai) plugin that exports telemetry via OpenTelemet
99
- [Configuration](#configuration)
1010
- [Quick start](#quick-start)
1111
- [Headers and resource attributes](#headers-and-resource-attributes)
12+
- [Disabling specific metrics](#disabling-specific-metrics)
1213
- [Datadog example](#datadog-example)
1314
- [Honeycomb example](#honeycomb-example)
1415
- [Claude Code dashboard compatibility](#claude-code-dashboard-compatibility)
@@ -18,21 +19,28 @@ An [opencode](https://opencode.ai) plugin that exports telemetry via OpenTelemet
1819

1920
### Metrics
2021

21-
| Metric | Description |
22-
|--------|-------------|
23-
| `opencode.session.count` | Counter — incremented on each `session.created` event |
24-
| `opencode.token.usage` | Counter — per token type: `input`, `output`, `reasoning`, `cacheRead`, `cacheCreation` |
25-
| `opencode.cost.usage` | Counter — USD cost per completed assistant message |
26-
| `opencode.lines_of_code.count` | Counter — lines added/removed per `session.diff` event |
27-
| `opencode.commit.count` | Counter — git commits detected via bash tool |
28-
| `opencode.tool.duration` | Histogram — tool execution time in milliseconds |
22+
| Metric | Type | Description |
23+
|--------|------|-------------|
24+
| `opencode.session.count` | Counter | Incremented on each `session.created` event |
25+
| `opencode.token.usage` | Counter | Per token type: `input`, `output`, `reasoning`, `cacheRead`, `cacheCreation` |
26+
| `opencode.cost.usage` | Counter | USD cost per completed assistant message |
27+
| `opencode.lines_of_code.count` | Counter | Lines added/removed per `session.diff` event |
28+
| `opencode.commit.count` | Counter | Git commits detected via bash tool |
29+
| `opencode.tool.duration` | Histogram | Tool execution time in milliseconds |
30+
| `opencode.cache.count` | Counter | Cache activity per message: `type=cacheRead` or `type=cacheCreation` |
31+
| `opencode.session.duration` | Histogram | Session duration from created to idle in milliseconds |
32+
| `opencode.message.count` | Counter | Completed assistant messages per session |
33+
| `opencode.session.token.total` | Histogram | Total tokens consumed per session, recorded on idle |
34+
| `opencode.session.cost.total` | Histogram | Total cost per session in USD, recorded on idle |
35+
| `opencode.model.usage` | Counter | Messages per model and provider |
36+
| `opencode.retry.count` | Counter | API retries observed via `session.status` events |
2937

3038
### Log events
3139

3240
| Event | Description |
3341
|-------|-------------|
3442
| `session.created` | Session started |
35-
| `session.idle` | Session went idle |
43+
| `session.idle` | Session went idle (includes total tokens, cost, messages) |
3644
| `session.error` | Session error |
3745
| `user_prompt` | User sent a message (includes `prompt_length`, `model`, `agent`) |
3846
| `api_request` | Completed assistant message (tokens, cost, duration) |
@@ -72,9 +80,18 @@ All configuration is via environment variables. Set them in your shell profile (
7280
| `OPENCODE_OTLP_METRICS_INTERVAL` | `60000` | Metrics export interval in milliseconds |
7381
| `OPENCODE_OTLP_LOGS_INTERVAL` | `5000` | Logs export interval in milliseconds |
7482
| `OPENCODE_METRIC_PREFIX` | `opencode.` | Prefix for all metric names (e.g. set to `claude_code.` for Claude Code dashboard compatibility) |
75-
| `OPENCODE_OTLP_HEADERS` | _(unset)_ | Comma-separated `key=value` headers added to all OTLP exports. Example: `api-key=abc123,x-tenant=my-org`. **Keep out of version control — may contain sensitive auth tokens.** |
83+
| `OPENCODE_DISABLE_METRICS` | _(unset)_ | Comma-separated list of metric name suffixes to disable (e.g. `cache.count,session.duration`) |
84+
| `OPENCODE_OTLP_HEADERS` | _(unset)_ | Comma-separated `key=value` headers added to all OTLP exports. **Keep out of version control — may contain sensitive auth tokens.** |
7685
| `OPENCODE_RESOURCE_ATTRIBUTES` | _(unset)_ | Comma-separated `key=value` pairs merged into the OTel resource. Example: `service.version=1.2.3,deployment.environment=production` |
7786

87+
### Quick start
88+
89+
```bash
90+
export OPENCODE_ENABLE_TELEMETRY=1
91+
export OPENCODE_OTLP_ENDPOINT=http://localhost:4317
92+
opencode
93+
```
94+
7895
### Headers and resource attributes
7996

8097
```bash
@@ -87,14 +104,38 @@ export OPENCODE_RESOURCE_ATTRIBUTES="service.version=1.2.3,deployment.environmen
87104

88105
> **Security note:** `OPENCODE_OTLP_HEADERS` typically contains auth tokens. Set it in your shell profile (`~/.zshrc`, `~/.bashrc`) or a secrets manager — never commit it to version control or print it in CI logs.
89106
90-
### Quick start
107+
### Disabling specific metrics
108+
109+
Use `OPENCODE_DISABLE_METRICS` to suppress individual metrics. The value is a comma-separated list of metric name suffixes (without the prefix).
110+
111+
Disabling a metric only stops the counter/histogram from being incremented — the corresponding log events are still emitted.
91112

92113
```bash
93-
export OPENCODE_ENABLE_TELEMETRY=1
94-
export OPENCODE_OTLP_ENDPOINT=http://localhost:4317
95-
opencode
114+
# Disable a single metric
115+
export OPENCODE_DISABLE_METRICS="retry.count"
116+
117+
# Disable multiple metrics
118+
export OPENCODE_DISABLE_METRICS="cache.count,session.duration,session.token.total,session.cost.total,model.usage,retry.count,message.count"
119+
```
120+
121+
#### opencode-only metrics
122+
123+
The following metrics are specific to opencode and have no equivalent in Claude Code's built-in monitoring. If you are using a Claude Code dashboard and want to avoid cluttering it with opencode-only metrics, you can disable them:
124+
125+
```bash
126+
export OPENCODE_DISABLE_METRICS="cache.count,session.duration,session.token.total,session.cost.total,model.usage,retry.count,message.count"
96127
```
97128

129+
| Metric suffix | Why it's opencode-only |
130+
|---------------|------------------------|
131+
| `cache.count` | Tracks cache read/write activity as occurrence counts — not a Claude Code signal |
132+
| `session.duration` | Session wall-clock duration — not emitted by Claude Code |
133+
| `session.token.total` | Per-session token histogram — not emitted by Claude Code |
134+
| `session.cost.total` | Per-session cost histogram — not emitted by Claude Code |
135+
| `model.usage` | Per-model message counter — not emitted by Claude Code |
136+
| `retry.count` | API retry counter — not emitted by Claude Code |
137+
| `message.count` | Completed message counter — not emitted by Claude Code |
138+
98139
### Datadog example
99140

100141
```bash

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
{
2-
"name": "@devtheops/opencode-plugin-otel",
3-
"version": "0.3.0",
4-
"module": "src/index.ts",
5-
"main": "src/index.ts",
6-
"type": "module",
7-
"repository": {
8-
"type": "git",
9-
"url": "https://github.com/DEVtheOPS/opencode-plugin-otel.git"
10-
},
11-
"files": [
12-
"src/"
13-
],
14-
"devDependencies": {
15-
"@types/bun": "latest"
16-
},
17-
"scripts": {
18-
"typecheck": "tsc --noEmit"
19-
},
202
"dependencies": {
213
"@opencode-ai/plugin": "^1.2.23",
224
"@opencode-ai/sdk": "^1.2.23",
@@ -28,5 +10,23 @@
2810
"@opentelemetry/sdk-metrics": "^2.6.0",
2911
"@opentelemetry/semantic-conventions": "^1.40.0",
3012
"typescript": "^5.9.3"
31-
}
13+
},
14+
"devDependencies": {
15+
"@types/bun": "latest"
16+
},
17+
"files": [
18+
"src/"
19+
],
20+
"main": "src/index.ts",
21+
"module": "src/index.ts",
22+
"name": "@devtheops/opencode-plugin-otel",
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/DEVtheOPS/opencode-plugin-otel.git"
26+
},
27+
"scripts": {
28+
"typecheck": "tsc --noEmit"
29+
},
30+
"type": "module",
31+
"version": "0.3.0"
3232
}

release-please-config.json

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,45 @@
22
"bootstrap-sha": "b7bf72d1b8ee652acb714431087d24b475ca6460",
33
"packages": {
44
".": {
5-
"release-type": "node",
6-
"package-name": "@devtheops/opencode-plugin-otel",
75
"changelog-sections": [
8-
{ "type": "feat", "section": "Features" },
9-
{ "type": "fix", "section": "Bug Fixes" },
10-
{ "type": "perf", "section": "Performance Improvements" },
11-
{ "type": "refactor", "section": "Code Refactoring" },
12-
{ "type": "docs", "section": "Documentation" },
13-
{ "type": "ci", "section": "Continuous Integration", "hidden": true },
14-
{ "type": "build", "section": "Build System", "hidden": true },
15-
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true }
16-
]
6+
{
7+
"section": "Features",
8+
"type": "feat"
9+
},
10+
{
11+
"section": "Bug Fixes",
12+
"type": "fix"
13+
},
14+
{
15+
"section": "Performance Improvements",
16+
"type": "perf"
17+
},
18+
{
19+
"section": "Code Refactoring",
20+
"type": "refactor"
21+
},
22+
{
23+
"section": "Documentation",
24+
"type": "docs"
25+
},
26+
{
27+
"hidden": true,
28+
"section": "Continuous Integration",
29+
"type": "ci"
30+
},
31+
{
32+
"hidden": true,
33+
"section": "Build System",
34+
"type": "build"
35+
},
36+
{
37+
"hidden": true,
38+
"section": "Miscellaneous Chores",
39+
"type": "chore"
40+
}
41+
],
42+
"package-name": "@devtheops/opencode-plugin-otel",
43+
"release-type": "node"
1744
}
1845
}
1946
}

0 commit comments

Comments
 (0)