fix: stabilize ObservabilityBuilder serviceNamespace test#243
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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/resourcesspy with a spy onObservabilityBuilder’s internalcreateResource()method. - Split the combined
serviceNamespaceassertion into two independent tests withbeforeEach/afterEach. - Mock
trace.getTracerProvider()to consistently force theNodeSDKcode path that invokescreateResource().
fpfp100
approved these changes
Apr 27, 2026
ajmfehr
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
observabilityBuilder-options.test.tsserviceNamespace test that failed because prior tests registered a global tracer provider, causingbuild()to skipcreateResource()resourceFromAttributesspy (which targeted the root@opentelemetry/resourceswhile the builder resolved a nested copy) with acreateResourceprototype spybeforeEach/afterEachlifecycle, mockinggetTracerProviderto force the NodeSDK code pathTest plan
observabilityBuilder-options.test.ts— all 4 tests pass (2 exporterOptions + 2 serviceNamespace)agentic-token-cache.test.tsTS error remains🤖 Generated with Claude Code