Skip to content

fix: cloud sdk - #451

Open
sjvans wants to merge 1 commit into
mainfrom
fix-cloud-sdk
Open

fix: cloud sdk#451
sjvans wants to merge 1 commit into
mainfrom
fix-cloud-sdk

Conversation

@sjvans

@sjvans sjvans commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

@sap-cloud-sdk/http-client may export executeHttpRequest and executeHttpRequestWithOrigin as non-writable / non-configurable properties. Direct assignment (cloudSDK.executeHttpRequest = wrap(...)) silently fails in that case.

Fix: use Object.defineProperty to patch both functions, with writable: true, configurable: true so the properties remain re-patchable (tests, re-instrumentation, future SDK versions).

Changes

  • lib/tracing/cloud_sdk.js — swap direct assignment for Object.defineProperty(..., { value, writable: true, configurable: true }); also reformats multi-line trace(...) calls for consistency.

Test plan

  • npx jest test/tracing-span-names.test.js test/tracing-attributes.test.js test/tracing.test.js — all pass
  • npm run lint — clean

@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
}
})
cloudSDK.executeHttpRequestWithOrigin = wrap(_executeWithOrigin, {
Object.defineProperty(cloudSDK, 'executeHttpRequest', { value: _executeHttpRequest })

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.

Bug: Object.defineProperty without writable: true or configurable: true defaults both to false, making the property non-writable and non-configurable. This is a stricter result than the original simple assignment, and will silently fail (or throw in strict mode) if any downstream code tries to reassign or redefine the property (e.g. in tests or repeated patching).

Suggested change
Object.defineProperty(cloudSDK, 'executeHttpRequest', { value: _executeHttpRequest })
Object.defineProperty(cloudSDK, 'executeHttpRequest', { value: _executeHttpRequest, writable: true, configurable: true })

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Comment thread lib/tracing/cloud_sdk.js Outdated
})
}
})
Object.defineProperty(cloudSDK, 'executeHttpRequestWithOrigin', { value: _executeHttpRequestWithOrigin })

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.

Bug: Same issue — writable and configurable default to false, making executeHttpRequestWithOrigin frozen on the module export.

Suggested change
Object.defineProperty(cloudSDK, 'executeHttpRequestWithOrigin', { value: _executeHttpRequestWithOrigin })
Object.defineProperty(cloudSDK, 'executeHttpRequestWithOrigin', { value: _executeHttpRequestWithOrigin, writable: true, configurable: true })

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

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

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