@grafana/faro-web-tracing 2.3.0 → 2.4.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/dist/bundle/faro-web-tracing.iife.js +1 -1
- package/dist/cjs/faroMetaAttributesSpanProcessor.js +15 -16
- package/dist/cjs/faroMetaAttributesSpanProcessor.js.map +1 -1
- package/dist/cjs/faroTraceExporter.js +12 -13
- package/dist/cjs/faroTraceExporter.js.map +1 -1
- package/dist/cjs/faroTraceExporter.utils.js +18 -26
- package/dist/cjs/faroTraceExporter.utils.js.map +1 -1
- package/dist/cjs/faroUserActionSpanProcessor.js +14 -15
- package/dist/cjs/faroUserActionSpanProcessor.js.map +1 -1
- package/dist/cjs/faroXhrInstrumentation.js +17 -41
- package/dist/cjs/faroXhrInstrumentation.js.map +1 -1
- package/dist/cjs/getDefaultOTELInstrumentations.js +12 -24
- package/dist/cjs/getDefaultOTELInstrumentations.js.map +1 -1
- package/dist/cjs/instrumentation.js +38 -58
- package/dist/cjs/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentationUtils.js +6 -6
- package/dist/cjs/instrumentationUtils.js.map +1 -1
- package/dist/cjs/sampler.js +4 -5
- package/dist/cjs/sampler.js.map +1 -1
- package/package.json +12 -9
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sendFaroEvents = sendFaroEvents;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function sendFaroEvents(resourceSpans, api) {
|
|
4
|
+
const internal_types_1 = require("@opentelemetry/otlp-transformer/build/src/trace/internal-types");
|
|
5
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
6
|
+
const DURATION_NS_KEY = 'duration_ns';
|
|
7
|
+
function sendFaroEvents(resourceSpans = [], api) {
|
|
8
8
|
var _a, _b;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var scopeSpan = scopeSpans_1[_c];
|
|
15
|
-
var scope = scopeSpan.scope, _d = scopeSpan.spans, spans = _d === void 0 ? [] : _d;
|
|
16
|
-
var _loop_1 = function (span) {
|
|
9
|
+
for (const resourceSpan of resourceSpans) {
|
|
10
|
+
const { scopeSpans } = resourceSpan;
|
|
11
|
+
for (const scopeSpan of scopeSpans) {
|
|
12
|
+
const { scope, spans = [] } = scopeSpan;
|
|
13
|
+
for (const span of spans) {
|
|
17
14
|
if (span.kind !== internal_types_1.ESpanKind.SPAN_KIND_CLIENT) {
|
|
18
|
-
|
|
15
|
+
continue;
|
|
19
16
|
}
|
|
20
|
-
|
|
17
|
+
const spanContext = {
|
|
21
18
|
traceId: span.traceId.toString(),
|
|
22
19
|
spanId: span.spanId.toString(),
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
for (
|
|
26
|
-
var attribute = _g[_f];
|
|
21
|
+
const faroEventAttributes = {};
|
|
22
|
+
for (const attribute of span.attributes) {
|
|
27
23
|
faroEventAttributes[attribute.key] = String(Object.values(attribute.value)[0]);
|
|
28
24
|
}
|
|
29
25
|
// Add span duration in nanoseconds
|
|
30
26
|
if (!Number.isNaN(span.endTimeUnixNano) && !Number.isNaN(span.startTimeUnixNano)) {
|
|
31
27
|
faroEventAttributes[DURATION_NS_KEY] = String(Number(span.endTimeUnixNano) - Number(span.startTimeUnixNano));
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const index = ((_a = scope === null || scope === void 0 ? void 0 : scope.name) !== null && _a !== void 0 ? _a : '').indexOf('-');
|
|
30
|
+
let eventName = faro_web_sdk_1.unknownString;
|
|
35
31
|
if (scope === null || scope === void 0 ? void 0 : scope.name) {
|
|
36
32
|
if (index === -1) {
|
|
37
33
|
eventName = (_b = scope.name.split('/')[1]) !== null && _b !== void 0 ? _b : scope.name;
|
|
@@ -40,11 +36,11 @@ function sendFaroEvents(resourceSpans, api) {
|
|
|
40
36
|
eventName = scope === null || scope === void 0 ? void 0 : scope.name.substring(index + 1);
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
|
-
api.pushEvent(
|
|
44
|
-
spanContext
|
|
39
|
+
api.pushEvent(`faro.tracing.${eventName}`, faroEventAttributes, undefined, {
|
|
40
|
+
spanContext,
|
|
45
41
|
// Convert nanoseconds to milliseconds
|
|
46
42
|
timestampOverwriteMs: Number(span.endTimeUnixNano) / 1000000,
|
|
47
|
-
customPayloadTransformer:
|
|
43
|
+
customPayloadTransformer: (payload) => {
|
|
48
44
|
var _a, _b;
|
|
49
45
|
if (faroEventAttributes['faro.action.user.name'] != null &&
|
|
50
46
|
faroEventAttributes['faro.action.user.parentId'] != null) {
|
|
@@ -58,10 +54,6 @@ function sendFaroEvents(resourceSpans, api) {
|
|
|
58
54
|
return payload;
|
|
59
55
|
},
|
|
60
56
|
});
|
|
61
|
-
};
|
|
62
|
-
for (var _e = 0, spans_1 = spans; _e < spans_1.length; _e++) {
|
|
63
|
-
var span = spans_1[_e];
|
|
64
|
-
_loop_1(span);
|
|
65
57
|
}
|
|
66
58
|
}
|
|
67
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faroTraceExporter.utils.js","sourceRoot":"","sources":["../../src/faroTraceExporter.utils.ts"],"names":[],"mappings":";;AAQA,wCAgEC;AAvED,
|
|
1
|
+
{"version":3,"file":"faroTraceExporter.utils.js","sourceRoot":"","sources":["../../src/faroTraceExporter.utils.ts"],"names":[],"mappings":";;AAQA,wCAgEC;AAvED,mGAAgH;AAEhH,wDAAsD;AAGtD,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC,SAAgB,cAAc,CAAC,gBAAkC,EAAE,EAAE,GAAQ;;IAC3E,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,MAAM,EAAE,UAAU,EAAE,GAAG,YAAY,CAAC;QAEpC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;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CAAC;wBACjB,SAAS,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mCAAI,KAAK,CAAC,IAAI,CAAC;oBACrD,CAAC;oBAED,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;wBACf,SAAS,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;oBAC/C,CAAC;gBACH,CAAC;gBAED,GAAG,CAAC,SAAS,CAAC,gBAAgB,SAAS,EAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE;oBACzE,WAAW;oBACX,sCAAsC;oBACtC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,OAAS;oBAC9D,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;;wBACpC,IACE,mBAAmB,CAAC,uBAAuB,CAAC,IAAI,IAAI;4BACpD,mBAAmB,CAAC,2BAA2B,CAAC,IAAI,IAAI,EACxD,CAAC;4BACD,OAAO,CAAC,MAAM,GAAG;gCACf,IAAI,EAAE,mBAAmB,CAAC,uBAAuB,CAAC;gCAClD,QAAQ,EAAE,mBAAmB,CAAC,2BAA2B,CAAC;6BAC3D,CAAC;4BAEK,MAAA,OAAO,CAAC,UAAU,+CAAG,uBAAuB,CAAC,CAAC;4BAC9C,MAAA,OAAO,CAAC,UAAU,+CAAG,2BAA2B,CAAC,CAAC;wBAC3D,CAAC;wBAED,OAAO,OAAO,CAAC;oBACjB,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\nimport { ESpanKind, type IResourceSpans } from '@opentelemetry/otlp-transformer/build/src/trace/internal-types';\n\nimport { unknownString } from '@grafana/faro-web-sdk';\nimport type { API, EventAttributes as FaroEventAttributes } from '@grafana/faro-web-sdk';\n\nconst DURATION_NS_KEY = 'duration_ns';\n\nexport function sendFaroEvents(resourceSpans: IResourceSpans[] = [], api: API) {\n for (const resourceSpan of resourceSpans) {\n const { scopeSpans } = resourceSpan;\n\n for (const scopeSpan of scopeSpans) {\n const { scope, spans = [] } = scopeSpan;\n\n for (const span of spans) {\n if (span.kind !== ESpanKind.SPAN_KIND_CLIENT) {\n continue;\n }\n\n const spanContext: Pick<SpanContext, 'traceId' | 'spanId'> = {\n traceId: span.traceId.toString(),\n spanId: span.spanId.toString(),\n };\n\n const faroEventAttributes: FaroEventAttributes = {};\n for (const attribute of span.attributes) {\n faroEventAttributes[attribute.key] = String(Object.values(attribute.value)[0]);\n }\n\n // Add span duration in nanoseconds\n if (!Number.isNaN(span.endTimeUnixNano) && !Number.isNaN(span.startTimeUnixNano)) {\n faroEventAttributes[DURATION_NS_KEY] = String(Number(span.endTimeUnixNano) - Number(span.startTimeUnixNano));\n }\n\n const index = (scope?.name ?? '').indexOf('-');\n let eventName = unknownString;\n\n if (scope?.name) {\n if (index === -1) {\n eventName = scope.name.split('/')[1] ?? scope.name;\n }\n\n if (index > -1) {\n eventName = scope?.name.substring(index + 1);\n }\n }\n\n api.pushEvent(`faro.tracing.${eventName}`, faroEventAttributes, undefined, {\n spanContext,\n // Convert nanoseconds to milliseconds\n timestampOverwriteMs: Number(span.endTimeUnixNano) / 1_000_000,\n customPayloadTransformer: (payload) => {\n if (\n faroEventAttributes['faro.action.user.name'] != null &&\n faroEventAttributes['faro.action.user.parentId'] != null\n ) {\n payload.action = {\n name: faroEventAttributes['faro.action.user.name'],\n parentId: faroEventAttributes['faro.action.user.parentId'],\n };\n\n delete payload.attributes?.['faro.action.user.name'];\n delete payload.attributes?.['faro.action.user.parentId'];\n }\n\n return payload;\n },\n });\n }\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FaroUserActionSpanProcessor = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
6
6
|
// There is very rare race condition that would result in span being attached to different user action. As shown in the diagram below.
|
|
7
7
|
// The scenario is the following
|
|
8
8
|
//
|
|
@@ -14,15 +14,15 @@ var faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
|
14
14
|
// 6. Span processor tries to attach the `faro.user.action` attributes based on the state of the current user action which is id = 2.
|
|
15
15
|
//
|
|
16
16
|
// This ultimately depends on the processing delay of the span processor which deems this race condition highly unlikely.
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
class FaroUserActionSpanProcessor {
|
|
18
|
+
constructor(processor) {
|
|
19
19
|
this.processor = processor;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
forceFlush() {
|
|
22
22
|
return this.processor.forceFlush();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
}
|
|
24
|
+
onStart(span, parentContext) {
|
|
25
|
+
const userAction = faro_web_sdk_1.faro.api.getActiveUserAction();
|
|
26
26
|
if (userAction &&
|
|
27
27
|
(userAction === null || userAction === void 0 ? void 0 : userAction.getState()) === faro_web_sdk_1.UserActionState.Started &&
|
|
28
28
|
span.kind === api_1.SpanKind.CLIENT) {
|
|
@@ -34,14 +34,13 @@ var FaroUserActionSpanProcessor = /** @class */ (function () {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
this.processor.onStart(span, parentContext);
|
|
37
|
-
}
|
|
38
|
-
|
|
37
|
+
}
|
|
38
|
+
onEnd(span) {
|
|
39
39
|
this.processor.onEnd(span);
|
|
40
|
-
}
|
|
41
|
-
|
|
40
|
+
}
|
|
41
|
+
shutdown() {
|
|
42
42
|
return this.processor.shutdown();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
46
45
|
exports.FaroUserActionSpanProcessor = FaroUserActionSpanProcessor;
|
|
47
46
|
//# sourceMappingURL=faroUserActionSpanProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faroUserActionSpanProcessor.js","sourceRoot":"","sources":["../../src/faroUserActionSpanProcessor.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"faroUserActionSpanProcessor.js","sourceRoot":"","sources":["../../src/faroUserActionSpanProcessor.ts"],"names":[],"mappings":";;;AAAA,4CAA4D;AAG5D,wDAAgG;AAEhG,sIAAsI;AACtI,gCAAgC;AAChC,EAAE;AACF,iCAAiC;AACjC,8CAA8C;AAC9C,sBAAsB;AACtB,2BAA2B;AAC3B,uCAAuC;AACvC,qIAAqI;AACrI,EAAE;AACF,yHAAyH;AACzH,MAAa,2BAA2B;IACtC,YAAoB,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;IAAG,CAAC;IAEhD,UAAU;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;IAED,OAAO,CAAC,IAAU,EAAE,aAAsB;QACxC,MAAM,UAAU,GAAG,mBAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAClD,IACE,UAAU;YACV,CAAC,UAAqD,aAArD,UAAU,uBAAV,UAAU,CAA6C,QAAQ,EAAE,MAAK,8BAAe,CAAC,OAAO;YAC9F,IAAI,CAAC,IAAI,KAAK,cAAQ,CAAC,MAAM,EAC7B,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,EAAE,CAAC;gBAC9C,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC;YAC9D,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,2BAA2B,CAAC,EAAE,CAAC;gBAClD,IAAI,CAAC,UAAU,CAAC,2BAA2B,CAAC,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,CAAC;YACtE,CAAC;QACH,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,IAAkB;QACtB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;CACF;AAhCD,kEAgCC","sourcesContent":["import { type Context, SpanKind } from '@opentelemetry/api';\nimport type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-web';\n\nimport { faro, type UserActionInternalInterface, UserActionState } from '@grafana/faro-web-sdk';\n\n// There is very rare race condition that would result in span being attached to different user action. As shown in the diagram below.\n// The scenario is the following\n//\n// 1. User action (id = 1) starts\n// 2. Things happen for a given amount of time\n// 3. User action ends\n// 4. Span processor starts\n// 5. A new user action (id = 2) starts\n// 6. Span processor tries to attach the `faro.user.action` attributes based on the state of the current user action which is id = 2.\n//\n// This ultimately depends on the processing delay of the span processor which deems this race condition highly unlikely.\nexport class FaroUserActionSpanProcessor implements SpanProcessor {\n constructor(private processor: SpanProcessor) {}\n\n forceFlush(): Promise<void> {\n return this.processor.forceFlush();\n }\n\n onStart(span: Span, parentContext: Context): void {\n const userAction = faro.api.getActiveUserAction();\n if (\n userAction &&\n (userAction as unknown as UserActionInternalInterface)?.getState() === UserActionState.Started &&\n span.kind === SpanKind.CLIENT\n ) {\n if (!span.attributes['faro.action.user.name']) {\n span.attributes['faro.action.user.name'] = userAction?.name;\n }\n if (!span.attributes['faro.action.user.parentId']) {\n span.attributes['faro.action.user.parentId'] = userAction?.parentId;\n }\n }\n\n this.processor.onStart(span, parentContext);\n }\n\n onEnd(span: ReadableSpan): void {\n this.processor.onEnd(span);\n }\n\n shutdown(): Promise<void> {\n return this.processor.shutdown();\n }\n}\n"]}
|
|
@@ -1,52 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.FaroXhrInstrumentation = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var self = _this;
|
|
27
|
-
_this.parentCreateSpan = self._createSpan.bind(_this);
|
|
28
|
-
return _this;
|
|
4
|
+
const instrumentation_xml_http_request_1 = require("@opentelemetry/instrumentation-xml-http-request");
|
|
5
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
6
|
+
class FaroXhrInstrumentation extends instrumentation_xml_http_request_1.XMLHttpRequestInstrumentation {
|
|
7
|
+
constructor(config = {}) {
|
|
8
|
+
super(config);
|
|
9
|
+
const self = this;
|
|
10
|
+
this.parentCreateSpan = self._createSpan.bind(this);
|
|
29
11
|
}
|
|
30
12
|
// Patching the parent's private method to handle url type string or URL
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var args = [];
|
|
37
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
38
|
-
args[_i] = arguments[_i];
|
|
39
|
-
}
|
|
40
|
-
var span;
|
|
13
|
+
_patchOpen() {
|
|
14
|
+
return (original) => {
|
|
15
|
+
const plugin = this;
|
|
16
|
+
return function patchOpen(...args) {
|
|
17
|
+
let span;
|
|
41
18
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
const method = args[0];
|
|
20
|
+
let url = (0, faro_web_sdk_1.getUrlFromResource)(args[1]);
|
|
44
21
|
span = plugin.parentCreateSpan(this, url, method);
|
|
45
22
|
}
|
|
46
23
|
catch (error) {
|
|
47
24
|
faro_web_sdk_1.faro.internalLogger.error(error);
|
|
48
25
|
}
|
|
49
|
-
|
|
26
|
+
const currentAction = faro_web_sdk_1.faro.api.getActiveUserAction();
|
|
50
27
|
if (span &&
|
|
51
28
|
currentAction &&
|
|
52
29
|
(currentAction === null || currentAction === void 0 ? void 0 : currentAction.getState()) === faro_web_sdk_1.UserActionState.Started) {
|
|
@@ -56,8 +33,7 @@ var FaroXhrInstrumentation = /** @class */ (function (_super) {
|
|
|
56
33
|
return original.apply(this, args);
|
|
57
34
|
};
|
|
58
35
|
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}(instrumentation_xml_http_request_1.XMLHttpRequestInstrumentation));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
62
38
|
exports.FaroXhrInstrumentation = FaroXhrInstrumentation;
|
|
63
39
|
//# sourceMappingURL=faroXhrInstrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faroXhrInstrumentation.js","sourceRoot":"","sources":["../../src/faroXhrInstrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"faroXhrInstrumentation.js","sourceRoot":"","sources":["../../src/faroXhrInstrumentation.ts"],"names":[],"mappings":";;;AACA,sGAAgG;AAIhG,wDAAoH;AAMpH,MAAa,sBAAuB,SAAQ,gEAA6B;IAGv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DAuCC","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';\nimport type { XMLHttpRequestInstrumentationConfig } from '@opentelemetry/instrumentation-xml-http-request';\nimport type { OpenFunction } from '@opentelemetry/instrumentation-xml-http-request/build/src/types';\n\nimport { faro, getUrlFromResource, type UserActionInternalInterface, UserActionState } from '@grafana/faro-web-sdk';\n\ntype Parent = {\n _createSpan: (xhr: XMLHttpRequest, url: string, method: string) => Span | undefined;\n};\n\nexport class FaroXhrInstrumentation extends XMLHttpRequestInstrumentation {\n private parentCreateSpan: Parent['_createSpan'];\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super(config);\n\n const self = this as any as Parent;\n this.parentCreateSpan = self._createSpan.bind(this);\n }\n\n // Patching the parent's private method to handle url type string or URL\n protected override _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n let span: Span | undefined;\n try {\n const method: string = args[0];\n let url: string | URL = getUrlFromResource(args[1])!;\n\n span = plugin.parentCreateSpan(this, url, method);\n } catch (error) {\n faro.internalLogger.error(error);\n }\n\n const currentAction = faro.api.getActiveUserAction();\n if (\n span &&\n currentAction &&\n (currentAction as unknown as UserActionInternalInterface)?.getState() === UserActionState.Started\n ) {\n span.setAttribute('faro.action.user.name', currentAction.name);\n span.setAttribute('faro.action.user.parentId', currentAction.parentId);\n }\n\n return original.apply(this, args);\n };\n };\n }\n}\n"]}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
3
|
var t = {};
|
|
15
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -23,22 +12,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
23
12
|
};
|
|
24
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
14
|
exports.getDefaultOTELInstrumentations = getDefaultOTELInstrumentations;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function getDefaultOTELInstrumentations(options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var xhrOpts = createXhrInstrumentationOptions(xhrInstrumentationOptions, sharedOptions);
|
|
15
|
+
const instrumentation_fetch_1 = require("@opentelemetry/instrumentation-fetch");
|
|
16
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
17
|
+
const faroXhrInstrumentation_1 = require("./faroXhrInstrumentation");
|
|
18
|
+
const instrumentationUtils_1 = require("./instrumentationUtils");
|
|
19
|
+
function getDefaultOTELInstrumentations(options = {}) {
|
|
20
|
+
const { fetchInstrumentationOptions, xhrInstrumentationOptions } = options, sharedOptions = __rest(options, ["fetchInstrumentationOptions", "xhrInstrumentationOptions"]);
|
|
21
|
+
const fetchOpts = createFetchInstrumentationOptions(fetchInstrumentationOptions, sharedOptions);
|
|
22
|
+
const xhrOpts = createXhrInstrumentationOptions(xhrInstrumentationOptions, sharedOptions);
|
|
35
23
|
return [new instrumentation_fetch_1.FetchInstrumentation(fetchOpts), new faroXhrInstrumentation_1.FaroXhrInstrumentation(xhrOpts)];
|
|
36
24
|
}
|
|
37
25
|
function createFetchInstrumentationOptions(fetchInstrumentationOptions, sharedOptions) {
|
|
38
|
-
return
|
|
26
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, sharedOptions), { ignoreNetworkEvents: true }), fetchInstrumentationOptions), {
|
|
39
27
|
// always keep this function
|
|
40
|
-
applyCustomAttributesOnSpan: (0, instrumentationUtils_1.fetchCustomAttributeFunctionWithDefaults)(fetchInstrumentationOptions === null || fetchInstrumentationOptions === void 0 ? void 0 : fetchInstrumentationOptions.applyCustomAttributesOnSpan), requestHook:
|
|
41
|
-
|
|
28
|
+
applyCustomAttributesOnSpan: (0, instrumentationUtils_1.fetchCustomAttributeFunctionWithDefaults)(fetchInstrumentationOptions === null || fetchInstrumentationOptions === void 0 ? void 0 : fetchInstrumentationOptions.applyCustomAttributesOnSpan), requestHook: (span, _) => {
|
|
29
|
+
const currentAction = faro_web_sdk_1.faro.api.getActiveUserAction();
|
|
42
30
|
if (currentAction &&
|
|
43
31
|
(currentAction === null || currentAction === void 0 ? void 0 : currentAction.getState()) === faro_web_sdk_1.UserActionState.Started) {
|
|
44
32
|
span.setAttribute('faro.action.user.name', currentAction.name);
|
|
@@ -47,7 +35,7 @@ function createFetchInstrumentationOptions(fetchInstrumentationOptions, sharedOp
|
|
|
47
35
|
} });
|
|
48
36
|
}
|
|
49
37
|
function createXhrInstrumentationOptions(xhrInstrumentationOptions, sharedOptions) {
|
|
50
|
-
return
|
|
38
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, sharedOptions), { ignoreNetworkEvents: true }), xhrInstrumentationOptions), {
|
|
51
39
|
// always keep this function
|
|
52
40
|
applyCustomAttributesOnSpan: (0, instrumentationUtils_1.xhrCustomAttributeFunctionWithDefaults)(xhrInstrumentationOptions === null || xhrInstrumentationOptions === void 0 ? void 0 : xhrInstrumentationOptions.applyCustomAttributesOnSpan) });
|
|
53
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultOTELInstrumentations.js","sourceRoot":"","sources":["../../src/getDefaultOTELInstrumentations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDefaultOTELInstrumentations.js","sourceRoot":"","sources":["../../src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EACtF,aAAsC;IAEtC,mEACK,aAAa,KAChB,mBAAmB,EAAE,IAAI,KAEtB,yBAAyB;QAC5B,4BAA4B;QAC5B,2BAA2B,EAAE,IAAA,6DAAsC,EACjE,yBAAyB,aAAzB,yBAAyB,uBAAzB,yBAAyB,CAAE,2BAA2B,CACvD,IACD;AACJ,CAAC","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';\n\nimport { faro, type UserActionInternalInterface, UserActionState } from '@grafana/faro-web-sdk';\n\nimport { FaroXhrInstrumentation } from './faroXhrInstrumentation';\nimport {\n fetchCustomAttributeFunctionWithDefaults,\n xhrCustomAttributeFunctionWithDefaults,\n} from './instrumentationUtils';\nimport type { DefaultInstrumentationsOptions, InstrumentationOption } from './types';\n\nexport function getDefaultOTELInstrumentations(options: DefaultInstrumentationsOptions = {}): InstrumentationOption[] {\n const { fetchInstrumentationOptions, xhrInstrumentationOptions, ...sharedOptions } = options;\n\n const fetchOpts = createFetchInstrumentationOptions(fetchInstrumentationOptions, sharedOptions);\n const xhrOpts = createXhrInstrumentationOptions(xhrInstrumentationOptions, sharedOptions);\n\n return [new FetchInstrumentation(fetchOpts), new FaroXhrInstrumentation(xhrOpts)];\n}\nfunction createFetchInstrumentationOptions(\n fetchInstrumentationOptions: DefaultInstrumentationsOptions['fetchInstrumentationOptions'],\n sharedOptions: Record<string, unknown>\n) {\n return {\n ...sharedOptions,\n ignoreNetworkEvents: true,\n // keep this here to overwrite the defaults above if provided by the users\n ...fetchInstrumentationOptions,\n // always keep this function\n applyCustomAttributesOnSpan: fetchCustomAttributeFunctionWithDefaults(\n fetchInstrumentationOptions?.applyCustomAttributesOnSpan\n ),\n requestHook: (span: Span, _: Request | RequestInit) => {\n const currentAction = faro.api.getActiveUserAction();\n if (\n currentAction &&\n (currentAction as unknown as UserActionInternalInterface)?.getState() === UserActionState.Started\n ) {\n span.setAttribute('faro.action.user.name', currentAction.name);\n span.setAttribute('faro.action.user.parentId', currentAction.parentId);\n }\n },\n };\n}\n\nfunction createXhrInstrumentationOptions(\n xhrInstrumentationOptions: DefaultInstrumentationsOptions['xhrInstrumentationOptions'],\n sharedOptions: Record<string, unknown>\n) {\n return {\n ...sharedOptions,\n ignoreNetworkEvents: true,\n // keep this here to overwrite the defaults above if provided by the users\n ...xhrInstrumentationOptions,\n // always keep this function\n applyCustomAttributesOnSpan: xhrCustomAttributeFunctionWithDefaults(\n xhrInstrumentationOptions?.applyCustomAttributesOnSpan\n ),\n };\n}\n"]}
|
|
@@ -1,51 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.TracingInstrumentation = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const core_1 = require("@opentelemetry/core");
|
|
6
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
7
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
8
|
+
const sdk_trace_web_1 = require("@opentelemetry/sdk-trace-web");
|
|
9
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
10
|
+
const faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
11
|
+
const faroMetaAttributesSpanProcessor_1 = require("./faroMetaAttributesSpanProcessor");
|
|
12
|
+
const faroTraceExporter_1 = require("./faroTraceExporter");
|
|
13
|
+
const getDefaultOTELInstrumentations_1 = require("./getDefaultOTELInstrumentations");
|
|
14
|
+
const sampler_1 = require("./sampler");
|
|
15
|
+
const semconv_1 = require("./semconv");
|
|
31
16
|
// the providing of app name here is not great
|
|
32
17
|
// should delay initialization and provide the full Faro config,
|
|
33
18
|
// taking app name from it
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
_this.name = '@grafana/faro-web-tracing';
|
|
41
|
-
_this.version = faro_web_sdk_1.VERSION;
|
|
42
|
-
return _this;
|
|
19
|
+
class TracingInstrumentation extends faro_web_sdk_1.BaseInstrumentation {
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
super();
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.name = '@grafana/faro-web-tracing';
|
|
24
|
+
this.version = faro_web_sdk_1.VERSION;
|
|
43
25
|
}
|
|
44
|
-
|
|
45
|
-
var _this = this;
|
|
26
|
+
initialize() {
|
|
46
27
|
var _a, _b, _c, _d, _e;
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
const options = this.options;
|
|
29
|
+
const attributes = {};
|
|
49
30
|
if (this.config.app.name) {
|
|
50
31
|
attributes[semantic_conventions_1.ATTR_SERVICE_NAME] = this.config.app.name;
|
|
51
32
|
}
|
|
@@ -63,9 +44,9 @@ var TracingInstrumentation = /** @class */ (function (_super) {
|
|
|
63
44
|
*/
|
|
64
45
|
attributes[semantic_conventions_1.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;
|
|
65
46
|
}
|
|
66
|
-
|
|
47
|
+
const browserMeta = this.metas.value.browser;
|
|
67
48
|
if ((0, faro_web_sdk_1.isArray)(browserMeta === null || browserMeta === void 0 ? void 0 : browserMeta.brands)) {
|
|
68
|
-
attributes[semconv_1.ATTR_BROWSER_BRANDS] = browserMeta.brands.map(
|
|
49
|
+
attributes[semconv_1.ATTR_BROWSER_BRANDS] = browserMeta.brands.map((entry) => entry.brand);
|
|
69
50
|
}
|
|
70
51
|
if (browserMeta === null || browserMeta === void 0 ? void 0 : browserMeta.language) {
|
|
71
52
|
attributes[semconv_1.ATTR_BROWSER_LANGUAGE] = browserMeta.language;
|
|
@@ -84,13 +65,13 @@ var TracingInstrumentation = /** @class */ (function (_super) {
|
|
|
84
65
|
attributes[semconv_1.ATTR_TELEMETRY_DISTRO_NAME] = 'faro-web-sdk';
|
|
85
66
|
attributes[semconv_1.ATTR_TELEMETRY_DISTRO_VERSION] = faro_web_sdk_1.VERSION;
|
|
86
67
|
Object.assign(attributes, options.resourceAttributes);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
resource
|
|
68
|
+
const resource = (0, resources_1.defaultResource)().merge((0, resources_1.resourceFromAttributes)(attributes));
|
|
69
|
+
const provider = new sdk_trace_web_1.WebTracerProvider({
|
|
70
|
+
resource,
|
|
90
71
|
sampler: {
|
|
91
|
-
shouldSample:
|
|
72
|
+
shouldSample: () => {
|
|
92
73
|
return {
|
|
93
|
-
decision: (0, sampler_1.getSamplingDecision)(
|
|
74
|
+
decision: (0, sampler_1.getSamplingDecision)(this.api.getSession()),
|
|
94
75
|
};
|
|
95
76
|
},
|
|
96
77
|
},
|
|
@@ -105,22 +86,21 @@ var TracingInstrumentation = /** @class */ (function (_super) {
|
|
|
105
86
|
propagator: (_c = options.propagator) !== null && _c !== void 0 ? _c : new core_1.W3CTraceContextPropagator(),
|
|
106
87
|
contextManager: options.contextManager,
|
|
107
88
|
});
|
|
108
|
-
|
|
89
|
+
const { propagateTraceHeaderCorsUrls, fetchInstrumentationOptions, xhrInstrumentationOptions } = (_d = this.options.instrumentationOptions) !== null && _d !== void 0 ? _d : {};
|
|
109
90
|
(0, instrumentation_1.registerInstrumentations)({
|
|
110
91
|
instrumentations: (_e = options.instrumentations) !== null && _e !== void 0 ? _e : (0, getDefaultOTELInstrumentations_1.getDefaultOTELInstrumentations)({
|
|
111
92
|
ignoreUrls: this.getIgnoreUrls(),
|
|
112
|
-
propagateTraceHeaderCorsUrls
|
|
113
|
-
fetchInstrumentationOptions
|
|
114
|
-
xhrInstrumentationOptions
|
|
93
|
+
propagateTraceHeaderCorsUrls,
|
|
94
|
+
fetchInstrumentationOptions,
|
|
95
|
+
xhrInstrumentationOptions,
|
|
115
96
|
}),
|
|
116
97
|
});
|
|
117
98
|
this.api.initOTEL(api_1.trace, api_1.context);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return this.transports.transports.flatMap(
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return TracingInstrumentation;
|
|
124
|
-
}(faro_web_sdk_1.BaseInstrumentation));
|
|
99
|
+
}
|
|
100
|
+
getIgnoreUrls() {
|
|
101
|
+
return this.transports.transports.flatMap((transport) => transport.getIgnoreUrls());
|
|
102
|
+
}
|
|
103
|
+
}
|
|
125
104
|
exports.TracingInstrumentation = TracingInstrumentation;
|
|
105
|
+
TracingInstrumentation.SCHEDULED_BATCH_DELAY_MS = 1000;
|
|
126
106
|
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AAEpD,8CAAgE;AAChE,oEAA0E;AAC1E,wDAAmF;AACnF,gEAAqF;AACrF,8EAK6C;AAE7C,wD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AAa;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAoB,EAAE,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IACjG,CAAC;;AAjHH,wDAkHC;AA9GQ,+CAAwB,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import { context, trace } from '@opentelemetry/api';\nimport type { Attributes } from '@opentelemetry/api';\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';\nimport { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';\nimport {\n ATTR_SERVICE_NAME,\n ATTR_SERVICE_VERSION,\n ATTR_USER_AGENT_ORIGINAL,\n SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,\n} from '@opentelemetry/semantic-conventions';\n\nimport { BaseInstrumentation, isArray, VERSION } from '@grafana/faro-web-sdk';\nimport type { Transport } from '@grafana/faro-web-sdk';\n\nimport { FaroMetaAttributesSpanProcessor } from './faroMetaAttributesSpanProcessor';\nimport { FaroTraceExporter } from './faroTraceExporter';\nimport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\nimport { getSamplingDecision } from './sampler';\nimport {\n ATTR_BROWSER_BRANDS,\n ATTR_BROWSER_LANGUAGE,\n ATTR_BROWSER_MOBILE,\n ATTR_BROWSER_PLATFORM,\n ATTR_DEPLOYMENT_ENVIRONMENT_NAME,\n ATTR_PROCESS_RUNTIME_NAME,\n ATTR_PROCESS_RUNTIME_VERSION,\n ATTR_SERVICE_NAMESPACE,\n ATTR_TELEMETRY_DISTRO_NAME,\n ATTR_TELEMETRY_DISTRO_VERSION,\n} from './semconv';\nimport type { TracingInstrumentationOptions } from './types';\n\n// the providing of app name here is not great\n// should delay initialization and provide the full Faro config,\n// taking app name from it\n\nexport class TracingInstrumentation extends BaseInstrumentation {\n name = '@grafana/faro-web-tracing';\n version = VERSION;\n\n static SCHEDULED_BATCH_DELAY_MS = 1000;\n\n constructor(private options: TracingInstrumentationOptions = {}) {\n super();\n }\n\n initialize(): void {\n const options = this.options;\n const attributes: Attributes = {};\n\n if (this.config.app.name) {\n attributes[ATTR_SERVICE_NAME] = this.config.app.name;\n }\n\n if (this.config.app.namespace) {\n attributes[ATTR_SERVICE_NAMESPACE] = this.config.app.namespace;\n }\n\n if (this.config.app.version) {\n attributes[ATTR_SERVICE_VERSION] = this.config.app.version;\n }\n\n if (this.config.app.environment) {\n attributes[ATTR_DEPLOYMENT_ENVIRONMENT_NAME] = this.config.app.environment;\n\n /**\n * @deprecated will be removed in the future and has been replaced by ATTR_DEPLOYMENT_ENVIRONMENT_NAME (deployment.environment.name)\n * We need to keep this for compatibility with some internal services for now.\n */\n attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;\n }\n\n const browserMeta = this.metas.value.browser;\n\n if (isArray(browserMeta?.brands)) {\n attributes[ATTR_BROWSER_BRANDS] = browserMeta.brands.map((entry) => entry.brand);\n }\n\n if (browserMeta?.language) {\n attributes[ATTR_BROWSER_LANGUAGE] = browserMeta.language;\n }\n\n if (typeof browserMeta?.mobile === 'boolean') {\n attributes[ATTR_BROWSER_MOBILE] = Boolean(browserMeta.mobile);\n }\n\n if (browserMeta?.os) {\n attributes[ATTR_BROWSER_PLATFORM] = browserMeta.os;\n }\n\n if (browserMeta?.userAgent) {\n attributes[ATTR_USER_AGENT_ORIGINAL] = browserMeta.userAgent;\n }\n\n attributes[ATTR_PROCESS_RUNTIME_NAME] = 'browser';\n attributes[ATTR_PROCESS_RUNTIME_VERSION] = this.metas.value.browser?.userAgent;\n\n attributes[ATTR_TELEMETRY_DISTRO_NAME] = 'faro-web-sdk';\n attributes[ATTR_TELEMETRY_DISTRO_VERSION] = VERSION;\n\n Object.assign(attributes, options.resourceAttributes);\n\n const resource = defaultResource().merge(resourceFromAttributes(attributes));\n\n const provider = new WebTracerProvider({\n resource,\n sampler: {\n shouldSample: () => {\n return {\n decision: getSamplingDecision(this.api.getSession()),\n };\n },\n },\n spanProcessors: [\n options.spanProcessor ??\n new FaroMetaAttributesSpanProcessor(\n new BatchSpanProcessor(new FaroTraceExporter({ api: this.api }), {\n scheduledDelayMillis: TracingInstrumentation.SCHEDULED_BATCH_DELAY_MS,\n maxExportBatchSize: 30,\n }),\n this.metas\n ),\n ],\n });\n\n provider.register({\n propagator: options.propagator ?? new W3CTraceContextPropagator(),\n contextManager: options.contextManager,\n });\n\n const { propagateTraceHeaderCorsUrls, fetchInstrumentationOptions, xhrInstrumentationOptions } =\n this.options.instrumentationOptions ?? {};\n\n registerInstrumentations({\n instrumentations:\n options.instrumentations ??\n getDefaultOTELInstrumentations({\n ignoreUrls: this.getIgnoreUrls(),\n propagateTraceHeaderCorsUrls,\n fetchInstrumentationOptions,\n xhrInstrumentationOptions,\n }),\n });\n\n this.api.initOTEL(trace, context);\n }\n\n private getIgnoreUrls(): Array<string | RegExp> {\n return this.transports.transports.flatMap((transport: Transport) => transport.getIgnoreUrls());\n }\n}\n"]}
|
|
@@ -4,7 +4,7 @@ exports.setSpanStatusOnFetchError = setSpanStatusOnFetchError;
|
|
|
4
4
|
exports.setSpanStatusOnXMLHttpRequestError = setSpanStatusOnXMLHttpRequestError;
|
|
5
5
|
exports.fetchCustomAttributeFunctionWithDefaults = fetchCustomAttributeFunctionWithDefaults;
|
|
6
6
|
exports.xhrCustomAttributeFunctionWithDefaults = xhrCustomAttributeFunctionWithDefaults;
|
|
7
|
-
|
|
7
|
+
const api_1 = require("@opentelemetry/api");
|
|
8
8
|
/**
|
|
9
9
|
* Adds HTTP status code to every span.
|
|
10
10
|
*
|
|
@@ -15,7 +15,7 @@ var api_1 = require("@opentelemetry/api");
|
|
|
15
15
|
* Spec: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md#status
|
|
16
16
|
*/
|
|
17
17
|
function setSpanStatusOnFetchError(span, _request, result) {
|
|
18
|
-
|
|
18
|
+
const httpStatusCode = result instanceof Error ? 0 : result.status;
|
|
19
19
|
setSpanStatus(span, httpStatusCode);
|
|
20
20
|
}
|
|
21
21
|
function setSpanStatusOnXMLHttpRequestError(span, xhr) {
|
|
@@ -25,20 +25,20 @@ function setSpanStatus(span, httpStatusCode) {
|
|
|
25
25
|
if (httpStatusCode == null) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const isError = httpStatusCode === 0;
|
|
29
|
+
const isClientOrServerError = httpStatusCode >= 400 && httpStatusCode < 600;
|
|
30
30
|
if (isError || isClientOrServerError) {
|
|
31
31
|
span.setStatus({ code: api_1.SpanStatusCode.ERROR });
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
function fetchCustomAttributeFunctionWithDefaults(callback) {
|
|
35
|
-
return
|
|
35
|
+
return (span, request, result) => {
|
|
36
36
|
setSpanStatusOnFetchError(span, request, result);
|
|
37
37
|
callback === null || callback === void 0 ? void 0 : callback(span, request, result);
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
function xhrCustomAttributeFunctionWithDefaults(callback) {
|
|
41
|
-
return
|
|
41
|
+
return (span, xhr) => {
|
|
42
42
|
setSpanStatusOnXMLHttpRequestError(span, xhr);
|
|
43
43
|
callback === null || callback === void 0 ? void 0 : callback(span, xhr);
|
|
44
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentationUtils.js","sourceRoot":"","sources":["../../src/instrumentationUtils.ts"],"names":[],"mappings":";;AAmBA,8DAGC;AAED,gFAEC;AAeD,4FAKC;AAED,wFAKC;AArDD,
|
|
1
|
+
{"version":3,"file":"instrumentationUtils.js","sourceRoot":"","sources":["../../src/instrumentationUtils.ts"],"names":[],"mappings":";;AAmBA,8DAGC;AAED,gFAEC;AAeD,4FAKC;AAED,wFAKC;AArDD,4CAAoD;AAUpD;;;;;;;;GAQG;AACH,SAAgB,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,CAAC","sourcesContent":["import { SpanStatusCode } from '@opentelemetry/api';\nimport type { Span } from '@opentelemetry/api';\nimport type { FetchCustomAttributeFunction } from '@opentelemetry/instrumentation-fetch';\nimport type { XHRCustomAttributeFunction } from '@opentelemetry/instrumentation-xml-http-request';\n\nexport interface FetchError {\n status?: number;\n message: string;\n}\n\n/**\n * Adds HTTP status code to every span.\n *\n * The fetch instrumentation does not always set the span status to error as defined by the spec.\n * To work around that issue we manually set the span status.\n *\n * Issue: https://github.com/open-telemetry/opentelemetry-js/issues/3564\n * Spec: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md#status\n */\nexport function setSpanStatusOnFetchError(span: Span, _request: Request | RequestInit, result: Response | FetchError) {\n const httpStatusCode = result instanceof Error ? 0 : result.status;\n setSpanStatus(span, httpStatusCode);\n}\n\nexport function setSpanStatusOnXMLHttpRequestError(span: Span, xhr: XMLHttpRequest) {\n setSpanStatus(span, xhr.status);\n}\n\nfunction setSpanStatus(span: Span, httpStatusCode?: number) {\n if (httpStatusCode == null) {\n return;\n }\n\n const isError = httpStatusCode === 0;\n const isClientOrServerError = httpStatusCode >= 400 && httpStatusCode < 600;\n\n if (isError || isClientOrServerError) {\n span.setStatus({ code: SpanStatusCode.ERROR });\n }\n}\n\nexport function fetchCustomAttributeFunctionWithDefaults(callback?: FetchCustomAttributeFunction) {\n return (span: Span, request: Request | RequestInit, result: Response | FetchError) => {\n setSpanStatusOnFetchError(span, request, result);\n callback?.(span, request, result);\n };\n}\n\nexport function xhrCustomAttributeFunctionWithDefaults(callback?: XHRCustomAttributeFunction) {\n return (span: Span, xhr: XMLHttpRequest) => {\n setSpanStatusOnXMLHttpRequestError(span, xhr);\n callback?.(span, xhr);\n };\n}\n"]}
|