Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ All configuration is via environment variables. Set them in your shell profile (
| Variable | Default | Description |
|----------|---------|-------------|
| `OPENCODE_ENABLE_TELEMETRY` | *(unset)* | Set to any non-empty value to enable the plugin |
| `OPENCODE_OTLP_ENDPOINT` | `http://localhost:4317` | OTLP collector endpoint. For `grpc`, use the collector host/port. For `http/protobuf` and `http/json`, use the base URL and the plugin will append `/v1/traces`, `/v1/metrics`, and `/v1/logs`. |
| `OPENCODE_OTLP_ENDPOINT` | `http://localhost:4317` | OTLP collector endpoint. Always include a URL scheme. For `grpc`, use the collector URL (for example `http://localhost:4317` or `grpc://collector:4317`). For `http/protobuf` and `http/json`, use the base URL and the plugin will append `/v1/traces`, `/v1/metrics`, and `/v1/logs`. |
| `OPENCODE_OTLP_PROTOCOL` | `grpc` | OTLP transport protocol: `grpc`, `http/protobuf`, or `http/json` |
| `OPENCODE_OTLP_METRICS_INTERVAL` | `60000` | Metrics export interval in milliseconds |
| `OPENCODE_OTLP_LOGS_INTERVAL` | `5000` | Logs export interval in milliseconds |
Expand All @@ -111,6 +111,8 @@ export OPENCODE_OTLP_PROTOCOL=grpc
opencode
```

Always set `OPENCODE_OTLP_ENDPOINT` to a full URL with a scheme. Scheme-less values like `localhost:4317` are rejected.

For `OPENCODE_OTLP_PROTOCOL=http/protobuf` or `OPENCODE_OTLP_PROTOCOL=http/json`, set `OPENCODE_OTLP_ENDPOINT` to the collector base URL rather than a per-signal path. The plugin expands it to `/v1/traces`, `/v1/metrics`, and `/v1/logs` automatically.

### Headers and resource attributes
Expand Down
1 change: 1 addition & 0 deletions src/probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ProbeResult = { ok: boolean; ms: number; error?: string }
export function parseEndpoint(endpoint: string): { host: string; port: number } | null {
try {
const url = new URL(endpoint)
if (!url.hostname) return null
const defaultPort = url.protocol === "http:" ? 80 : url.protocol === "https:" ? 443 : 4317
return { host: url.hostname, port: url.port ? parseInt(url.port, 10) : defaultPort }
} catch {
Expand Down
5 changes: 5 additions & 0 deletions tests/probe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ describe("parseEndpoint", () => {
test("returns null for invalid URLs", () => {
expect(parseEndpoint("not a url")).toBeNull()
})

test("returns null for URLs without a hostname", () => {
expect(parseEndpoint("localhost:4317")).toBeNull()
})
})

describe("probeEndpoint", () => {
test("returns error for malformed URL (no scheme)", async () => {
const result = await probeEndpoint("localhost:4317")
expect(result.ok).toBe(false)
expect(result.error).toContain("invalid endpoint URL")
expect(result.error).toBeDefined()
Comment on lines +35 to 36
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove redundant assertion.

Line 36 checking result.error is defined is redundant because line 35 already validates that result.error contains the string "invalid endpoint URL", which implicitly confirms it is defined.

🧹 Proposed fix to remove redundant assertion
     expect(result.error).toContain("invalid endpoint URL")
-    expect(result.error).toBeDefined()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(result.error).toContain("invalid endpoint URL")
expect(result.error).toBeDefined()
expect(result.error).toContain("invalid endpoint URL")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/probe.test.ts` around lines 35 - 36, Remove the redundant assertion
`expect(result.error).toBeDefined()` in tests/probe.test.ts; the existing
`expect(result.error).toContain("invalid endpoint URL")` already implies
`result.error` is defined, so delete the `expect(result.error).toBeDefined()`
line to avoid duplication.

})

Expand Down
Loading