Expose the resource lifecycle as a network-stack-agnostic entry point - #19
Open
Fiona2016 wants to merge 3 commits into
Open
Expose the resource lifecycle as a network-stack-agnostic entry point#19Fiona2016 wants to merge 3 commits into
Fiona2016 wants to merge 3 commits into
Conversation
The rcp interceptor and FlashcatHttp cover the two stacks the SDK can reach on its own. Anything else — axios routes through its own @ohos.net.http adapter, and custom clients exist — had only half of what it needs: getHeaders() returns the trace headers but no way to report the resource, and startResource() accepts the correlation attributes but produces no headers. Applications bridged the gap themselves and had to know that trace ids belong on a resource only for a sampled trace, that _dd.span_id is decimal while traceparent carries hex, and that a url without a host silently disables injection. startTracedResource() closes that gap: it registers the resource, applies the consent and first-party gates, and returns the headers to send. Pair it with stopTracedResource() for anything that got a response, whatever its status, and failTracedResource() only for a request that never got one. FlashcatHttp now builds on it rather than duplicating the logic, which is what makes this an extraction rather than a new surface. Extracting it dropped the merge of a pre-existing tracestate; TraceContext.mergeDatadogTracestate is now reachable so the wrapper keeps that behaviour, with a test pinning it.
Adds an axios integration to the demo built on the new entry point, plus an `axios` smoke scenario. The mock intake now also serves /e2e/* as a stand-in origin and records request headers, so an assertion can compare the traceparent that actually left the device against the resource the SDK reported for it. Verified on an emulator: both requests carry a traceparent, both arrive as resources with the full url and statuses 200 and 404, each _dd.span_id is the decimal form of the span in the header it sent, and no network error is emitted for the 404.
Host parsing now happens behind the first-party gate inside startTracedResource, which left FlashcatHttp.hostOf() without a caller outside its own test — it was a URL helper on a public class rather than part of what this package does, so it goes, and the test asserts hostOfUrl directly. The class comment restated the consent and first-party rules that now live in startTracedResource, which would drift, and pointed at a plan file that is not in the repository. It now says what the wrapper itself adds and defers the rest.
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.
Why
The rcp interceptor and
FlashcatHttpcover the two stacks the SDK can reach on its own. Anything else has only half of what it needs:getHeaders()returns trace headers but no way to report the resource, andstartResource()accepts the correlation attributes but produces no headers.axios is the case that surfaced this — it routes through its own
@ohos.net.httpadapter, so neither existing path observes it. Bridging the gap by hand means knowing that trace ids belong on a resource only for a sampled trace, that_dd.span_idis decimal whiletraceparentcarries hex, and that a url without a host silently disables injection. Each of those fails quietly: resources keep flowing while the trace correlation is wrong or missing.What
FlashcatTrace.startTracedResource(url, method, injectTrace?)registers the resource, applies the consent and first-party gates, and returns the headers to send. Close it withstopTracedResource()for anything that got a response — whatever its status — andfailTracedResource()only for a request that never got one.FlashcatHttpnow builds on the same entry point instead of duplicating the logic, which is what makes this an extraction rather than a new surface.Notes for review
setTrackNetworkRequests(true)like every other network integration.tracestate.TraceContext.mergeDatadogTracestateis now reachable so the wrapper keeps that behaviour, with a test pinning it.FlashcatHttp.hostOf()is removed. Host parsing moved behind the first-party gate and the method had no callers left; it was a URL helper on a public class rather than part of what this package does.Verification
traceparent, both arrive as resources with the full url and statuses 200 and 404, each_dd.span_idis the decimal form of the span in the header actually sent, and no network error is emitted for the 404.