Fix #2374: Make getResourceName() consistent with hasResourceName()#3244
Fix #2374: Make getResourceName() consistent with hasResourceName()#3244mariusc83 wants to merge 3 commits into
Conversation
Root cause: DDSpanContext.getResourceName() only checked the internal resourceName field, falling back to operationName. Unlike hasResourceName(), it did not check the resource.name tag in unsafeTags. Changes: - Make getResourceName() check getTag(DDTags.RESOURCE_NAME) as fallback - Remove TODO comment that flagged this inconsistency - Add tests for tag-based resource name resolution Tests: 2 unit Performance: SUCCESS
Add two integration tests that exercise the full tracer chain (builder → TagInterceptor → DDSpanContext → getResourceName) to catch regressions in resource.name tag handling. Tests: - Resource name set via builder withTag before start() - Resource name set via setTag after start()
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3244 +/- ##
===========================================
+ Coverage 71.40% 71.49% +0.09%
===========================================
Files 938 938
Lines 34667 34674 +7
Branches 5874 5877 +3
===========================================
+ Hits 24752 24788 +36
+ Misses 8265 8233 -32
- Partials 1650 1653 +3
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
Impact analysis identified that SamplingRule.TraceSamplingRule.matches() uses getResourceName() for pattern matching. Without this test, a regression in the tag fallback could silently change sampling decisions. The test verifies that a sampling rule targeting a specific resource name correctly matches when the name comes from the resource.name tag fallback path (not the internal resourceName field).
|
@codex review |
| // TODO this logic is inconsistent with hasResourceName | ||
| public CharSequence getResourceName() { | ||
| return isResourceNameSet() ? resourceName : operationName; | ||
| if (isResourceNameSet()) { |
There was a problem hiding this comment.
Changing the behavior of existing method can skew existing dashboards/monitors. I'm not sure we should do this for the minor release.
There was a problem hiding this comment.
Totally agree and that was my worry too. Actually Claude picked this up also during the fixing session and mentioned it. That's a decision on your end. Choose to keep it as it is or take the risk and merge it. This is a hard one as there's definitely a problem there of inconsistency which can have repercussions later. Either you take the bullet now and fix it or you postpone it and face it later.
There was a problem hiding this comment.
Are you sure this change ever needed? According to TagInterceptor logic it would call setResource in case if customer tries to set DDTags.RESOURCE_NAME. So Basically seems like the opposite logic might make more sense - removing hasTag(DDTags.RESOURCE_NAME) from the hasResourceName method. WDYT?
There was a problem hiding this comment.
I think you have more context than me on this one but from what I see it makes sense what you are saying. But not matter what we decide is going to change the API functionality so it will be some sort of regression. In the same time if we decide to keep it as it is, it means that we acknowledge that there's an issue and we accept it. I let you guys decide and I will apply the changes if needed.
There was a problem hiding this comment.
My opinion - is to add TODO comment, with RUM-13454 and link to this PR and close for now. With the next major release - we gonna fix this
There was a problem hiding this comment.
Done — I've opened a separate PR (#3252) that updates the TODO comment with RUM-13454 and a link to this PR, deferring the fix to the next major release as suggested. Will close this PR.
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Issue
Fixes #2374: Span resource name set with tag is not used
GitHub Issue: #2374
Root Cause Analysis
DDSpanContext.getResourceName()only checked the internalresourceNamefield, falling back tooperationName. UnlikehasResourceName(), it did not check theresource.nametag inunsafeTags. This caused an inconsistency wherehasResourceName()returnedtruebutgetResourceName()returned the operation name instead of the tag-set resource name — specifically when theresource.nametag was stored directly in the tags map (e.g., when the RESOURCE_NAME rule flag in TagInterceptor is disabled).A TODO comment at the method explicitly flagged this inconsistency.
Changes
Make
getResourceName()checkgetTag(DDTags.RESOURCE_NAME)as a fallback before returningoperationName, matching the logic inhasResourceName(). Remove the TODO comment.Files Changed
DDSpanContext.javagetResourceName()to check tag fallbackDDSpanContextTest.ktImpact Analysis
An architectural impact analysis was performed after the initial fix to evaluate the blast radius:
Caller Map
SamplingRule.TraceSamplingRule.matches()CoreTracerSpanToSpanEventMapperSpanEvent.resourceTraceStructureWriter.NodeDatadogSpanAdapterAll production callers (network instrumentation, OkHttp interceptor) explicitly write to
.resourceNamebefore reading, so the fallback path is only hit when no explicit resource name is set.Thread Safety
The fix adds a
getTag()call (which takessynchronized(unsafeTags)) in the fallback path. The old code was lock-free. Risk is low because:getResourceName()is called once per span at serialization time, not in loopsresourceNamefield is not setConsistency Scan
Found a latent similar pattern in
getServiceName()(only checks internal field, same RuleFlags conditional processing). Not a bug today since nohasServiceName()method exists, but noted for future awareness.Test Coverage
withTagflow,setTagafter start)