Skip to content

Commit 3c8b83a

Browse files
committed
refactor(web-transport): enforce fetch APM protection
Enforce use of the `fetch` function from the context, which is not affected by APM monkey patching.
1 parent 01154b4 commit 3c8b83a

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

src/transport/web-transport.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,12 @@ export class WebTransport implements Transport {
105105

106106
if (this.transport !== 'fetch') return;
107107

108-
// Keeping reference on current `window.fetch` function.
109-
WebTransport.originalFetch = fetch.bind(window);
108+
// Storing reference on original `fetch` function implementation as protection against APM lib monkey patching.
109+
WebTransport.originalFetch = WebTransport.getOriginalFetch();
110110

111111
// Check whether `fetch` has been monkey patched or not.
112-
if (this.isFetchMonkeyPatched()) {
113-
WebTransport.originalFetch = WebTransport.getOriginalFetch();
114-
112+
if (this.isFetchMonkeyPatched())
115113
logger.warn('WebTransport', "Native Web Fetch API 'fetch' function monkey patched.");
116-
117-
if (!this.isFetchMonkeyPatched(WebTransport.originalFetch)) {
118-
logger.info('WebTransport', "Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.");
119-
} else {
120-
logger.warn(
121-
'WebTransport',
122-
'Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation',
123-
);
124-
}
125-
}
126114
}
127115

128116
makeSendable(req: TransportRequest): [Promise<TransportResponse>, CancellationController | undefined] {

0 commit comments

Comments
 (0)