Skip to content

Prefer explicit OTLP resource configuration - #6746

Merged
fubhy merged 2 commits into
mainfrom
issue-6742
Jul 29, 2026
Merged

Prefer explicit OTLP resource configuration#6746
fubhy merged 2 commits into
mainfrom
issue-6742

Conversation

@fubhy

@fubhy fubhy commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

  • prefer explicit serviceName and serviceVersion options over matching resource attributes and OTEL environment configuration
  • prefer all explicit resource attributes over OTEL_RESOURCE_ATTRIBUTES
  • preserve dedicated OTEL service variable precedence over matching attributes in OTEL_RESOURCE_ATTRIBUTES
  • document that applications should omit explicit resource identity when deployment operators should configure it
  • add regression coverage and a patch changeset

Testing

  • pnpm jsdocs && pnpm exec oxlint -f unix
  • nix shell nixpkgs#dprint --command dprint check
  • pnpm --filter effect test --run test/unstable/observability/OtlpResource.test.ts
  • pnpm check
  • pnpm exec docgen from packages/effect

Resolves #6742

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 29, 2026
@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 12a80f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@fubhy, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bd3c1f8c-3ee5-40f0-b059-cdb6a828321b

📥 Commits

Reviewing files that changed from the base of the PR and between 5f2ffb8 and 12a80f6.

📒 Files selected for processing (3)
  • .changeset/explicit-otel-service-identity.md
  • packages/effect/src/unstable/observability/OtlpResource.ts
  • packages/effect/test/unstable/observability/OtlpResource.test.ts
📝 Walkthrough

Walkthrough

OtlpResource.fromConfig now prioritizes explicit service identity options and attributes before OTEL environment values, with updated documentation, tests, and a patch changeset.

Changes

OTLP service identity

Layer / File(s) Summary
Update fromConfig precedence
packages/effect/src/unstable/observability/OtlpResource.ts
Documents configuration behavior and resolves explicit service names and versions before OTEL environment attributes and configuration fallbacks.
Validate precedence and release note
packages/effect/test/unstable/observability/OtlpResource.test.ts, .changeset/explicit-otel-service-identity.md
Tests explicit options, explicit service attributes, dedicated OTEL variables, resource attributes, and custom attributes; adds a patch release note.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant OtlpResource.fromConfig
  participant ExplicitOptions
  participant OTELEnvironment
  participant Config
  Caller->>OtlpResource.fromConfig: provide options and attributes
  OtlpResource.fromConfig->>ExplicitOptions: resolve explicit service identity
  OtlpResource.fromConfig->>OTELEnvironment: read OTEL service and resource attributes
  OtlpResource.fromConfig->>Config: read fallback service configuration
  OtlpResource.fromConfig-->>Caller: return OTLP resource
Loading

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR restores explicit serviceName/service.name precedence over ambient OTEL config and adds tests matching the linked issue's intent.
Out of Scope Changes check ✅ Passed The changes are limited to the precedence fix, matching tests, docs, and a changeset, with no unrelated scope evident.

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

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.31 KB 6.31 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 19.90 KB 19.90 KB 0.00 KB (0.00%)
differ.ts 20.03 KB 20.03 KB 0.00 KB (0.00%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.33 KB 7.33 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.86 KB 18.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.78 KB 28.78 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.09 KB 25.09 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.95 KB 12.95 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.10 KB 24.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.00 KB 19.00 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.59 KB 18.59 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.23 KB 22.23 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
schema.ts 18.12 KB 18.12 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

coderabbitai[bot]
coderabbitai Bot previously requested changes Jul 29, 2026

@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: 1

🤖 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 `@packages/effect/src/unstable/observability/OtlpResource.ts`:
- Around line 109-115: Validate the "service.name" and "service.version" values
read from options.attributes at runtime before using them in the serviceName and
serviceVersion resolution in make. Only accept values that are strings;
otherwise skip them and continue to the existing configuration or environment
fallbacks, preserving the current precedence for valid attributes.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 22fe7e3e-635d-452a-8b1d-1666332c2ecf

📥 Commits

Reviewing files that changed from the base of the PR and between 501a1a1 and 5f2ffb8.

📒 Files selected for processing (3)
  • .changeset/explicit-otel-service-identity.md
  • packages/effect/src/unstable/observability/OtlpResource.ts
  • packages/effect/test/unstable/observability/OtlpResource.test.ts

Comment on lines 109 to 115
?? options?.attributes?.["service.name"] as string | undefined
?? options?.serviceName
?? (yield* Config.schema(Schema.UndefinedOr(Schema.String), "OTEL_SERVICE_NAME"))
?? env?.["service.name"] as string | undefined
?? (yield* Config.string("OTEL_SERVICE_NAME"))

const serviceVersion = (yield* Config.schema(Schema.UndefinedOr(Schema.String), "OTEL_SERVICE_VERSION"))
?? env?.["service.version"] as string | undefined
const serviceVersion = options?.serviceVersion
?? options?.attributes?.["service.version"] as string | undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Validate service attributes before using them as strings.

options.attributes accepts unknown values, so these assertions do not validate runtime types. For example, { "service.name": 123 } is passed to make despite serviceName requiring a string, producing invalid resource metadata. Use a runtime string check or schema validation before applying these attributes.

Proposed fix
+  const serviceNameAttribute = options?.attributes?.["service.name"]
+  const serviceVersionAttribute = options?.attributes?.["service.version"]
+
   const serviceName = options?.serviceName
-    ?? options?.attributes?.["service.name"] as string | undefined
+    ?? (typeof serviceNameAttribute === "string" ? serviceNameAttribute : undefined)
...
   const serviceVersion = options?.serviceVersion
-    ?? options?.attributes?.["service.version"] as string | undefined
+    ?? (typeof serviceVersionAttribute === "string" ? serviceVersionAttribute : undefined)
📝 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
?? options?.attributes?.["service.name"] as string | undefined
?? options?.serviceName
?? (yield* Config.schema(Schema.UndefinedOr(Schema.String), "OTEL_SERVICE_NAME"))
?? env?.["service.name"] as string | undefined
?? (yield* Config.string("OTEL_SERVICE_NAME"))
const serviceVersion = (yield* Config.schema(Schema.UndefinedOr(Schema.String), "OTEL_SERVICE_VERSION"))
?? env?.["service.version"] as string | undefined
const serviceVersion = options?.serviceVersion
?? options?.attributes?.["service.version"] as string | undefined
const serviceNameAttribute = options?.attributes?.["service.name"]
const serviceVersionAttribute = options?.attributes?.["service.version"]
const serviceName = options?.serviceName
?? (typeof serviceNameAttribute === "string" ? serviceNameAttribute : undefined)
?? (yield* Config.schema(Schema.UndefinedOr(Schema.String), "OTEL_SERVICE_NAME"))
?? env?.["service.name"] as string | undefined
?? (yield* Config.string("OTEL_SERVICE_NAME"))
const serviceVersion = options?.serviceVersion
?? (typeof serviceVersionAttribute === "string" ? serviceVersionAttribute : undefined)
🤖 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 `@packages/effect/src/unstable/observability/OtlpResource.ts` around lines 109
- 115, Validate the "service.name" and "service.version" values read from
options.attributes at runtime before using them in the serviceName and
serviceVersion resolution in make. Only accept values that are strings;
otherwise skip them and continue to the existing configuration or environment
fallbacks, preserving the current precedence for valid attributes.

@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 29, 2026
@fubhy fubhy changed the title Prefer explicit OTLP service identity Prefer explicit OTLP resource configuration Jul 29, 2026
@fubhy
fubhy enabled auto-merge (squash) July 29, 2026 16:59
@fubhy
fubhy disabled auto-merge July 29, 2026 17:17
@fubhy
fubhy merged commit cedb01a into main Jul 29, 2026
16 checks passed
@fubhy
fubhy deleted the issue-6742 branch July 29, 2026 17:17
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in PR Backlog Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

OTLP resource precedence reversed in v4: ambient OTEL_SERVICE_NAME overrides explicit service name

2 participants