Skip to content

fix: stabilize ObservabilityBuilder serviceNamespace test#243

Merged
gwharris7 merged 1 commit intomainfrom
fix/observability-builder-namespace-test
Apr 28, 2026
Merged

fix: stabilize ObservabilityBuilder serviceNamespace test#243
gwharris7 merged 1 commit intomainfrom
fix/observability-builder-namespace-test

Conversation

@gwharris7
Copy link
Copy Markdown
Contributor

Summary

  • Fixed flaky observabilityBuilder-options.test.ts serviceNamespace test that failed because prior tests registered a global tracer provider, causing build() to skip createResource()
  • Replaced broken resourceFromAttributes spy (which targeted the root @opentelemetry/resources while the builder resolved a nested copy) with a createResource prototype spy
  • Split single combined test into two independent tests with proper beforeEach/afterEach lifecycle, mocking getTracerProvider to force the NodeSDK code path

Test plan

  • observabilityBuilder-options.test.ts — all 4 tests pass (2 exporterOptions + 2 serviceNamespace)
  • Full test suite — 1239 tests pass; only pre-existing agentic-token-cache.test.ts TS error remains

🤖 Generated with Claude Code

The serviceNamespace test was failing because prior tests in the same
file registered a global tracer provider, causing subsequent build()
calls to skip createResource(). Additionally, the resourceFromAttributes
spy targeted the root @opentelemetry/resources while the builder
resolved a nested copy from node_modules.

Fix by spying on createResource via prototype and mocking
getTracerProvider to force the NodeSDK code path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 27, 2026 21:58
@gwharris7 gwharris7 requested a review from a team as a code owner April 27, 2026 21:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Stabilizes the ObservabilityBuilder serviceNamespace unit tests by making them resilient to global OpenTelemetry tracer provider state that can be influenced by other tests in the suite.

Changes:

  • Replace a brittle @opentelemetry/resources spy with a spy on ObservabilityBuilder’s internal createResource() method.
  • Split the combined serviceNamespace assertion into two independent tests with beforeEach/afterEach.
  • Mock trace.getTracerProvider() to consistently force the NodeSDK code path that invokes createResource().

@gwharris7 gwharris7 merged commit 0faf81d into main Apr 28, 2026
11 checks passed
@gwharris7 gwharris7 deleted the fix/observability-builder-namespace-test branch April 28, 2026 02:04
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.

4 participants