Skip to content

Commit 28e8527

Browse files
authored
SUMO-262842 Fix xhr instrumentation span check (#108)
* Fix xhr instrumentation span check * fixing Uts
1 parent cb3af81 commit 28e8527

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

e2e_test/demoApps/fixtures/angularjs.hash-second-batch.traces.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,30 @@
275275
"stringValue": "OK"
276276
}
277277
},
278+
{
279+
"key": "http.time_in_xhr_calls",
280+
"value": {
281+
"intValue": 19000064
282+
}
283+
},
284+
{
285+
"key": "http.time_to_first_xhr",
286+
"value": {
287+
"intValue": 0
288+
}
289+
},
290+
{
291+
"key": "http.time_to_last_xhr",
292+
"value": {
293+
"intValue": 19000064
294+
}
295+
},
296+
{
297+
"key": "http.time_to_xhr_processing_end",
298+
"value": {
299+
"intValue": 19000064
300+
}
301+
},
278302
{
279303
"key": "http.host",
280304
"value": {
@@ -580,6 +604,30 @@
580604
"value": {
581605
"stringValue": "http://localhost:52360/angularjs/index_hash.html#!/angularjs/planet/3"
582606
}
607+
},
608+
{
609+
"key": "http.time_in_xhr_calls",
610+
"value": {
611+
"intValue": 60000000
612+
}
613+
},
614+
{
615+
"key": "http.time_to_first_xhr",
616+
"value": {
617+
"intValue": 7000064
618+
}
619+
},
620+
{
621+
"key": "http.time_to_last_xhr",
622+
"value": {
623+
"intValue": 67000064
624+
}
625+
},
626+
{
627+
"key": "http.time_to_xhr_processing_end",
628+
"value": {
629+
"intValue": 67000064
630+
}
583631
}
584632
],
585633
"droppedAttributesCount": 0,

e2e_test/demoApps/fixtures/angularjs.historyapi-second-batch.traces.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,30 @@
275275
"stringValue": "OK"
276276
}
277277
},
278+
{
279+
"key": "http.time_in_xhr_calls",
280+
"value": {
281+
"intValue": 20000000
282+
}
283+
},
284+
{
285+
"key": "http.time_to_first_xhr",
286+
"value": {
287+
"intValue": 0
288+
}
289+
},
290+
{
291+
"key": "http.time_to_last_xhr",
292+
"value": {
293+
"intValue": 20000000
294+
}
295+
},
296+
{
297+
"key": "http.time_to_xhr_processing_end",
298+
"value": {
299+
"intValue": 20000000
300+
}
301+
},
278302
{
279303
"key": "http.host",
280304
"value": {
@@ -580,6 +604,30 @@
580604
"value": {
581605
"stringValue": "http://localhost:52375/angularjs/planet/3"
582606
}
607+
},
608+
{
609+
"key": "http.time_in_xhr_calls",
610+
"value": {
611+
"intValue": 54999808
612+
}
613+
},
614+
{
615+
"key": "http.time_to_first_xhr",
616+
"value": {
617+
"intValue": 6000128
618+
}
619+
},
620+
{
621+
"key": "http.time_to_last_xhr",
622+
"value": {
623+
"intValue": 60999936
624+
}
625+
},
626+
{
627+
"key": "http.time_to_xhr_processing_end",
628+
"value": {
629+
"intValue": 60999936
630+
}
583631
}
584632
],
585633
"droppedAttributesCount": 0,

e2e_test/demoApps/fixtures/react.hash-second-batch.traces.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,30 @@
482482
"stringValue": "OK"
483483
}
484484
},
485+
{
486+
"key": "http.time_in_xhr_calls",
487+
"value": {
488+
"intValue": 260000000
489+
}
490+
},
491+
{
492+
"key": "http.time_to_first_xhr",
493+
"value": {
494+
"intValue": 0
495+
}
496+
},
497+
{
498+
"key": "http.time_to_last_xhr",
499+
"value": {
500+
"intValue": 260000000
501+
}
502+
},
503+
{
504+
"key": "http.time_to_xhr_processing_end",
505+
"value": {
506+
"intValue": 260000000
507+
}
508+
},
485509
{
486510
"key": "http.host",
487511
"value": {

e2e_test/demoApps/fixtures/react.historyapi-second-batch.traces.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,30 @@
482482
"stringValue": "OK"
483483
}
484484
},
485+
{
486+
"key": "http.time_in_xhr_calls",
487+
"value": {
488+
"intValue": 227000064
489+
}
490+
},
491+
{
492+
"key": "http.time_to_first_xhr",
493+
"value": {
494+
"intValue": 0
495+
}
496+
},
497+
{
498+
"key": "http.time_to_last_xhr",
499+
"value": {
500+
"intValue": 227000064
501+
}
502+
},
503+
{
504+
"key": "http.time_to_xhr_processing_end",
505+
"value": {
506+
"intValue": 227000064
507+
}
508+
},
485509
{
486510
"key": "http.host",
487511
"value": {

src/sumologic-span-processor/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@ import { XHR_IS_ROOT_SPAN } from '../constants';
55
export const useWindow = typeof window === 'object' && window != null;
66
export const useDocument = typeof document === 'object' && document != null;
77

8+
const METHOD_NAMES = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'];
9+
10+
const isXhrInstrumentationSpan = (span: SdkTraceSpan) => {
11+
return (
12+
span.instrumentationLibrary.name ===
13+
'@opentelemetry/instrumentation-xml-http-request' &&
14+
METHOD_NAMES.includes(span.name)
15+
);
16+
};
17+
818
export const isXhrSpan = (span: SdkTraceSpan): boolean =>
9-
span.name.startsWith('HTTP ') && span.kind === SpanKind.CLIENT;
19+
(span.name.startsWith('HTTP ') || isXhrInstrumentationSpan(span)) &&
20+
span.kind === SpanKind.CLIENT;
1021

1122
export const isDocumentLoadSpan = (span: SdkTraceSpan): boolean =>
1223
span.name === 'documentLoad' &&

0 commit comments

Comments
 (0)