fix: trace Cloud SDK outbound requests (getter-only exports) - #451
Conversation
There was a problem hiding this comment.
The switch from direct assignment to Object.defineProperty is likely the intended fix (e.g., to patch a read-only exported property), but both calls are missing writable: true and configurable: true, which silently freezes those properties and can break re-patching or tests.
PR Bot Information
Version: 1.26.14
- Correlation ID:
6bf1b950-76e8-11f1-877b-299e7adc465b - LLM:
anthropic--claude-4.6-sonnet - Event Trigger:
pull_request.opened - File Content Strategy: Full file content
SummaryThe following content is AI-generated and provides a summary of the pull request: Fix Cloud SDK HTTP Request Tracing via
|
There was a problem hiding this comment.
The writable: true, configurable: true flags are already present in the current diff — my previous comments have been addressed. The code looks correct. The test file change simply sets process.env.cds_remote_native__fetch = 'true' at the top level, which is a sensible setup for OpenTelemetry HTTP instrumentation to intercept outbound calls during testing.
The PR is in good shape. Both Object.defineProperty calls already include writable: true and configurable: true as my earlier comments suggested, and the test file change correctly forces native fetch before any module is loaded. No further issues to raise.
PR Bot Information
Version: 1.29.14
- LLM:
anthropic--claude-4.6-sonnet - Event Trigger:
pull_request.ready_for_review - Experiment Variant:
control - File Content Strategy: Full file content
- Correlation ID:
b42aa6c0-8d20-11f1-8315-2d3e2e9f6717
Uses Object.defineProperty to patch executeHttpRequest and executeHttpRequestWithOrigin on the @sap-cloud-sdk/http-client module exports, which may be non-writable. Adds writable: true, configurable: true so the properties remain re-patchable (e.g. by tests or re-instrumentation).
Add end-to-end tests for both outbound remote-call tracing paths: - cloud sdk (default when @sap-cloud-sdk/http-client is installed): asserts the cloud_sdk.js wrapper produces a @cap-js/telemetry CLIENT span carrying sap.btp.destination - native fetch (cds.env.remote.native_fetch): asserts the span comes from @opentelemetry/instrumentation-undici with http.*/url.*/server.* attributes Both make a real HTTP call to a local http.createServer. Gated on cds >= 9. Also drop the 'REVISIT: unverified!' note in cloud_sdk.js (verified working via Object.defineProperty over the getter-only exports) and fix a comment that wrongly credited instrumentation-http for native fetch (it is undici).
The cloud-sdk tracing tests need @sap-cloud-sdk/http-client resolvable at the package root. It was only declared in test/bookshop/package.json, which CI does not install (CI runs root `npm i` only) — so lib/tracing/cloud_sdk.js's require.resolve guard bailed, the wrapper never attached, and tracing-remote-cloudsdk.test.js failed on CI (passed locally only due to a hoisted copy). http-client pulls connectivity + resilience transitively. Lockfile resolved against the public npm registry (@sap/xssec 4.13.3), not the SAP-internal registry, so public CI runners can fetch every dep.
Problem
Cloud SDK v4 exposes
executeHttpRequest/executeHttpRequestWithOriginas getter-only properties. The plugin patched them with plain assignment, which silently fails on a getter — so the Cloud SDK outbound path (CAP's default when@sap-cloud-sdk/http-clientis installed) produced no CLIENT span and nosap.btp.destination.Fix
Patch via
Object.defineProperty(cloudSDK, name, { value, writable: true, configurable: true })—writable/configurablekeep the exports re-patchable. Verified the wrapper now fires end-to-end.Tests
test/tracing-remote-cloudsdk.test.js— Cloud SDK path: asserts a@cap-js/telemetryCLIENT span withsap.btp.destination, and no undici span.test/tracing-remote-native.test.js— native-fetch path: asserts the span comes from@opentelemetry/instrumentation-undici(not-http) withhttp.*/url.*/server.*attributes.Both drive a real local HTTP call; gated on
cds.version >= 9. Changelog updated.