Skip to content

feat(config): allow plugin configuration via second options parameter#65

Merged
dialupdisaster merged 3 commits into
DEVtheOPS:mainfrom
cbrachem:feat/plugin-tuple-options
Jul 4, 2026
Merged

feat(config): allow plugin configuration via second options parameter#65
dialupdisaster merged 3 commits into
DEVtheOPS:mainfrom
cbrachem:feat/plugin-tuple-options

Conversation

@cbrachem

@cbrachem cbrachem commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description

Since March 2026, Opencode has supported passing options to plugins as a second parameter. This change allows resolving plugin configuration from opencode's plugin tuple form (["opencode-plugin-otel", { ... }]) in addition to OPENCODE_* env vars. Precedence is option > env > default, so existing env-only setups are unchanged and loadConfig() still works with no arguments.

loadConfig now accepts an OtelPluginOptions object (keys 1:1 with PluginConfig) and validates every field at runtime, so malformed JSON options fall through to env/default. The entrypoint threads opencode's second factory argument through to loadConfig.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Chore (dependency updates, etc.)

Checklist

  • I have read the CONTRIBUTING.md document
  • My code follows the style guidelines of this project (I hope so; if not, please point out what should be different)
  • bun run lint passes with no errors
  • bun run check:jsdoc-coverage passes with no errors
  • bun run typecheck passes with no errors
  • bun test passes with no errors
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • My commits follow the Conventional Commits specification

Related issues

none

Additional context

none

Summary by CodeRabbit

  • New Features

    • Added inline OTEL plugin options via opencode.json tuple syntax, which override matching environment variables and built-in defaults.
    • Option-based configuration now drives endpoint/protocol, enablement, intervals, OTLP headers and resource attributes, metrics temporality, and disabled metrics/traces (including all expansion for trace types).
  • Documentation

    • Updated README and AGENTS.md with tuple examples, precedence rules, option-to-env mappings, data-shape notes, and a security reminder to avoid sensitive inline values.
  • Tests

    • Expanded coverage for option precedence, validation/fallback behavior (including invalid inputs), environment propagation, and safe handling of null.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9d7a4641-f35a-46c1-b6d5-abfe325b1d3f

📥 Commits

Reviewing files that changed from the base of the PR and between ceb79a4 and 11306b5.

📒 Files selected for processing (1)
  • README.md
✅ Files skipped from review due to trivial changes (1)
  • README.md

📝 Walkthrough

Walkthrough

loadConfig now accepts inline plugin options and resolves configuration in option, environment, then default order. The plugin entrypoint forwards options, tests cover precedence and propagation, and the README and AGENTS notes document the new tuple form.

Changes

OtelPluginOptions config resolution

Layer / File(s) Summary
OtelPluginOptions type and pick helpers
src/config.ts
Exports OtelPluginOptions with optional override fields and adds typed helpers for resolving string, boolean, integer, and list values.
loadConfig option/env precedence implementation
src/config.ts
Adds list normalization and disabled-trace expansion utilities, then rewrites loadConfig to resolve fields from options, env vars, and defaults while setting OTEL exporter env vars and computing disabled metrics/traces.
OtelPlugin entrypoint wiring
src/index.ts
Updates the plugin handler to accept a second options argument and pass it into loadConfig.
loadConfig options test suite
tests/config.test.ts
Adds option-precedence and propagation tests for config fields, interval handling, temporality, disabled metrics/traces, and the no-options regression case.
Plugin options documentation
README.md, AGENTS.md
Documents the inline plugin tuple form, precedence rules, option-to-env mappings, and field-name matching guidance.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: dialupdisaster

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a second options parameter for plugin configuration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/config.test.ts (1)

306-419: ⚡ Quick win

Add regression tests for malformed options object and enum fallback behavior.

This suite doesn’t currently assert two critical paths: loadConfig(null) safety and invalid protocol/metricsTemporality option values falling through to env vars.

Suggested test additions
+  test("null options object does not throw and falls back to env/defaults", () => {
+    process.env["OPENCODE_OTLP_ENDPOINT"] = "http://env:4317"
+    const cfg = loadConfig(null as unknown as Parameters<typeof loadConfig>[0])
+    expect(cfg.endpoint).toBe("http://env:4317")
+  })
+
+  test("invalid option protocol falls back to env protocol", () => {
+    process.env["OPENCODE_OTLP_PROTOCOL"] = "http/json"
+    const cfg = loadConfig({ protocol: "bad" as unknown as "grpc" })
+    expect(cfg.protocol).toBe("http/json")
+  })
+
+  test("invalid option metricsTemporality falls back to env temporality", () => {
+    process.env["OPENCODE_OTLP_METRICS_TEMPORALITY"] = "delta"
+    const cfg = loadConfig({ metricsTemporality: "bad" as unknown as "delta" })
+    expect(cfg.metricsTemporality).toBe("delta")
+  })
🤖 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/config.test.ts` around lines 306 - 419, The "loadConfig options" test
suite is missing coverage for two critical scenarios. Add a new test case within
this describe block to verify that loadConfig(null) handles null input safely
without throwing errors. Additionally, add test cases that verify invalid
protocol option values and invalid metricsTemporality option values (non-enum
strings) properly fall back to environment variables or defaults, similar to how
the existing "non-number option interval is ignored" test validates invalid
interval inputs. These tests ensure the loadConfig function is resilient to
unexpected option values.
🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/config.ts`:
- Around line 120-122: The issue is that `pickString` extracts values from
`options.metricsTemporality` and `options.protocol` without validation, causing
invalid option values to bypass the environment variable fallback. When an
option is provided but malformed, it should fall through to the environment
variable instead of using the default. Fix this by validating the option value
first before using it; only if the option value is missing or invalid should you
fall back to the environment variable, and only if that's also missing or
invalid should you use the default. Apply this pattern to both the `protocol`
assignment and the `metricsTemporality` assignment, ensuring proper precedence:
validated option → validated env var → default.
- Around line 114-121: The loadConfig function does not guard against cases
where the options parameter might be null or a non-object value, causing runtime
errors when attempting to access properties like options.otlpHeaders,
options.otlpHeadersHelper, options.resourceAttributes, options.traceparent,
options.tracestate, options.metricsTemporality, and options.protocol. Add a
guard at the start of the loadConfig function to ensure options is a valid
object before attempting to access its properties, falling back to the empty
object default if it is null, undefined, or not an object.

---

Nitpick comments:
In `@tests/config.test.ts`:
- Around line 306-419: The "loadConfig options" test suite is missing coverage
for two critical scenarios. Add a new test case within this describe block to
verify that loadConfig(null) handles null input safely without throwing errors.
Additionally, add test cases that verify invalid protocol option values and
invalid metricsTemporality option values (non-enum strings) properly fall back
to environment variables or defaults, similar to how the existing "non-number
option interval is ignored" test validates invalid interval inputs. These tests
ensure the loadConfig function is resilient to unexpected option values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7646e227-8b41-4d79-9af4-be6b513d5aca

📥 Commits

Reviewing files that changed from the base of the PR and between 7153352 and 5a02128.

📒 Files selected for processing (5)
  • AGENTS.md
  • README.md
  • src/config.ts
  • src/index.ts
  • tests/config.test.ts

Comment thread src/config.ts Outdated
Comment thread src/config.ts Outdated
@cbrachem cbrachem changed the title Allow plugin configuration via second options parameter feat(config): allow plugin configuration via second options parameter Jun 17, 2026
@dialupdisaster dialupdisaster added the enhancement New feature or request label Jun 25, 2026
@dialupdisaster

Copy link
Copy Markdown
Contributor

@cbrachem can you rebase on master and fix the conflicts?

cbrachem added 2 commits July 3, 2026 14:24
Resolve plugin configuration from opencode's plugin tuple form
(["opencode-plugin-otel", { ... }]) in addition to OPENCODE_* env vars.
Precedence is option > env > default, so existing env-only setups are
unchanged and loadConfig() still works with no arguments.

loadConfig now accepts an OtelPluginOptions object (keys 1:1 with
PluginConfig) and validates every field at runtime, so malformed JSON
options fall through to env/default. The entrypoint threads opencode's
second factory argument through to loadConfig.
@cbrachem cbrachem force-pushed the feat/plugin-tuple-options branch from d880778 to ceb79a4 Compare July 3, 2026 13:06
@cbrachem

cbrachem commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@cbrachem can you rebase on master and fix the conflicts?

@dialupdisaster Sure. Done. Sorry about the delay, another thing came up.

@dialupdisaster

dialupdisaster commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Small docs gap: the new plugin options table appears to be missing spanAttributesOPENCODE_SPAN_ATTRIBUTES. I checked the rest of OtelPluginOptions against the table, and the other option keys seem to be covered.

This was added between when you created this PR and now.

Comment thread README.md
Co-authored-by: Marc <157699+dialupdisaster@users.noreply.github.com>
@cbrachem

cbrachem commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Small docs gap: the new plugin options table appears to be missing spanAttributesOPENCODE_SPAN_ATTRIBUTES. I checked the rest of OtelPluginOptions against the table, and the other option keys seem to be covered.

This was added between when you created this PR and now.

Yeah I noticed; I added the option in code but forgot about the README when fixing the merge conflict. Thanks!

@dialupdisaster

Copy link
Copy Markdown
Contributor

Thanks for the contribution! I really like this config method better than environment variables, lol

@dialupdisaster dialupdisaster merged commit f88839a into DEVtheOPS:main Jul 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants