Skip to content

Commit e744798

Browse files
authored
refactor(instrumentation-xhr): fix eslint warnings (#5402)
1 parent 6508845 commit e744798

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

experimental/packages/opentelemetry-instrumentation-xml-http-request/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface XhrMem {
6363
entries: PerformanceResourceTiming[];
6464
};
6565
// callback to remove events from xhr once the span ends
66-
callbackToRemoveEvents?: Function;
66+
callbackToRemoveEvents?: () => void;
6767
}
6868

6969
export type PropagateTraceHeaderCorsUrl = string | RegExp;

experimental/packages/opentelemetry-instrumentation-xml-http-request/src/utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const DIAG_LOGGER = api.diag.createComponentLogger({
2424
'@opentelemetry/opentelemetry-instrumentation-xml-http-request/utils',
2525
});
2626

27+
function isDocument(value: unknown): value is Document {
28+
return typeof Document !== 'undefined' && value instanceof Document;
29+
}
30+
2731
/**
2832
* Helper function to determine payload content length for XHR requests
2933
* @param body
@@ -32,17 +36,17 @@ const DIAG_LOGGER = api.diag.createComponentLogger({
3236
export function getXHRBodyLength(
3337
body: Document | XMLHttpRequestBodyInit
3438
): number | undefined {
35-
if (typeof Document !== 'undefined' && body instanceof Document) {
39+
if (isDocument(body)) {
3640
return new XMLSerializer().serializeToString(document).length;
3741
}
42+
3843
// XMLHttpRequestBodyInit expands to the following:
39-
if (body instanceof Blob) {
40-
return body.size;
44+
if (typeof body === 'string') {
45+
return getByteLength(body);
4146
}
4247

43-
// ArrayBuffer | ArrayBufferView
44-
if ((body as any).byteLength !== undefined) {
45-
return (body as any).byteLength as number;
48+
if (body instanceof Blob) {
49+
return body.size;
4650
}
4751

4852
if (body instanceof FormData) {
@@ -53,8 +57,9 @@ export function getXHRBodyLength(
5357
return getByteLength(body.toString());
5458
}
5559

56-
if (typeof body === 'string') {
57-
return getByteLength(body);
60+
// ArrayBuffer | ArrayBufferView
61+
if (body.byteLength !== undefined) {
62+
return body.byteLength;
5863
}
5964

6065
DIAG_LOGGER.warn('unknown body type');

experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const XHR_TIMEOUT = 2000;
6666
const getData = (
6767
req: XMLHttpRequest,
6868
url: string,
69-
callbackAfterSend: Function,
69+
callbackAfterSend: () => void,
7070
async?: boolean
7171
) => {
7272
// eslint-disable-next-line no-async-promise-executor
@@ -101,7 +101,7 @@ const postData = (
101101
req: XMLHttpRequest,
102102
url: string,
103103
data: Document | XMLHttpRequestBodyInit,
104-
callbackAfterSend: Function,
104+
callbackAfterSend: () => void,
105105
async?: boolean
106106
) => {
107107
// eslint-disable-next-line no-async-promise-executor

0 commit comments

Comments
 (0)