@grafana/faro-react-native-tracing 1.3.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/cjs/exporters/faroTraceExporter.utils.js +33 -0
- package/dist/cjs/exporters/faroTraceExporter.utils.js.map +1 -1
- package/dist/cjs/instrumentation.js +259 -44
- package/dist/cjs/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/getDefaultOTELInstrumentations.js +28 -20
- package/dist/cjs/instrumentations/getDefaultOTELInstrumentations.js.map +1 -1
- package/dist/cjs/instrumentations/instrumentationUtils.js +15 -0
- package/dist/cjs/instrumentations/instrumentationUtils.js.map +1 -1
- package/dist/cjs/processors/httpRequestMonitorSpanProcessor.js +27 -13
- package/dist/cjs/processors/httpRequestMonitorSpanProcessor.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/exporters/faroTraceExporter.utils.js +32 -0
- package/dist/esm/exporters/faroTraceExporter.utils.js.map +1 -1
- package/dist/esm/instrumentation.js +237 -43
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/instrumentations/getDefaultOTELInstrumentations.js +27 -21
- package/dist/esm/instrumentations/getDefaultOTELInstrumentations.js.map +1 -1
- package/dist/esm/instrumentations/instrumentationUtils.js +14 -0
- package/dist/esm/instrumentations/instrumentationUtils.js.map +1 -1
- package/dist/esm/processors/httpRequestMonitorSpanProcessor.js +27 -13
- package/dist/esm/processors/httpRequestMonitorSpanProcessor.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/instrumentation.d.ts +12 -4
- package/dist/types/instrumentations/getDefaultOTELInstrumentations.d.ts +2 -0
- package/dist/types/instrumentations/instrumentationUtils.d.ts +2 -0
- package/dist/types/types.d.ts +4 -0
- package/package.json +3 -3
- package/src/exporters/faroTraceExporter.events.test.ts +90 -0
- package/src/exporters/faroTraceExporter.utils.ts +32 -0
- package/src/httpSemantics.test.ts +300 -0
- package/src/instrumentation.test.ts +740 -0
- package/src/instrumentation.ts +299 -67
- package/src/instrumentations/getDefaultOTELInstrumentations.test.ts +28 -1
- package/src/instrumentations/getDefaultOTELInstrumentations.ts +41 -32
- package/src/instrumentations/instrumentationUtils.ts +13 -0
- package/src/processors/httpRequestMonitorSpanProcessor.ts +27 -15
- package/src/types.ts +4 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Context } from '@opentelemetry/api';
|
|
2
|
+
import { hrTimeToMilliseconds } from '@opentelemetry/core';
|
|
2
3
|
import type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
4
|
|
|
4
5
|
import {
|
|
@@ -7,6 +8,9 @@ import {
|
|
|
7
8
|
notifyHttpRequestStart,
|
|
8
9
|
} from '@grafana/faro-react-native';
|
|
9
10
|
|
|
11
|
+
import { captureFetchUserAction } from '../instrumentations/instrumentationUtils';
|
|
12
|
+
|
|
13
|
+
// Optional XHR instrumentation still emits these attributes.
|
|
10
14
|
const ATTR_HTTP_METHOD = 'http.method';
|
|
11
15
|
const ATTR_HTTP_STATUS_CODE = 'http.status_code';
|
|
12
16
|
const ATTR_HTTP_URL = 'http.url';
|
|
@@ -33,7 +37,16 @@ function getAttr(span: Span | ReadableSpan, key: string): string | undefined {
|
|
|
33
37
|
* Check if a span is an HTTP span (from FetchInstrumentation).
|
|
34
38
|
*/
|
|
35
39
|
function isHttpSpan(span: Span | ReadableSpan): boolean {
|
|
36
|
-
|
|
40
|
+
// url.full is shared by non-HTTP spans; stable HTTP spans identify their method at creation.
|
|
41
|
+
return getHttpMethod(span) != null || getAttr(span, ATTR_HTTP_URL) != null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getHttpUrl(span: Span | ReadableSpan): string | undefined {
|
|
45
|
+
return getAttr(span, 'url.full') ?? getAttr(span, ATTR_HTTP_URL);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getHttpMethod(span: Span | ReadableSpan): string | undefined {
|
|
49
|
+
return getAttr(span, 'http.request.method') ?? getAttr(span, ATTR_HTTP_METHOD);
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
/**
|
|
@@ -49,10 +62,15 @@ export class HttpRequestMonitorSpanProcessor implements SpanProcessor {
|
|
|
49
62
|
|
|
50
63
|
onStart(span: Span, parentContext: Context): void {
|
|
51
64
|
if (isHttpSpan(span)) {
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
// Capture before notifyStart changes Started to Halted. New requests while
|
|
66
|
+
// already Halted are not tracked by the controller and must not inherit it.
|
|
67
|
+
if (span.instrumentationScope.name === '@opentelemetry/instrumentation-fetch') {
|
|
68
|
+
captureFetchUserAction(span);
|
|
69
|
+
}
|
|
70
|
+
const url = getHttpUrl(span) ?? '';
|
|
71
|
+
const method = getHttpMethod(span) ?? 'GET';
|
|
54
72
|
const requestId = span.spanContext().spanId;
|
|
55
|
-
const startTimeMs =
|
|
73
|
+
const startTimeMs = hrTimeToMilliseconds(span.startTime);
|
|
56
74
|
|
|
57
75
|
const payload: HttpRequestMessagePayload = {
|
|
58
76
|
requestId,
|
|
@@ -68,19 +86,13 @@ export class HttpRequestMonitorSpanProcessor implements SpanProcessor {
|
|
|
68
86
|
|
|
69
87
|
onEnd(span: ReadableSpan): void {
|
|
70
88
|
if (isHttpSpan(span)) {
|
|
71
|
-
const url =
|
|
72
|
-
const method =
|
|
89
|
+
const url = getHttpUrl(span) ?? '';
|
|
90
|
+
const method = getHttpMethod(span) ?? 'GET';
|
|
73
91
|
const requestId = span.spanContext().spanId;
|
|
74
|
-
const statusAttr = getAttr(span, ATTR_HTTP_STATUS_CODE);
|
|
92
|
+
const statusAttr = getAttr(span, 'http.response.status_code') ?? getAttr(span, ATTR_HTTP_STATUS_CODE);
|
|
75
93
|
const status = statusAttr != null ? parseInt(statusAttr, 10) : undefined;
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
endTimeUnixNano?: number | bigint;
|
|
79
|
-
};
|
|
80
|
-
const startNs = spanWithTime.startTimeUnixNano;
|
|
81
|
-
const endNs = spanWithTime.endTimeUnixNano;
|
|
82
|
-
const startTimeMs = startNs != null && !Number.isNaN(Number(startNs)) ? Number(startNs) / 1_000_000 : Date.now();
|
|
83
|
-
const endTimeMs = endNs != null && !Number.isNaN(Number(endNs)) ? Number(endNs) / 1_000_000 : Date.now();
|
|
94
|
+
const startTimeMs = hrTimeToMilliseconds(span.startTime);
|
|
95
|
+
const endTimeMs = hrTimeToMilliseconds(span.endTime);
|
|
84
96
|
|
|
85
97
|
const payload: HttpRequestMessagePayload = {
|
|
86
98
|
requestId,
|
package/src/types.ts
CHANGED
|
@@ -17,6 +17,10 @@ export interface TracingInstrumentationOptions {
|
|
|
17
17
|
propagator?: TextMapPropagator;
|
|
18
18
|
contextManager?: ContextManager;
|
|
19
19
|
instrumentations?: InstrumentationOption[];
|
|
20
|
+
/**
|
|
21
|
+
* A caller-supplied processor. Faro removal flushes it so the tracing instrumentation can be re-added;
|
|
22
|
+
* TracingInstrumentation.shutdown() shuts it down and is terminal for that processor.
|
|
23
|
+
*/
|
|
20
24
|
spanProcessor?: SpanProcessor;
|
|
21
25
|
instrumentationOptions?: Omit<DefaultInstrumentationsOptions, 'ignoreUrls'>;
|
|
22
26
|
}
|