Skip to content

Conversation

@js62789
Copy link

@js62789 js62789 commented Dec 23, 2025

Which problem is this PR solving?

Our team is using DataDome for bot detection. They have set us up with a custom Captcha script which overrides the global Request constructor. We're going to see if they can eliminate this code smell, but in the case where they can't, I believe it would be valuable to improve the Request detection with this duck-typing helper instead. This will prevent requests to incorrect URLs when a patched request instance is provided to fetch().

Short description of the changes

  • Use structural Request type guard instead of relying on global Request identity
  • Add test coverage for overwritten global Request constructor

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added a test with global Request overwritten
  • All tests passed with rpm run test

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added

@js62789 js62789 requested a review from a team as a code owner December 23, 2025 16:56
@linux-foundation-easycla
Copy link

CLA Not Signed

namespace: '@opentelemetry/opentelemetry-instrumentation-fetch/utils',
});

export function isRequest(value: unknown): value is Request {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to document that we duck-type for Request in this instrumentation as a result of this PR just to make it clear what the risk (even if minimal) of false positives.

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.

2 participants