Skip to content

fix: trace Cloud SDK outbound requests (getter-only exports) - #451

Merged
sjvans merged 4 commits into
developfrom
fix-cloud-sdk
Aug 7, 2026
Merged

fix: trace Cloud SDK outbound requests (getter-only exports)#451
sjvans merged 4 commits into
developfrom
fix-cloud-sdk

Conversation

@sjvans

@sjvans sjvans commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Cloud SDK v4 exposes executeHttpRequest / executeHttpRequestWithOrigin as 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-client is installed) produced no CLIENT span and no sap.btp.destination.

Fix

Patch via Object.defineProperty(cloudSDK, name, { value, writable: true, configurable: true })writable/configurable keep 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/telemetry CLIENT span with sap.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) with http.*/url.*/server.* attributes.

Both drive a real local HTTP call; gated on cds.version >= 9. Changelog updated.

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread lib/tracing/cloud_sdk.js Outdated
Comment thread lib/tracing/cloud_sdk.js Outdated
@sjvans
sjvans marked this pull request as ready for review July 31, 2026 20:45
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Fix Cloud SDK HTTP Request Tracing via Object.defineProperty

Bug Fix

🐛 Fixes an issue where Cloud SDK HTTP client functions were not being properly patched for tracing. Direct property assignment (cloudSDK.executeHttpRequest = ...) fails when the property is non-writable or non-configurable on the module exports. The fix uses Object.defineProperty to correctly override these functions, ensuring tracing wrappers are applied reliably.

Changes

  • lib/tracing/cloud_sdk.js: Replaced direct property assignment with Object.defineProperty (with writable: true, configurable: true) for both executeHttpRequest and executeHttpRequestWithOrigin. Wrapped functions are now stored in intermediate variables before being applied via Object.defineProperty. Also includes minor code style cleanup, reformatting multi-line trace(...) calls for consistency.
  • test/tracing-attributes.test.js: Added process.env.cds_remote_native__fetch = 'true' at the top to force native fetch usage in CDS OData Query, allowing @opentelemetry/instrumentation-http to properly intercept outbound HTTP calls during tests.

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.29.14

  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt
  • Event Trigger: pull_request.ready_for_review
  • File Content Strategy: Full file content
  • Output Template: Default Template
  • Correlation ID: b42aa6c0-8d20-11f1-8315-2d3e2e9f6717

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@sjvans
sjvans changed the base branch from main to develop August 7, 2026 07:28
@sjvans sjvans changed the title fix: cloud sdk fix: trace Cloud SDK outbound requests (getter-only exports) Aug 7, 2026
sjvans and others added 3 commits August 7, 2026 10:54
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.
@sjvans
sjvans merged commit 29d0028 into develop Aug 7, 2026
8 checks passed
@sjvans
sjvans deleted the fix-cloud-sdk branch August 7, 2026 12:54
@sjvans sjvans mentioned this pull request Aug 7, 2026
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