Skip to content

feat: honor OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES - #28

Merged
hassiebp merged 1 commit into
mainfrom
feat/otel-resource-attributes
Sep 14, 2026
Merged

hassiebp merged 1 commit into
mainfrom
feat/otel-resource-attributes

Conversation

@milanagm

@milanagm milanagm commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #27.
Fixes LFE-16130

createRuntime() built its NodeTracerProvider without a resource, so a bare provider fell back to defaultResource() only and read neither OTEL_SERVICE_NAME nor OTEL_RESOURCE_ATTRIBUTES. Anything a user set through those standard variables was silently dropped.

The package.json line is not optional

@opentelemetry/resources was already in the tree, but only transitively — under pnpm it is not hoisted, so node_modules/@opentelemetry/ holds just api and sdk-trace-node. pi installs extensions with npm --legacy-peer-deps, which does not install peers. This is the same failure mode that made 0.1.0 unloadable on a fresh install (#17), so the dependency is declared explicitly. Note that no test covers that install path yet — tracked separately in LFE-16130.

Verification

  • 64/64 tests green, typecheck clean.
  • Two new integration tests. The main one is red without the fix (actual: 'unknown_service:node', expected: 'pi-agent'); the second pins that the default resource is unchanged when the variables are unset, so it passes either way by design.
  • runPi now clears OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES alongside the LANGFUSE_* vars, so a developer's own environment cannot leak into a run. Confirmed by running the suite with both exported.
  • Verified live against Langfuse Cloud with a paired before/after run

Behavior worth knowing when reviewing

Resource attributes are not purely inert once they reach Langfuse:

  • service.version populates the first-class version field on the trace and every observation (visible in the table above).
  • deployment.environment / deployment.environment.name set the Langfuse environment when no Langfuse environment is configured. LANGFUSE_TRACING_ENVIRONMENT — and the environment key in langfuse.json — both take precedence, because @langfuse/otel stamps a langfuse.environment span attribute and extractEnvironment prefers span attributes over resource attributes. Invalid values coerce to default server-side rather than being rejected.
  • A single malformed entry makes the OTel envDetector discard the entire OTEL_RESOURCE_ATTRIBUTES value, reported only via diag.debug, which nothing here enables.

@milanagm
milanagm requested a review from hassiebp September 9, 2026 17:03
@hassiebp
hassiebp merged commit 5163caa into main Sep 14, 2026
13 checks passed
@hassiebp
hassiebp deleted the feat/otel-resource-attributes branch September 14, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Honor OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES

2 participants