@grafana/faro-web-tracing 1.18.2 → 2.0.0-beta
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/bundle/types/faroUserActionSpanProcessor.d.ts +0 -2
- package/dist/bundle/types/index.d.ts +0 -1
- package/dist/cjs/faroMetaAttributesSpanProcessor.js +0 -4
- package/dist/cjs/faroMetaAttributesSpanProcessor.js.map +1 -1
- package/dist/cjs/faroUserActionSpanProcessor.js +19 -19
- package/dist/cjs/faroUserActionSpanProcessor.js.map +1 -1
- package/dist/cjs/faroXhrInstrumentation.js +9 -2
- package/dist/cjs/faroXhrInstrumentation.js.map +1 -1
- package/dist/cjs/getDefaultOTELInstrumentations.js +8 -1
- package/dist/cjs/getDefaultOTELInstrumentations.js.map +1 -1
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/instrumentation.js +3 -3
- package/dist/cjs/instrumentation.js.map +1 -1
- package/dist/esm/faroMetaAttributesSpanProcessor.js +0 -4
- package/dist/esm/faroMetaAttributesSpanProcessor.js.map +1 -1
- package/dist/esm/faroUserActionSpanProcessor.js +19 -18
- package/dist/esm/faroUserActionSpanProcessor.js.map +1 -1
- package/dist/esm/faroXhrInstrumentation.js +9 -2
- package/dist/esm/faroXhrInstrumentation.js.map +1 -1
- package/dist/esm/getDefaultOTELInstrumentations.js +8 -1
- package/dist/esm/getDefaultOTELInstrumentations.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instrumentation.js +3 -3
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/types/faroUserActionSpanProcessor.d.ts +0 -2
- package/dist/types/index.d.ts +0 -1
- package/package.json +13 -13
- package/dist/bundle/types/sessionSpanProcessor.d.ts +0 -16
- package/dist/cjs/sessionSpanProcessor.js +0 -37
- package/dist/cjs/sessionSpanProcessor.js.map +0 -1
- package/dist/esm/sessionSpanProcessor.js +0 -32
- package/dist/esm/sessionSpanProcessor.js.map +0 -1
- package/dist/types/sessionSpanProcessor.d.ts +0 -16
|
@@ -24,6 +24,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.getDefaultOTELInstrumentations = getDefaultOTELInstrumentations;
|
|
26
26
|
var instrumentation_fetch_1 = require("@opentelemetry/instrumentation-fetch");
|
|
27
|
+
var faro_core_1 = require("@grafana/faro-core");
|
|
27
28
|
var faroXhrInstrumentation_1 = require("./faroXhrInstrumentation");
|
|
28
29
|
var instrumentationUtils_1 = require("./instrumentationUtils");
|
|
29
30
|
function getDefaultOTELInstrumentations(options) {
|
|
@@ -36,7 +37,13 @@ function getDefaultOTELInstrumentations(options) {
|
|
|
36
37
|
function createFetchInstrumentationOptions(fetchInstrumentationOptions, sharedOptions) {
|
|
37
38
|
return __assign(__assign(__assign(__assign({}, sharedOptions), { ignoreNetworkEvents: true }), fetchInstrumentationOptions), {
|
|
38
39
|
// always keep this function
|
|
39
|
-
applyCustomAttributesOnSpan: (0, instrumentationUtils_1.fetchCustomAttributeFunctionWithDefaults)(fetchInstrumentationOptions === null || fetchInstrumentationOptions === void 0 ? void 0 : fetchInstrumentationOptions.applyCustomAttributesOnSpan)
|
|
40
|
+
applyCustomAttributesOnSpan: (0, instrumentationUtils_1.fetchCustomAttributeFunctionWithDefaults)(fetchInstrumentationOptions === null || fetchInstrumentationOptions === void 0 ? void 0 : fetchInstrumentationOptions.applyCustomAttributesOnSpan), requestHook: function (span, _) {
|
|
41
|
+
var currentAction = faro_core_1.faro.api.getActiveUserAction();
|
|
42
|
+
if (currentAction && currentAction.getState() === faro_core_1.UserActionState.Started) {
|
|
43
|
+
span.setAttribute('faro.action.user.name', currentAction.name);
|
|
44
|
+
span.setAttribute('faro.action.user.parentId', currentAction.parentId);
|
|
45
|
+
}
|
|
46
|
+
} });
|
|
40
47
|
}
|
|
41
48
|
function createXhrInstrumentationOptions(xhrInstrumentationOptions, sharedOptions) {
|
|
42
49
|
return __assign(__assign(__assign(__assign({}, sharedOptions), { ignoreNetworkEvents: true }), xhrInstrumentationOptions), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultOTELInstrumentations.js","sourceRoot":"","sources":["../../src/getDefaultOTELInstrumentations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getDefaultOTELInstrumentations.js","sourceRoot":"","sources":["../../src/getDefaultOTELInstrumentations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAYA,wEAOC;AAlBD,8EAA4E;AAE5E,gDAA2D;AAE3D,mEAAkE;AAClE,+DAGgC;AAGhC,SAAgB,8BAA8B,CAAC,OAA4C;IAA5C,wBAAA,EAAA,YAA4C;IACjF,IAAA,2BAA2B,GAAkD,OAAO,4BAAzD,EAAE,yBAAyB,GAAuB,OAAO,0BAA9B,EAAK,aAAa,UAAK,OAAO,EAAtF,4DAA4E,CAAF,CAAa;IAE7F,IAAM,SAAS,GAAG,iCAAiC,CAAC,2BAA2B,EAAE,aAAa,CAAC,CAAC;IAChG,IAAM,OAAO,GAAG,+BAA+B,CAAC,yBAAyB,EAAE,aAAa,CAAC,CAAC;IAE1F,OAAO,CAAC,IAAI,4CAAoB,CAAC,SAAS,CAAC,EAAE,IAAI,+CAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;AACpF,CAAC;AACD,SAAS,iCAAiC,CACxC,2BAA0F,EAC1F,aAAsC;IAEtC,+CACK,aAAa,KAChB,mBAAmB,EAAE,IAAI,KAEtB,2BAA2B;QAC9B,4BAA4B;QAC5B,2BAA2B,EAAE,IAAA,+DAAwC,EACnE,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAE,2BAA2B,CACzD,EACD,WAAW,EAAE,UAAC,IAAU,EAAE,CAAwB;YAChD,IAAM,aAAa,GAAG,gBAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;YACrD,IAAI,aAAa,IAAI,aAAa,CAAC,QAAQ,EAAE,KAAK,2BAAe,CAAC,OAAO,EAAE,CAAC;gBAC1E,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC/D,IAAI,CAAC,YAAY,CAAC,2BAA2B,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;YACzE,CAAC;QACH,CAAC,IACD;AACJ,CAAC;AAED,SAAS,+BAA+B,CACtC,yBAAsF,EACtF,aAAsC;IAEtC,+CACK,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, UserActionState } from '@grafana/faro-core';\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 (currentAction && currentAction.getState() === UserActionState.Started) {\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"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchCustomAttributeFunctionWithDefaults = exports.setSpanStatusOnFetchError = exports.getSamplingDecision = exports.TracingInstrumentation = exports.getDefaultOTELInstrumentations = exports.
|
|
3
|
+
exports.fetchCustomAttributeFunctionWithDefaults = exports.setSpanStatusOnFetchError = exports.getSamplingDecision = exports.TracingInstrumentation = exports.getDefaultOTELInstrumentations = exports.FaroTraceExporter = void 0;
|
|
4
4
|
var faroTraceExporter_1 = require("./faroTraceExporter");
|
|
5
5
|
Object.defineProperty(exports, "FaroTraceExporter", { enumerable: true, get: function () { return faroTraceExporter_1.FaroTraceExporter; } });
|
|
6
|
-
var sessionSpanProcessor_1 = require("./sessionSpanProcessor");
|
|
7
|
-
Object.defineProperty(exports, "FaroSessionSpanProcessor", { enumerable: true, get: function () { return sessionSpanProcessor_1.FaroSessionSpanProcessor; } });
|
|
8
6
|
var getDefaultOTELInstrumentations_1 = require("./getDefaultOTELInstrumentations");
|
|
9
7
|
Object.defineProperty(exports, "getDefaultOTELInstrumentations", { enumerable: true, get: function () { return getDefaultOTELInstrumentations_1.getDefaultOTELInstrumentations; } });
|
|
10
8
|
var instrumentation_1 = require("./instrumentation");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAE1B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAE1B,mFAAkF;AAAzE,gJAAA,8BAA8B,OAAA;AAEvC,qDAA2D;AAAlD,yHAAA,sBAAsB,OAAA;AAE/B,qCAAgD;AAAvC,8GAAA,mBAAmB,OAAA;AAI5B,+DAA6G;AAApG,iIAAA,yBAAyB,OAAA;AAAE,gJAAA,wCAAwC,OAAA","sourcesContent":["export { FaroTraceExporter } from './faroTraceExporter';\n\nexport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\n\nexport { TracingInstrumentation } from './instrumentation';\n\nexport { getSamplingDecision } from './sampler';\n\nexport type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';\n\nexport { setSpanStatusOnFetchError, fetchCustomAttributeFunctionWithDefaults } from './instrumentationUtils';\n"]}
|
|
@@ -25,7 +25,6 @@ var semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
|
25
25
|
var faro_web_sdk_1 = require("@grafana/faro-web-sdk");
|
|
26
26
|
var faroMetaAttributesSpanProcessor_1 = require("./faroMetaAttributesSpanProcessor");
|
|
27
27
|
var faroTraceExporter_1 = require("./faroTraceExporter");
|
|
28
|
-
var faroUserActionSpanProcessor_1 = require("./faroUserActionSpanProcessor");
|
|
29
28
|
var getDefaultOTELInstrumentations_1 = require("./getDefaultOTELInstrumentations");
|
|
30
29
|
var sampler_1 = require("./sampler");
|
|
31
30
|
var semconv_1 = require("./semconv");
|
|
@@ -60,6 +59,7 @@ var TracingInstrumentation = /** @class */ (function (_super) {
|
|
|
60
59
|
attributes[semconv_1.ATTR_DEPLOYMENT_ENVIRONMENT_NAME] = this.config.app.environment;
|
|
61
60
|
/**
|
|
62
61
|
* @deprecated will be removed in the future and has been replaced by ATTR_DEPLOYMENT_ENVIRONMENT_NAME (deployment.environment.name)
|
|
62
|
+
* We need to keep this for compatibility with some internal services for now.
|
|
63
63
|
*/
|
|
64
64
|
attributes[semantic_conventions_1.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;
|
|
65
65
|
}
|
|
@@ -95,10 +95,10 @@ var TracingInstrumentation = /** @class */ (function (_super) {
|
|
|
95
95
|
},
|
|
96
96
|
},
|
|
97
97
|
spanProcessors: [
|
|
98
|
-
(_b = options.spanProcessor) !== null && _b !== void 0 ? _b : new
|
|
98
|
+
(_b = options.spanProcessor) !== null && _b !== void 0 ? _b : new faroMetaAttributesSpanProcessor_1.FaroMetaAttributesSpanProcessor(new sdk_trace_web_1.BatchSpanProcessor(new faroTraceExporter_1.FaroTraceExporter({ api: this.api }), {
|
|
99
99
|
scheduledDelayMillis: TracingInstrumentation.SCHEDULED_BATCH_DELAY_MS,
|
|
100
100
|
maxExportBatchSize: 30,
|
|
101
|
-
}), this.metas)
|
|
101
|
+
}), this.metas),
|
|
102
102
|
],
|
|
103
103
|
});
|
|
104
104
|
provider.register({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0CAAoD;AAEpD,4CAAgE;AAChE,kEAA0E;AAC1E,sDAAmF;AAC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,+BACjD,CAAC;QAE5C,IAAA,0CAAwB,EAAC;YACvB,gBAAgB,EACd,MAAA,OAAO,CAAC,gBAAgB,mCACxB,IAAA,+DAA8B,EAAC;gBAC7B,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;gBAChC,4BAA4B,8BAAA;gBAC5B,2BAA2B,6BAAA;gBAC3B,yBAAyB,2BAAA;aAC1B,CAAC;SACL,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAK,EAAE,aAAO,CAAC,CAAC;IACpC,CAAC;IAEO,8CAAa,GAArB;QACE,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,UAAC,SAAoB,IAAK,OAAA,SAAS,CAAC,aAAa,EAAE,EAAzB,CAAyB,CAAC,CAAC;IACjG,CAAC;IA7GM,+CAAwB,GAAG,IAAI,AAAP,CAAQ;IA8GzC,6BAAC;CAAA,AAlHD,CAA4C,kCAAmB,GAkH9D;AAlHY,wDAAsB","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"]}
|
|
@@ -12,10 +12,6 @@ export class FaroMetaAttributesSpanProcessor {
|
|
|
12
12
|
const session = this.metas.value.session;
|
|
13
13
|
if (session === null || session === void 0 ? void 0 : session.id) {
|
|
14
14
|
span.attributes[ATTR_SESSION_ID] = session.id;
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated will be removed in the future and has been replaced by ATTR_SESSION_ID (session.id)
|
|
17
|
-
*/
|
|
18
|
-
span.attributes['session_id'] = session.id;
|
|
19
15
|
}
|
|
20
16
|
const user = (_a = this.metas.value.user) !== null && _a !== void 0 ? _a : {};
|
|
21
17
|
if (user.email) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faroMetaAttributesSpanProcessor.js","sourceRoot":"","sources":["../../src/faroMetaAttributesSpanProcessor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,OAAO,+BAA+B;IAC1C,YACU,SAAwB,EACxB,KAAY;QADZ,cAAS,GAAT,SAAS,CAAe;QACxB,UAAK,GAAL,KAAK,CAAO;IACnB,CAAC;IAEJ,UAAU;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;IAED,OAAO,CAAC,IAAU,EAAE,aAAsB;;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;QAEzC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,EAAE,CAAC;YAChB,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"faroMetaAttributesSpanProcessor.js","sourceRoot":"","sources":["../../src/faroMetaAttributesSpanProcessor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,OAAO,+BAA+B;IAC1C,YACU,SAAwB,EACxB,KAAY;QADZ,cAAS,GAAT,SAAS,CAAe;QACxB,UAAK,GAAL,KAAK,CAAO;IACnB,CAAC;IAEJ,UAAU;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;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;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","sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-web';\n\nimport type { Metas } from '@grafana/faro-web-sdk';\n\nimport { ATTR_SESSION_ID } from './semconv';\n\nexport class FaroMetaAttributesSpanProcessor implements SpanProcessor {\n constructor(\n private processor: SpanProcessor,\n private metas: Metas\n ) {}\n\n forceFlush(): Promise<void> {\n return this.processor.forceFlush();\n }\n\n onStart(span: Span, parentContext: Context): void {\n const session = this.metas.value.session;\n\n if (session?.id) {\n span.attributes[ATTR_SESSION_ID] = session.id;\n }\n\n const user = this.metas.value.user ?? {};\n\n if (user.email) {\n span.attributes['user.email'] = user.email;\n }\n\n if (user.id) {\n span.attributes['user.id'] = user.id;\n }\n\n if (user.username) {\n span.attributes['user.name'] = user.username;\n }\n\n if (user.fullName) {\n span.attributes['user.full_name'] = user.fullName;\n }\n\n if (user.roles) {\n span.attributes['user.roles'] = user.roles.split(',').map((role) => role.trim());\n }\n\n if (user.hash) {\n span.attributes['user.hash'] = user.hash;\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,30 +1,31 @@
|
|
|
1
1
|
import { SpanKind } from '@opentelemetry/api';
|
|
2
|
-
import {
|
|
2
|
+
import { faro, UserActionState } from '@grafana/faro-core';
|
|
3
|
+
// There is very rare race condition that would result in span being attached to different user action. As shown in the diagram below.
|
|
4
|
+
// The scenario is the following
|
|
5
|
+
//
|
|
6
|
+
// 1. User action (id = 1) starts
|
|
7
|
+
// 2. Things happen for a given amount of time
|
|
8
|
+
// 3. User action ends
|
|
9
|
+
// 4. Span processor starts
|
|
10
|
+
// 5. A new user action (id = 2) starts
|
|
11
|
+
// 6. Span processor tries to attach the `faro.user.action` attributes based on the state of the current user action which is id = 2.
|
|
12
|
+
//
|
|
13
|
+
// This ultimately depends on the processing delay of the span processor which deems this race condition highly unlikely.
|
|
3
14
|
export class FaroUserActionSpanProcessor {
|
|
4
15
|
constructor(processor) {
|
|
5
16
|
this.processor = processor;
|
|
6
|
-
apiMessageBus.subscribe((msg) => {
|
|
7
|
-
if (msg.type === USER_ACTION_START) {
|
|
8
|
-
this.message = msg;
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if ([USER_ACTION_END, USER_ACTION_HALT, USER_ACTION_CANCEL].includes(msg.type)) {
|
|
12
|
-
this.message = undefined;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
17
|
}
|
|
16
18
|
forceFlush() {
|
|
17
19
|
return this.processor.forceFlush();
|
|
18
20
|
}
|
|
19
21
|
onStart(span, parentContext) {
|
|
20
|
-
|
|
21
|
-
if (span.kind === SpanKind.CLIENT) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
span.attributes['faro.action.user.
|
|
27
|
-
span.attributes['faro.action.user.parentId'] = (_b = this.message) === null || _b === void 0 ? void 0 : _b.parentId;
|
|
22
|
+
const userAction = faro.api.getActiveUserAction();
|
|
23
|
+
if (userAction && userAction.getState() === UserActionState.Started && span.kind === SpanKind.CLIENT) {
|
|
24
|
+
if (!span.attributes['faro.action.user.name']) {
|
|
25
|
+
span.attributes['faro.action.user.name'] = userAction === null || userAction === void 0 ? void 0 : userAction.name;
|
|
26
|
+
}
|
|
27
|
+
if (!span.attributes['faro.action.user.parentId']) {
|
|
28
|
+
span.attributes['faro.action.user.parentId'] = userAction === null || userAction === void 0 ? void 0 : userAction.parentId;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
this.processor.onStart(span, parentContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faroUserActionSpanProcessor.js","sourceRoot":"","sources":["../../src/faroUserActionSpanProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG5D,OAAO,
|
|
1
|
+
{"version":3,"file":"faroUserActionSpanProcessor.js","sourceRoot":"","sources":["../../src/faroUserActionSpanProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG5D,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE3D,sIAAsI;AACtI,gCAAgC;AAChC,EAAE;AACF,iCAAiC;AACjC,8CAA8C;AAC9C,sBAAsB;AACtB,2BAA2B;AAC3B,uCAAuC;AACvC,qIAAqI;AACrI,EAAE;AACF,yHAAyH;AACzH,MAAM,OAAO,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,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAClD,IAAI,UAAU,IAAI,UAAU,CAAC,QAAQ,EAAE,KAAK,eAAe,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YACrG,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","sourcesContent":["import { type Context, SpanKind } from '@opentelemetry/api';\nimport type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-web';\n\nimport { faro, UserActionState } from '@grafana/faro-core';\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 (userAction && userAction.getState() === UserActionState.Started && span.kind === SpanKind.CLIENT) {\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,5 +1,6 @@
|
|
|
1
1
|
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
|
|
2
|
-
import { faro,
|
|
2
|
+
import { faro, UserActionState } from '@grafana/faro-core';
|
|
3
|
+
import { getUrlFromResource } from '@grafana/faro-web-sdk';
|
|
3
4
|
export class FaroXhrInstrumentation extends XMLHttpRequestInstrumentation {
|
|
4
5
|
constructor(config = {}) {
|
|
5
6
|
super(config);
|
|
@@ -11,14 +12,20 @@ export class FaroXhrInstrumentation extends XMLHttpRequestInstrumentation {
|
|
|
11
12
|
return (original) => {
|
|
12
13
|
const plugin = this;
|
|
13
14
|
return function patchOpen(...args) {
|
|
15
|
+
let span;
|
|
14
16
|
try {
|
|
15
17
|
const method = args[0];
|
|
16
18
|
let url = getUrlFromResource(args[1]);
|
|
17
|
-
plugin.parentCreateSpan(this, url, method);
|
|
19
|
+
span = plugin.parentCreateSpan(this, url, method);
|
|
18
20
|
}
|
|
19
21
|
catch (error) {
|
|
20
22
|
faro.internalLogger.error(error);
|
|
21
23
|
}
|
|
24
|
+
const currentAction = faro.api.getActiveUserAction();
|
|
25
|
+
if (span && currentAction && currentAction.getState() === UserActionState.Started) {
|
|
26
|
+
span.setAttribute('faro.action.user.name', currentAction.name);
|
|
27
|
+
span.setAttribute('faro.action.user.parentId', currentAction.parentId);
|
|
28
|
+
}
|
|
22
29
|
return original.apply(this, args);
|
|
23
30
|
};
|
|
24
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faroXhrInstrumentation.js","sourceRoot":"","sources":["../../src/faroXhrInstrumentation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAIhG,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"faroX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C,IAAI,CAAC,CAAC;oBAC/D,IAAI,CAAC,YAAY,CAAC,2BAA2B,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;gBACzE,CAAC;gBAED,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACpC,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF","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, UserActionState } from '@grafana/faro-core';\nimport { getUrlFromResource } 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 (span && currentAction && currentAction.getState() === UserActionState.Started) {\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"]}
|
|
@@ -10,6 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
|
|
13
|
+
import { faro, UserActionState } from '@grafana/faro-core';
|
|
13
14
|
import { FaroXhrInstrumentation } from './faroXhrInstrumentation';
|
|
14
15
|
import { fetchCustomAttributeFunctionWithDefaults, xhrCustomAttributeFunctionWithDefaults, } from './instrumentationUtils';
|
|
15
16
|
export function getDefaultOTELInstrumentations(options = {}) {
|
|
@@ -21,7 +22,13 @@ export function getDefaultOTELInstrumentations(options = {}) {
|
|
|
21
22
|
function createFetchInstrumentationOptions(fetchInstrumentationOptions, sharedOptions) {
|
|
22
23
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, sharedOptions), { ignoreNetworkEvents: true }), fetchInstrumentationOptions), {
|
|
23
24
|
// always keep this function
|
|
24
|
-
applyCustomAttributesOnSpan: fetchCustomAttributeFunctionWithDefaults(fetchInstrumentationOptions === null || fetchInstrumentationOptions === void 0 ? void 0 : fetchInstrumentationOptions.applyCustomAttributesOnSpan)
|
|
25
|
+
applyCustomAttributesOnSpan: fetchCustomAttributeFunctionWithDefaults(fetchInstrumentationOptions === null || fetchInstrumentationOptions === void 0 ? void 0 : fetchInstrumentationOptions.applyCustomAttributesOnSpan), requestHook: (span, _) => {
|
|
26
|
+
const currentAction = faro.api.getActiveUserAction();
|
|
27
|
+
if (currentAction && currentAction.getState() === UserActionState.Started) {
|
|
28
|
+
span.setAttribute('faro.action.user.name', currentAction.name);
|
|
29
|
+
span.setAttribute('faro.action.user.parentId', currentAction.parentId);
|
|
30
|
+
}
|
|
31
|
+
} });
|
|
25
32
|
}
|
|
26
33
|
function createXhrInstrumentationOptions(xhrInstrumentationOptions, sharedOptions) {
|
|
27
34
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, sharedOptions), { ignoreNetworkEvents: true }), xhrInstrumentationOptions), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultOTELInstrumentations.js","sourceRoot":"","sources":["../../src/getDefaultOTELInstrumentations.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getDefaultOTELInstrumentations.js","sourceRoot":"","sources":["../../src/getDefaultOTELInstrumentations.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EACL,wCAAwC,EACxC,sCAAsC,GACvC,MAAM,wBAAwB,CAAC;AAGhC,MAAM,UAAU,8BAA8B,CAAC,UAA0C,EAAE;IACzF,MAAM,EAAE,2BAA2B,EAAE,yBAAyB,KAAuB,OAAO,EAAzB,aAAa,UAAK,OAAO,EAAtF,4DAA4E,CAAU,CAAC;IAE7F,MAAM,SAAS,GAAG,iCAAiC,CAAC,2BAA2B,EAAE,aAAa,CAAC,CAAC;IAChG,MAAM,OAAO,GAAG,+BAA+B,CAAC,yBAAyB,EAAE,aAAa,CAAC,CAAC;IAE1F,OAAO,CAAC,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,IAAI,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;AACpF,CAAC;AACD,SAAS,iCAAiC,CACxC,2BAA0F,EAC1F,aAAsC;IAEtC,mEACK,aAAa,KAChB,mBAAmB,EAAE,IAAI,KAEtB,2BAA2B;QAC9B,4BAA4B;QAC5B,2BAA2B,EAAE,wCAAwC,CACnE,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAE,2BAA2B,CACzD,EACD,WAAW,EAAE,CAAC,IAAU,EAAE,CAAwB,EAAE,EAAE;YACpD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;YACrD,IAAI,aAAa,IAAI,aAAa,CAAC,QAAQ,EAAE,KAAK,eAAe,CAAC,OAAO,EAAE,CAAC;gBAC1E,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC/D,IAAI,CAAC,YAAY,CAAC,2BAA2B,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;YACzE,CAAC;QACH,CAAC,IACD;AACJ,CAAC;AAED,SAAS,+BAA+B,CACtC,yBAAsF,EACtF,aAAsC;IAEtC,mEACK,aAAa,KAChB,mBAAmB,EAAE,IAAI,KAEtB,yBAAyB;QAC5B,4BAA4B;QAC5B,2BAA2B,EAAE,sCAAsC,CACjE,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, UserActionState } from '@grafana/faro-core';\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 (currentAction && currentAction.getState() === UserActionState.Started) {\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"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { FaroTraceExporter } from './faroTraceExporter';
|
|
2
|
-
export { FaroSessionSpanProcessor } from './sessionSpanProcessor';
|
|
3
2
|
export { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
|
|
4
3
|
export { TracingInstrumentation } from './instrumentation';
|
|
5
4
|
export { getSamplingDecision } from './sampler';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAIhD,OAAO,EAAE,yBAAyB,EAAE,wCAAwC,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { FaroTraceExporter } from './faroTraceExporter';\n\nexport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\n\nexport { TracingInstrumentation } from './instrumentation';\n\nexport { getSamplingDecision } from './sampler';\n\nexport type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';\n\nexport { setSpanStatusOnFetchError, fetchCustomAttributeFunctionWithDefaults } from './instrumentationUtils';\n"]}
|
|
@@ -7,7 +7,6 @@ import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, ATTR_USER_AGENT_ORIGINAL, SEMR
|
|
|
7
7
|
import { BaseInstrumentation, isArray, VERSION } from '@grafana/faro-web-sdk';
|
|
8
8
|
import { FaroMetaAttributesSpanProcessor } from './faroMetaAttributesSpanProcessor';
|
|
9
9
|
import { FaroTraceExporter } from './faroTraceExporter';
|
|
10
|
-
import { FaroUserActionSpanProcessor } from './faroUserActionSpanProcessor';
|
|
11
10
|
import { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
|
|
12
11
|
import { getSamplingDecision } from './sampler';
|
|
13
12
|
import { ATTR_BROWSER_BRANDS, ATTR_BROWSER_LANGUAGE, ATTR_BROWSER_MOBILE, ATTR_BROWSER_PLATFORM, ATTR_DEPLOYMENT_ENVIRONMENT_NAME, ATTR_PROCESS_RUNTIME_NAME, ATTR_PROCESS_RUNTIME_VERSION, ATTR_SERVICE_NAMESPACE, ATTR_TELEMETRY_DISTRO_NAME, ATTR_TELEMETRY_DISTRO_VERSION, } from './semconv';
|
|
@@ -38,6 +37,7 @@ export class TracingInstrumentation extends BaseInstrumentation {
|
|
|
38
37
|
attributes[ATTR_DEPLOYMENT_ENVIRONMENT_NAME] = this.config.app.environment;
|
|
39
38
|
/**
|
|
40
39
|
* @deprecated will be removed in the future and has been replaced by ATTR_DEPLOYMENT_ENVIRONMENT_NAME (deployment.environment.name)
|
|
40
|
+
* We need to keep this for compatibility with some internal services for now.
|
|
41
41
|
*/
|
|
42
42
|
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;
|
|
43
43
|
}
|
|
@@ -73,10 +73,10 @@ export class TracingInstrumentation extends BaseInstrumentation {
|
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
75
|
spanProcessors: [
|
|
76
|
-
(_b = options.spanProcessor) !== null && _b !== void 0 ? _b : new
|
|
76
|
+
(_b = options.spanProcessor) !== null && _b !== void 0 ? _b : new FaroMetaAttributesSpanProcessor(new BatchSpanProcessor(new FaroTraceExporter({ api: this.api }), {
|
|
77
77
|
scheduledDelayMillis: TracingInstrumentation.SCHEDULED_BATCH_DELAY_MS,
|
|
78
78
|
maxExportBatchSize: 30,
|
|
79
|
-
}), this.metas)
|
|
79
|
+
}), this.metas),
|
|
80
80
|
],
|
|
81
81
|
});
|
|
82
82
|
provider.register({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,kCAAkC,GACnC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAG9E,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,iBAAiB,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E;gBACd,MAAA,OAAO,CAAC,aAAa,mCACnB,IAAI,+BAA+B,CACjC,IAAI,kBAAkB,CAAC,IAAI,iBAAiB,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE;oBAC/D,oBAAoB,EAAE,sBAAsB,CAAC,wBAAwB;oBACrE,kBAAkB,EAAE,EAAE;iBACvB,CAAC,EACF,IAAI,CAAC,KAAK,CACX;aACJ;SACF,CAAC,CAAC;QAEH,QAAQ,CAAC,QAAQ,CAAC;YAChB,UAAU,EAAE,MAAA,OAAO,CAAC,UAAU,mCAAI,IAAI,yBAAyB,EAAE;YACjE,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC;QAEH,MAAM,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,GAC5F,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,mCAAI,EAAE,CAAC;QAE5C,wBAAwB,CAAC;YACvB,gBAAgB,EACd,MAAA,OAAO,CAAC,gBAAgB,mCACxB,8BAA8B,CAAC;gBAC7B,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;gBAChC,4BAA4B;gBAC5B,2BAA2B;gBAC3B,yBAAyB;aAC1B,CAAC;SACL,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAEO,aAAa;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAoB,EAAE,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IACjG,CAAC;;AA7GM,+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"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { type Context } from '@opentelemetry/api';
|
|
2
2
|
import type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-web';
|
|
3
|
-
import type { UserActionStartMessage } from '@grafana/faro-web-sdk';
|
|
4
3
|
export declare class FaroUserActionSpanProcessor implements SpanProcessor {
|
|
5
4
|
private processor;
|
|
6
|
-
message: UserActionStartMessage | undefined;
|
|
7
5
|
constructor(processor: SpanProcessor);
|
|
8
6
|
forceFlush(): Promise<void>;
|
|
9
7
|
onStart(span: Span, parentContext: Context): void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { FaroTraceExporter } from './faroTraceExporter';
|
|
2
|
-
export { FaroSessionSpanProcessor } from './sessionSpanProcessor';
|
|
3
2
|
export { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
|
|
4
3
|
export { TracingInstrumentation } from './instrumentation';
|
|
5
4
|
export { getSamplingDecision } from './sampler';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/faro-web-tracing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta",
|
|
4
4
|
"description": "Faro web tracing implementation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observability",
|
|
@@ -32,34 +32,34 @@
|
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"start": "yarn watch",
|
|
35
|
-
"build": "run-s build:*",
|
|
36
|
-
"build:compile": "run-p build:compile:*",
|
|
35
|
+
"build": "run-s 'build:*'",
|
|
36
|
+
"build:compile": "run-p 'build:compile:*'",
|
|
37
37
|
"build:compile:cjs": "tsc --build tsconfig.cjs.json",
|
|
38
38
|
"build:compile:esm": "tsc --build tsconfig.esm.json",
|
|
39
|
-
"build:compile:bundle": "run-s build:compile:bundle:*",
|
|
39
|
+
"build:compile:bundle": "run-s 'build:compile:bundle:*'",
|
|
40
40
|
"build:compile:bundle:create": "rollup -c ./rollup.config.js",
|
|
41
41
|
"build:compile:bundle:remove-extras": "rimraf dist/bundle/dist",
|
|
42
42
|
"watch": "run-s watch:compile",
|
|
43
43
|
"watch:compile": "yarn build:compile:cjs -w",
|
|
44
44
|
"clean": "rimraf dist/ yarn-error.log",
|
|
45
|
-
"quality": "run-s quality:*",
|
|
45
|
+
"quality": "run-s 'quality:*'",
|
|
46
46
|
"quality:test": "jest",
|
|
47
47
|
"quality:format": "prettier --cache --cache-location=../../.cache/prettier/webTracing --ignore-path ../../.prettierignore -w \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
|
|
48
|
-
"quality:lint": "run-s quality:lint:*",
|
|
48
|
+
"quality:lint": "run-s 'quality:lint:*'",
|
|
49
49
|
"quality:lint:eslint": "eslint --cache --cache-location ../../.cache/eslint/webTracing --ignore-path ../../.eslintignore \"./**/*.{js,jsx,ts,tsx}\"",
|
|
50
50
|
"quality:lint:prettier": "prettier --cache --cache-location=../../.cache/prettier/webTracing --ignore-path ../../.prettierignore -c \"./**/*.{js,jsx,ts,tsx,css,scss,md,yaml,yml,json}\"",
|
|
51
51
|
"quality:lint:md": "markdownlint README.md",
|
|
52
52
|
"quality:circular-deps": "madge --circular ."
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@grafana/faro-web-sdk": "^
|
|
55
|
+
"@grafana/faro-web-sdk": "^2.0.0-beta",
|
|
56
56
|
"@opentelemetry/api": "^1.9.0",
|
|
57
57
|
"@opentelemetry/core": "^2.0.0",
|
|
58
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
59
|
-
"@opentelemetry/instrumentation": "^0.
|
|
60
|
-
"@opentelemetry/instrumentation-fetch": "^0.
|
|
61
|
-
"@opentelemetry/instrumentation-xml-http-request": "^0.
|
|
62
|
-
"@opentelemetry/otlp-transformer": "^0.
|
|
58
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
|
|
59
|
+
"@opentelemetry/instrumentation": "^0.203.0",
|
|
60
|
+
"@opentelemetry/instrumentation-fetch": "^0.203.0",
|
|
61
|
+
"@opentelemetry/instrumentation-xml-http-request": "^0.203.0",
|
|
62
|
+
"@opentelemetry/otlp-transformer": "^0.203.0",
|
|
63
63
|
"@opentelemetry/resources": "^2.0.0",
|
|
64
64
|
"@opentelemetry/sdk-trace-web": "^2.0.0",
|
|
65
65
|
"@opentelemetry/semantic-conventions": "^1.32.0"
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "45be1a46e697add78addde51fce36f14176afa62"
|
|
71
71
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Context } from '@opentelemetry/api';
|
|
2
|
-
import type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-web';
|
|
3
|
-
import type { Metas } from '@grafana/faro-web-sdk';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated
|
|
6
|
-
* please use FaroMetaAttributesSpanProcessor instead
|
|
7
|
-
*/
|
|
8
|
-
export declare class FaroSessionSpanProcessor implements SpanProcessor {
|
|
9
|
-
private processor;
|
|
10
|
-
private metas;
|
|
11
|
-
constructor(processor: SpanProcessor, metas: Metas);
|
|
12
|
-
forceFlush(): Promise<void>;
|
|
13
|
-
onStart(span: Span, parentContext: Context): void;
|
|
14
|
-
onEnd(span: ReadableSpan): void;
|
|
15
|
-
shutdown(): Promise<void>;
|
|
16
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FaroSessionSpanProcessor = void 0;
|
|
4
|
-
var semconv_1 = require("./semconv");
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated
|
|
7
|
-
* please use FaroMetaAttributesSpanProcessor instead
|
|
8
|
-
*/
|
|
9
|
-
var FaroSessionSpanProcessor = /** @class */ (function () {
|
|
10
|
-
function FaroSessionSpanProcessor(processor, metas) {
|
|
11
|
-
this.processor = processor;
|
|
12
|
-
this.metas = metas;
|
|
13
|
-
}
|
|
14
|
-
FaroSessionSpanProcessor.prototype.forceFlush = function () {
|
|
15
|
-
return this.processor.forceFlush();
|
|
16
|
-
};
|
|
17
|
-
FaroSessionSpanProcessor.prototype.onStart = function (span, parentContext) {
|
|
18
|
-
var session = this.metas.value.session;
|
|
19
|
-
if (session === null || session === void 0 ? void 0 : session.id) {
|
|
20
|
-
span.attributes[semconv_1.ATTR_SESSION_ID] = session.id;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated will be removed in the future and has been replaced by ATTR_SESSION_ID (session.id)
|
|
23
|
-
*/
|
|
24
|
-
span.attributes['session_id'] = session.id;
|
|
25
|
-
}
|
|
26
|
-
this.processor.onStart(span, parentContext);
|
|
27
|
-
};
|
|
28
|
-
FaroSessionSpanProcessor.prototype.onEnd = function (span) {
|
|
29
|
-
this.processor.onEnd(span);
|
|
30
|
-
};
|
|
31
|
-
FaroSessionSpanProcessor.prototype.shutdown = function () {
|
|
32
|
-
return this.processor.shutdown();
|
|
33
|
-
};
|
|
34
|
-
return FaroSessionSpanProcessor;
|
|
35
|
-
}());
|
|
36
|
-
exports.FaroSessionSpanProcessor = FaroSessionSpanProcessor;
|
|
37
|
-
//# sourceMappingURL=sessionSpanProcessor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sessionSpanProcessor.js","sourceRoot":"","sources":["../../src/sessionSpanProcessor.ts"],"names":[],"mappings":";;;AAKA,qCAA4C;AAE5C;;;GAGG;AACH;IACE,kCACU,SAAwB,EACxB,KAAY;QADZ,cAAS,GAAT,SAAS,CAAe;QACxB,UAAK,GAAL,KAAK,CAAO;IACnB,CAAC;IAEJ,6CAAU,GAAV;QACE,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;IAED,0CAAO,GAAP,UAAQ,IAAU,EAAE,aAAsB;QACxC,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;QAEzC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,EAAE,CAAC;YAChB,IAAI,CAAC,UAAU,CAAC,yBAAe,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;YAC9C;;eAEG;YACH,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;QAC7C,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,wCAAK,GAAL,UAAM,IAAkB;QACtB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,2CAAQ,GAAR;QACE,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IACH,+BAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,4DAAwB","sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-web';\n\nimport type { Metas } from '@grafana/faro-web-sdk';\n\nimport { ATTR_SESSION_ID } from './semconv';\n\n/**\n * @deprecated\n * please use FaroMetaAttributesSpanProcessor instead\n */\nexport class FaroSessionSpanProcessor implements SpanProcessor {\n constructor(\n private processor: SpanProcessor,\n private metas: Metas\n ) {}\n\n forceFlush(): Promise<void> {\n return this.processor.forceFlush();\n }\n\n onStart(span: Span, parentContext: Context): void {\n const session = this.metas.value.session;\n\n if (session?.id) {\n span.attributes[ATTR_SESSION_ID] = session.id;\n /**\n * @deprecated will be removed in the future and has been replaced by ATTR_SESSION_ID (session.id)\n */\n span.attributes['session_id'] = session.id;\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"]}
|