Skip to content

Expose the resource lifecycle as a network-stack-agnostic entry point - #19

Open
Fiona2016 wants to merge 3 commits into
mainfrom
feat/traced-resource-primitive
Open

Expose the resource lifecycle as a network-stack-agnostic entry point#19
Fiona2016 wants to merge 3 commits into
mainfrom
feat/traced-resource-primitive

Conversation

@Fiona2016

Copy link
Copy Markdown
Collaborator

Why

The rcp interceptor and FlashcatHttp cover 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, and startResource() accepts the correlation attributes but produces no headers.

axios is the case that surfaced this — it routes through its own @ohos.net.http adapter, 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_id is decimal while traceparent carries 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 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 the same entry point instead of duplicating the logic, which is what makes this an extraction rather than a new surface.

Notes for review

  • Resources travel the existing bus path, so this requires setTrackNetworkRequests(true) like every other network integration.
  • Extracting the logic dropped the merge of a pre-existing tracestate. TraceContext.mergeDatadogTracestate is now reachable so the wrapper keeps that behaviour, with a test pinning it.
  • Breaking: 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

  • 130 unit tests pass.
  • Emulator end-to-end through the demo's axios integration: 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 actually sent, and no network error is emitted for the 404.

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.
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.

1 participant