@grafana/faro-web-tracing 1.3.8 → 1.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.
@@ -0,0 +1,2 @@
1
+ import { IResourceSpans } from '@opentelemetry/otlp-transformer';
2
+ export declare function sendFaroEvents(resourceSpans?: IResourceSpans[]): void;
@@ -2,4 +2,5 @@ export { FaroTraceExporter } from './faroTraceExporter';
2
2
  export { FaroSessionSpanProcessor } from './sessionSpanProcessor';
3
3
  export { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
4
4
  export { TracingInstrumentation } from './instrumentation';
5
+ export { getSamplingDecision } from './sampler';
5
6
  export type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';
@@ -0,0 +1,3 @@
1
+ import { SamplingDecision } from '@opentelemetry/sdk-trace-web';
2
+ import type { MetaSession } from '@grafana/faro-web-sdk';
3
+ export declare function getSamplingDecision(sessionMeta?: MetaSession): SamplingDecision;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FaroTraceExporter = void 0;
4
4
  var core_1 = require("@opentelemetry/core");
5
5
  var otlp_transformer_1 = require("@opentelemetry/otlp-transformer");
6
+ var faroTraceExporter_utils_1 = require("./faroTraceExporter.utils");
6
7
  var FaroTraceExporter = /** @class */ (function () {
7
8
  function FaroTraceExporter(config) {
8
9
  this.config = config;
@@ -10,6 +11,7 @@ var FaroTraceExporter = /** @class */ (function () {
10
11
  FaroTraceExporter.prototype.export = function (spans, resultCallback) {
11
12
  var traceEvent = (0, otlp_transformer_1.createExportTraceServiceRequest)(spans, { useHex: true, useLongBits: false });
12
13
  this.config.api.pushTraces(traceEvent);
14
+ (0, faroTraceExporter_utils_1.sendFaroEvents)(traceEvent.resourceSpans);
13
15
  resultCallback({ code: core_1.ExportResultCode.SUCCESS });
14
16
  };
15
17
  FaroTraceExporter.prototype.shutdown = function () {
@@ -1 +1 @@
1
- {"version":3,"file":"faroTraceExporter.js","sourceRoot":"","sources":["../../src/faroTraceExporter.ts"],"names":[],"mappings":";;;AAAA,4CAAuD;AAEvD,oEAAkF;AAKlF;IACE,2BAAoB,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;IAAG,CAAC;IAEvD,kCAAM,GAAN,UAAO,KAAqB,EAAE,cAA8C;QAC1E,IAAM,UAAU,GAAG,IAAA,kDAA+B,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;QAEhG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAEvC,cAAc,CAAC,EAAE,IAAI,EAAE,uBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,oCAAQ,GAAR;QACE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IACH,wBAAC;AAAD,CAAC,AAdD,IAcC;AAdY,8CAAiB","sourcesContent":["import { ExportResultCode } from '@opentelemetry/core';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { createExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-web';\n\nimport type { FaroTraceExporterConfig } from './types';\n\nexport class FaroTraceExporter implements SpanExporter {\n constructor(private config: FaroTraceExporterConfig) {}\n\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n const traceEvent = createExportTraceServiceRequest(spans, { useHex: true, useLongBits: false });\n\n this.config.api.pushTraces(traceEvent);\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve(undefined);\n }\n}\n"]}
1
+ {"version":3,"file":"faroTraceExporter.js","sourceRoot":"","sources":["../../src/faroTraceExporter.ts"],"names":[],"mappings":";;;AAAA,4CAAuD;AAEvD,oEAAkF;AAGlF,qEAA2D;AAG3D;IACE,2BAAoB,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;IAAG,CAAC;IAEvD,kCAAM,GAAN,UAAO,KAAqB,EAAE,cAA8C;QAC1E,IAAM,UAAU,GAAG,IAAA,kDAA+B,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;QAEhG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACvC,IAAA,wCAAc,EAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QAEzC,cAAc,CAAC,EAAE,IAAI,EAAE,uBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,oCAAQ,GAAR;QACE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IACH,wBAAC;AAAD,CAAC,AAfD,IAeC;AAfY,8CAAiB","sourcesContent":["import { ExportResultCode } from '@opentelemetry/core';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { createExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-web';\n\nimport { sendFaroEvents } from './faroTraceExporter.utils';\nimport type { FaroTraceExporterConfig } from './types';\n\nexport class FaroTraceExporter implements SpanExporter {\n constructor(private config: FaroTraceExporterConfig) {}\n\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n const traceEvent = createExportTraceServiceRequest(spans, { useHex: true, useLongBits: false });\n\n this.config.api.pushTraces(traceEvent);\n sendFaroEvents(traceEvent.resourceSpans);\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve(undefined);\n }\n}\n"]}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendFaroEvents = void 0;
4
+ var otlp_transformer_1 = require("@opentelemetry/otlp-transformer");
5
+ var faro_core_1 = require("@grafana/faro-core");
6
+ function sendFaroEvents(resourceSpans) {
7
+ var _a, _b;
8
+ if (resourceSpans === void 0) { resourceSpans = []; }
9
+ for (var _i = 0, resourceSpans_1 = resourceSpans; _i < resourceSpans_1.length; _i++) {
10
+ var resourceSpan = resourceSpans_1[_i];
11
+ var scopeSpans = resourceSpan.scopeSpans;
12
+ for (var _c = 0, scopeSpans_1 = scopeSpans; _c < scopeSpans_1.length; _c++) {
13
+ var scopeSpan = scopeSpans_1[_c];
14
+ var scope = scopeSpan.scope, _d = scopeSpan.spans, spans = _d === void 0 ? [] : _d;
15
+ for (var _e = 0, spans_1 = spans; _e < spans_1.length; _e++) {
16
+ var span = spans_1[_e];
17
+ if (span.kind !== otlp_transformer_1.ESpanKind.SPAN_KIND_CLIENT) {
18
+ continue;
19
+ }
20
+ var faroEventAttributes = {};
21
+ for (var _f = 0, _g = span.attributes; _f < _g.length; _f++) {
22
+ var attribute = _g[_f];
23
+ faroEventAttributes[attribute.key] = String(Object.values(attribute.value)[0]);
24
+ }
25
+ var index = ((_a = scope === null || scope === void 0 ? void 0 : scope.name) !== null && _a !== void 0 ? _a : '').indexOf('-');
26
+ var eventName = 'unknown';
27
+ if (scope === null || scope === void 0 ? void 0 : scope.name) {
28
+ if (index === -1) {
29
+ eventName = (_b = scope.name.split('/')[1]) !== null && _b !== void 0 ? _b : scope.name;
30
+ }
31
+ if (index > -1) {
32
+ eventName = scope === null || scope === void 0 ? void 0 : scope.name.substring(index + 1);
33
+ }
34
+ }
35
+ faro_core_1.faro.api.pushEvent("faro.tracing.".concat(eventName), faroEventAttributes, undefined, { skipDedupe: true });
36
+ }
37
+ }
38
+ }
39
+ }
40
+ exports.sendFaroEvents = sendFaroEvents;
41
+ //# sourceMappingURL=faroTraceExporter.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faroTraceExporter.utils.js","sourceRoot":"","sources":["../../src/faroTraceExporter.utils.ts"],"names":[],"mappings":";;;AAAA,oEAA4E;AA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AAC,mCAAI,KAAK,CAAC,IAAI,CAAC;qBACpD;oBAED,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;wBACd,SAAS,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;qBAC9C;iBACF;gBAED,gBAAI,CAAC,GAAG,CAAC,SAAS,CAAC,uBAAgB,SAAS,CAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;aACvG;SACF;KACF;AACH,CAAC;AAnCD,wCAmCC","sourcesContent":["import { ESpanKind, IResourceSpans } from '@opentelemetry/otlp-transformer';\n\nimport { faro } from '@grafana/faro-core';\nimport type { EventAttributes as FaroEventAttributes } from '@grafana/faro-web-sdk';\n\nexport function sendFaroEvents(resourceSpans: IResourceSpans[] = []) {\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 faroEventAttributes: FaroEventAttributes = {};\n\n for (const attribute of span.attributes) {\n faroEventAttributes[attribute.key] = String(Object.values(attribute.value)[0]);\n }\n\n const index = (scope?.name ?? '').indexOf('-');\n let eventName = 'unknown';\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 faro.api.pushEvent(`faro.tracing.${eventName}`, faroEventAttributes, undefined, { skipDedupe: true });\n }\n }\n }\n}\n"]}
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TracingInstrumentation = exports.getDefaultOTELInstrumentations = exports.FaroSessionSpanProcessor = exports.FaroTraceExporter = void 0;
3
+ exports.getSamplingDecision = exports.TracingInstrumentation = exports.getDefaultOTELInstrumentations = exports.FaroSessionSpanProcessor = 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
6
  var sessionSpanProcessor_1 = require("./sessionSpanProcessor");
@@ -9,4 +9,6 @@ var getDefaultOTELInstrumentations_1 = require("./getDefaultOTELInstrumentations
9
9
  Object.defineProperty(exports, "getDefaultOTELInstrumentations", { enumerable: true, get: function () { return getDefaultOTELInstrumentations_1.getDefaultOTELInstrumentations; } });
10
10
  var instrumentation_1 = require("./instrumentation");
11
11
  Object.defineProperty(exports, "TracingInstrumentation", { enumerable: true, get: function () { return instrumentation_1.TracingInstrumentation; } });
12
+ var sampler_1 = require("./sampler");
13
+ Object.defineProperty(exports, "getSamplingDecision", { enumerable: true, get: function () { return sampler_1.getSamplingDecision; } });
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAE1B,+DAAkE;AAAzD,gIAAA,wBAAwB,OAAA;AAEjC,mFAAkF;AAAzE,gJAAA,8BAA8B,OAAA;AAEvC,qDAA2D;AAAlD,yHAAA,sBAAsB,OAAA","sourcesContent":["export { FaroTraceExporter } from './faroTraceExporter';\n\nexport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\n\nexport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\n\nexport { TracingInstrumentation } from './instrumentation';\n\nexport type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAE1B,+DAAkE;AAAzD,gIAAA,wBAAwB,OAAA;AAEjC,mFAAkF;AAAzE,gJAAA,8BAA8B,OAAA;AAEvC,qDAA2D;AAAlD,yHAAA,sBAAsB,OAAA;AAE/B,qCAAgD;AAAvC,8GAAA,mBAAmB,OAAA","sourcesContent":["export { FaroTraceExporter } from './faroTraceExporter';\n\nexport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\n\nexport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\n\nexport { TracingInstrumentation } from './instrumentation';\n\nexport { getSamplingDecision } from './sampler';\n\nexport type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';\n"]}
@@ -26,6 +26,7 @@ var semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
26
26
  var faro_web_sdk_1 = require("@grafana/faro-web-sdk");
27
27
  var faroTraceExporter_1 = require("./faroTraceExporter");
28
28
  var getDefaultOTELInstrumentations_1 = require("./getDefaultOTELInstrumentations");
29
+ var sampler_1 = require("./sampler");
29
30
  var sessionSpanProcessor_1 = require("./sessionSpanProcessor");
30
31
  // the providing of app name here is not great
31
32
  // should delay initialization and provide the full Faro config,
@@ -41,6 +42,7 @@ var TracingInstrumentation = /** @class */ (function (_super) {
41
42
  return _this;
42
43
  }
43
44
  TracingInstrumentation.prototype.initialize = function () {
45
+ var _this = this;
44
46
  var _a, _b, _c, _d, _e;
45
47
  var options = this.options;
46
48
  var attributes = {};
@@ -55,7 +57,16 @@ var TracingInstrumentation = /** @class */ (function (_super) {
55
57
  }
56
58
  Object.assign(attributes, options.resourceAttributes);
57
59
  var resource = resources_1.Resource.default().merge(new resources_1.Resource(attributes));
58
- var provider = new sdk_trace_web_1.WebTracerProvider({ resource: resource });
60
+ var provider = new sdk_trace_web_1.WebTracerProvider({
61
+ resource: resource,
62
+ sampler: {
63
+ shouldSample: function () {
64
+ return {
65
+ decision: (0, sampler_1.getSamplingDecision)(_this.api.getSession()),
66
+ };
67
+ },
68
+ },
69
+ });
59
70
  provider.addSpanProcessor((_a = options.spanProcessor) !== null && _a !== void 0 ? _a : new sessionSpanProcessor_1.FaroSessionSpanProcessor(new sdk_trace_web_1.BatchSpanProcessor(new faroTraceExporter_1.FaroTraceExporter({ api: this.api }), {
60
71
  scheduledDelayMillis: TracingInstrumentation.SCHEDULED_BATCH_DELAY_MS,
61
72
  maxExportBatchSize: 30,
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0CAAoD;AACpD,4DAAiE;AACjE,4CAAgE;AAChE,kEAA0E;AAC1E,sDAAwE;AACxE,8DAAqF;AACrF,4EAAiF;AAEjF,sDAAgF;AAEhF,yDAAwD;AACxD,mFAAkF;AAClF,+DAAkE;AAGlE,8CAA8C;AAC9C,gEAAgE;AAChE,0BAA0B;AAE1B;IAA4C,0CAAmB;IAM7D,gCAAoB,OAA2C;QAA3C,wBAAA,EAAA,YAA2C;QAA/D,YACE,iBAAO,SACR;QAFmB,aAAO,GAAP,OAAO,CAAoC;QAL/D,UAAI,GAAG,2BAA2B,CAAC;QACnC,aAAO,GAAG,sBAAO,CAAC;;IAMlB,CAAC;IAED,2CAAU,GAAV;;QACE,IAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAM,UAAU,GAAuB,EAAE,CAAC;QAE1C,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;YACxB,UAAU,CAAC,iDAA0B,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;SAC5E;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE;YAC3B,UAAU,CAAC,iDAA0B,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;SAClF;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,EAA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;QACE,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,UAAC,SAAoB,IAAK,OAAA,SAAS,CAAC,aAAa,EAAE,EAAzB,CAAyB,CAAC,CAAC;IACjG,CAAC;IA1DM,+CAAwB,GAAG,IAAI,CAAC;IA2DzC,6BAAC;CAAA,AA/DD,CAA4C,kCAAmB,GA+D9D;AA/DY,wDAAsB","sourcesContent":["import { context, trace } from '@opentelemetry/api';\nimport { ZoneContextManager } from '@opentelemetry/context-zone';\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport { Resource, ResourceAttributes } from '@opentelemetry/resources';\nimport { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\n\nimport { BaseInstrumentation, Transport, VERSION } from '@grafana/faro-web-sdk';\n\nimport { FaroTraceExporter } from './faroTraceExporter';\nimport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\nimport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\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: ResourceAttributes = {};\n\n if (this.config.app.name) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = this.config.app.name;\n }\n\n if (this.config.app.version) {\n attributes[SemanticResourceAttributes.SERVICE_VERSION] = this.config.app.version;\n }\n\n if (this.config.app.environment) {\n attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;\n }\n\n Object.assign(attributes, options.resourceAttributes);\n\n const resource = Resource.default().merge(new Resource(attributes));\n\n const provider = new WebTracerProvider({ resource });\n\n provider.addSpanProcessor(\n options.spanProcessor ??\n new FaroSessionSpanProcessor(\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 provider.register({\n propagator: options.propagator ?? new W3CTraceContextPropagator(),\n contextManager: options.contextManager ?? new ZoneContextManager(),\n });\n\n registerInstrumentations({\n instrumentations:\n options.instrumentations ??\n getDefaultOTELInstrumentations({\n ignoreUrls: this.getIgnoreUrls(),\n propagateTraceHeaderCorsUrls: this.options.instrumentationOptions?.propagateTraceHeaderCorsUrls,\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
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0CAAoD;AACpD,4DAAiE;AACjE,4CAAgE;AAChE,kEAA0E;AAC1E,sDAAwE;AACxE,8DAAqF;AACrF,4EAAiF;AAEjF,sDAAgF;AAEhF,yDAAwD;AACxD,mFAAkF;AAClF,qCAAgD;AAChD,+DAAkE;AAGlE,8CAA8C;AAC9C,gEAAgE;AAChE,0BAA0B;AAE1B;IAA4C,0CAAmB;IAM7D,gCAAoB,OAA2C;QAA3C,wBAAA,EAAA,YAA2C;QAA/D,YACE,iBAAO,SACR;QAFmB,aAAO,GAAP,OAAO,CAAoC;QAL/D,UAAI,GAAG,2BAA2B,CAAC;QACnC,aAAO,GAAG,sBAAO,CAAC;;IAMlB,CAAC;IAED,2CAAU,GAAV;QAAA,iBAyDC;;QAxDC,IAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAM,UAAU,GAAuB,EAAE,CAAC;QAE1C,IAAI,IAA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,CAAC,QAAQ,CAAC;YAChB,UAAU,EAAE,MAAA,OAAO,CAAC,UAAU,mCAAI,IAAI,gCAAyB,EAAE;YACjE,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI,IAAI,iCAAkB,EAAE;SACnE,CAAC,CAAC;QAEH,IAAA,0CAAwB,EAAC;YACvB,gBAAgB,EACd,MAAA,OAAO,CAAC,gBAAgB,mCACxB,IAAA,+DAA8B,EAAC;gBAC7B,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;gBAChC,4BAA4B,EAAE,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,0CAAE,4BAA4B;aAChG,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;IAnEM,+CAAwB,GAAG,IAAI,CAAC;IAoEzC,6BAAC;CAAA,AAxED,CAA4C,kCAAmB,GAwE9D;AAxEY,wDAAsB","sourcesContent":["import { context, trace } from '@opentelemetry/api';\nimport { ZoneContextManager } from '@opentelemetry/context-zone';\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport { Resource, ResourceAttributes } from '@opentelemetry/resources';\nimport { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\n\nimport { BaseInstrumentation, Transport, VERSION } from '@grafana/faro-web-sdk';\n\nimport { FaroTraceExporter } from './faroTraceExporter';\nimport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\nimport { getSamplingDecision } from './sampler';\nimport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\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: ResourceAttributes = {};\n\n if (this.config.app.name) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = this.config.app.name;\n }\n\n if (this.config.app.version) {\n attributes[SemanticResourceAttributes.SERVICE_VERSION] = this.config.app.version;\n }\n\n if (this.config.app.environment) {\n attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;\n }\n\n Object.assign(attributes, options.resourceAttributes);\n\n const resource = Resource.default().merge(new Resource(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 });\n\n provider.addSpanProcessor(\n options.spanProcessor ??\n new FaroSessionSpanProcessor(\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 provider.register({\n propagator: options.propagator ?? new W3CTraceContextPropagator(),\n contextManager: options.contextManager ?? new ZoneContextManager(),\n });\n\n registerInstrumentations({\n instrumentations:\n options.instrumentations ??\n getDefaultOTELInstrumentations({\n ignoreUrls: this.getIgnoreUrls(),\n propagateTraceHeaderCorsUrls: this.options.instrumentationOptions?.propagateTraceHeaderCorsUrls,\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"]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSamplingDecision = void 0;
4
+ var sdk_trace_web_1 = require("@opentelemetry/sdk-trace-web");
5
+ function getSamplingDecision(sessionMeta) {
6
+ var _a;
7
+ if (sessionMeta === void 0) { sessionMeta = {}; }
8
+ var isSessionSampled = ((_a = sessionMeta.attributes) === null || _a === void 0 ? void 0 : _a['isSampled']) === 'true';
9
+ var samplingDecision = isSessionSampled ? sdk_trace_web_1.SamplingDecision.RECORD_AND_SAMPLED : sdk_trace_web_1.SamplingDecision.NOT_RECORD;
10
+ return samplingDecision;
11
+ }
12
+ exports.getSamplingDecision = getSamplingDecision;
13
+ //# sourceMappingURL=sampler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.js","sourceRoot":"","sources":["../../src/sampler.ts"],"names":[],"mappings":";;;AAAA,8DAAgE;AAIhE,SAAgB,mBAAmB,CAAC,WAA6B;;IAA7B,4BAAA,EAAA,gBAA6B;IAC/D,IAAM,gBAAgB,GAAG,CAAA,MAAA,WAAW,CAAC,UAAU,0CAAG,WAAW,CAAC,MAAK,MAAM,CAAC;IAC1E,IAAM,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,gCAAgB,CAAC,kBAAkB,CAAC,CAAC,CAAC,gCAAgB,CAAC,UAAU,CAAC;IAE9G,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AALD,kDAKC","sourcesContent":["import { SamplingDecision } from '@opentelemetry/sdk-trace-web';\n\nimport type { MetaSession } from '@grafana/faro-web-sdk';\n\nexport function getSamplingDecision(sessionMeta: MetaSession = {}): SamplingDecision {\n const isSessionSampled = sessionMeta.attributes?.['isSampled'] === 'true';\n const samplingDecision = isSessionSampled ? SamplingDecision.RECORD_AND_SAMPLED : SamplingDecision.NOT_RECORD;\n\n return samplingDecision;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { ExportResultCode } from '@opentelemetry/core';
2
2
  import { createExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
3
+ import { sendFaroEvents } from './faroTraceExporter.utils';
3
4
  export class FaroTraceExporter {
4
5
  constructor(config) {
5
6
  this.config = config;
@@ -7,6 +8,7 @@ export class FaroTraceExporter {
7
8
  export(spans, resultCallback) {
8
9
  const traceEvent = createExportTraceServiceRequest(spans, { useHex: true, useLongBits: false });
9
10
  this.config.api.pushTraces(traceEvent);
11
+ sendFaroEvents(traceEvent.resourceSpans);
10
12
  resultCallback({ code: ExportResultCode.SUCCESS });
11
13
  }
12
14
  shutdown() {
@@ -1 +1 @@
1
- {"version":3,"file":"faroTraceExporter.js","sourceRoot":"","sources":["../../src/faroTraceExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAKlF,MAAM,OAAO,iBAAiB;IAC5B,YAAoB,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;IAAG,CAAC;IAEvD,MAAM,CAAC,KAAqB,EAAE,cAA8C;QAC1E,MAAM,UAAU,GAAG,+BAA+B,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;QAEhG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAEvC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,QAAQ;QACN,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;CACF","sourcesContent":["import { ExportResultCode } from '@opentelemetry/core';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { createExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-web';\n\nimport type { FaroTraceExporterConfig } from './types';\n\nexport class FaroTraceExporter implements SpanExporter {\n constructor(private config: FaroTraceExporterConfig) {}\n\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n const traceEvent = createExportTraceServiceRequest(spans, { useHex: true, useLongBits: false });\n\n this.config.api.pushTraces(traceEvent);\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve(undefined);\n }\n}\n"]}
1
+ {"version":3,"file":"faroTraceExporter.js","sourceRoot":"","sources":["../../src/faroTraceExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAGlF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,MAAM,OAAO,iBAAiB;IAC5B,YAAoB,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;IAAG,CAAC;IAEvD,MAAM,CAAC,KAAqB,EAAE,cAA8C;QAC1E,MAAM,UAAU,GAAG,+BAA+B,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;QAEhG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACvC,cAAc,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QAEzC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,QAAQ;QACN,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;CACF","sourcesContent":["import { ExportResultCode } from '@opentelemetry/core';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { createExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-web';\n\nimport { sendFaroEvents } from './faroTraceExporter.utils';\nimport type { FaroTraceExporterConfig } from './types';\n\nexport class FaroTraceExporter implements SpanExporter {\n constructor(private config: FaroTraceExporterConfig) {}\n\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n const traceEvent = createExportTraceServiceRequest(spans, { useHex: true, useLongBits: false });\n\n this.config.api.pushTraces(traceEvent);\n sendFaroEvents(traceEvent.resourceSpans);\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve(undefined);\n }\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import { ESpanKind } from '@opentelemetry/otlp-transformer';
2
+ import { faro } from '@grafana/faro-core';
3
+ export function sendFaroEvents(resourceSpans = []) {
4
+ var _a, _b;
5
+ for (const resourceSpan of resourceSpans) {
6
+ const { scopeSpans } = resourceSpan;
7
+ for (const scopeSpan of scopeSpans) {
8
+ const { scope, spans = [] } = scopeSpan;
9
+ for (const span of spans) {
10
+ if (span.kind !== ESpanKind.SPAN_KIND_CLIENT) {
11
+ continue;
12
+ }
13
+ const faroEventAttributes = {};
14
+ for (const attribute of span.attributes) {
15
+ faroEventAttributes[attribute.key] = String(Object.values(attribute.value)[0]);
16
+ }
17
+ const index = ((_a = scope === null || scope === void 0 ? void 0 : scope.name) !== null && _a !== void 0 ? _a : '').indexOf('-');
18
+ let eventName = 'unknown';
19
+ if (scope === null || scope === void 0 ? void 0 : scope.name) {
20
+ if (index === -1) {
21
+ eventName = (_b = scope.name.split('/')[1]) !== null && _b !== void 0 ? _b : scope.name;
22
+ }
23
+ if (index > -1) {
24
+ eventName = scope === null || scope === void 0 ? void 0 : scope.name.substring(index + 1);
25
+ }
26
+ }
27
+ faro.api.pushEvent(`faro.tracing.${eventName}`, faroEventAttributes, undefined, { skipDedupe: true });
28
+ }
29
+ }
30
+ }
31
+ }
32
+ //# sourceMappingURL=faroTraceExporter.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faroTraceExporter.utils.js","sourceRoot":"","sources":["../../src/faroTraceExporter.utils.ts"],"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L,KAAK,CAAE,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;qBAC9C;iBACF;gBAED,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,gBAAgB,SAAS,EAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;aACvG;SACF;KACF;AACH,CAAC","sourcesContent":["import { ESpanKind, IResourceSpans } from '@opentelemetry/otlp-transformer';\n\nimport { faro } from '@grafana/faro-core';\nimport type { EventAttributes as FaroEventAttributes } from '@grafana/faro-web-sdk';\n\nexport function sendFaroEvents(resourceSpans: IResourceSpans[] = []) {\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 faroEventAttributes: FaroEventAttributes = {};\n\n for (const attribute of span.attributes) {\n faroEventAttributes[attribute.key] = String(Object.values(attribute.value)[0]);\n }\n\n const index = (scope?.name ?? '').indexOf('-');\n let eventName = 'unknown';\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 faro.api.pushEvent(`faro.tracing.${eventName}`, faroEventAttributes, undefined, { skipDedupe: true });\n }\n }\n }\n}\n"]}
package/dist/esm/index.js CHANGED
@@ -2,4 +2,5 @@ export { FaroTraceExporter } from './faroTraceExporter';
2
2
  export { FaroSessionSpanProcessor } from './sessionSpanProcessor';
3
3
  export { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
4
4
  export { TracingInstrumentation } from './instrumentation';
5
+ export { getSamplingDecision } from './sampler';
5
6
  //# sourceMappingURL=index.js.map
@@ -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,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { FaroTraceExporter } from './faroTraceExporter';\n\nexport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\n\nexport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\n\nexport { TracingInstrumentation } from './instrumentation';\n\nexport type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { FaroTraceExporter } from './faroTraceExporter';\n\nexport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\n\nexport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\n\nexport { TracingInstrumentation } from './instrumentation';\n\nexport { getSamplingDecision } from './sampler';\n\nexport type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';\n"]}
@@ -8,6 +8,7 @@ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
8
8
  import { BaseInstrumentation, VERSION } from '@grafana/faro-web-sdk';
9
9
  import { FaroTraceExporter } from './faroTraceExporter';
10
10
  import { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
11
+ import { getSamplingDecision } from './sampler';
11
12
  import { FaroSessionSpanProcessor } from './sessionSpanProcessor';
12
13
  // the providing of app name here is not great
13
14
  // should delay initialization and provide the full Faro config,
@@ -34,7 +35,16 @@ export class TracingInstrumentation extends BaseInstrumentation {
34
35
  }
35
36
  Object.assign(attributes, options.resourceAttributes);
36
37
  const resource = Resource.default().merge(new Resource(attributes));
37
- const provider = new WebTracerProvider({ resource });
38
+ const provider = new WebTracerProvider({
39
+ resource,
40
+ sampler: {
41
+ shouldSample: () => {
42
+ return {
43
+ decision: getSamplingDecision(this.api.getSession()),
44
+ };
45
+ },
46
+ },
47
+ });
38
48
  provider.addSpanProcessor((_a = options.spanProcessor) !== null && _a !== void 0 ? _a : new FaroSessionSpanProcessor(new BatchSpanProcessor(new FaroTraceExporter({ api: this.api }), {
39
49
  scheduledDelayMillis: TracingInstrumentation.SCHEDULED_BATCH_DELAY_MS,
40
50
  maxExportBatchSize: 30,
@@ -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;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,C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AAiB,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE;YAC/D,oBAAoB,EAAE,sBAAsB,CAAC,wBAAwB;YACrE,kBAAkB,EAAE,EAAE;SACvB,CAAC,EACF,IAAI,CAAC,KAAK,CACX,CACJ,CAAC;QAEF,QAAQ,CAAC,QAAQ,CAAC;YAChB,UAAU,EAAE,MAAA,OAAO,CAAC,UAAU,mCAAI,IAAI,yBAAyB,EAAE;YACjE,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI,IAAI,kBAAkB,EAAE;SACnE,CAAC,CAAC;QAEH,wBAAwB,CAAC;YACvB,gBAAgB,EACd,MAAA,OAAO,CAAC,gBAAgB,mCACxB,8BAA8B,CAAC;gBAC7B,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;gBAChC,4BAA4B,EAAE,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,0CAAE,4BAA4B;aAChG,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;;AA1DM,+CAAwB,GAAG,IAAI,CAAC","sourcesContent":["import { context, trace } from '@opentelemetry/api';\nimport { ZoneContextManager } from '@opentelemetry/context-zone';\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport { Resource, ResourceAttributes } from '@opentelemetry/resources';\nimport { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\n\nimport { BaseInstrumentation, Transport, VERSION } from '@grafana/faro-web-sdk';\n\nimport { FaroTraceExporter } from './faroTraceExporter';\nimport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\nimport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\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: ResourceAttributes = {};\n\n if (this.config.app.name) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = this.config.app.name;\n }\n\n if (this.config.app.version) {\n attributes[SemanticResourceAttributes.SERVICE_VERSION] = this.config.app.version;\n }\n\n if (this.config.app.environment) {\n attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;\n }\n\n Object.assign(attributes, options.resourceAttributes);\n\n const resource = Resource.default().merge(new Resource(attributes));\n\n const provider = new WebTracerProvider({ resource });\n\n provider.addSpanProcessor(\n options.spanProcessor ??\n new FaroSessionSpanProcessor(\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 provider.register({\n propagator: options.propagator ?? new W3CTraceContextPropagator(),\n contextManager: options.contextManager ?? new ZoneContextManager(),\n });\n\n registerInstrumentations({\n instrumentations:\n options.instrumentations ??\n getDefaultOTELInstrumentations({\n ignoreUrls: this.getIgnoreUrls(),\n propagateTraceHeaderCorsUrls: this.options.instrumentationOptions?.propagateTraceHeaderCorsUrls,\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
+ {"version":3,"file":"instrumentation.js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kB,EAAE;SACnE,CAAC,CAAC;QAEH,wBAAwB,CAAC;YACvB,gBAAgB,EACd,MAAA,OAAO,CAAC,gBAAgB,mCACxB,8BAA8B,CAAC;gBAC7B,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;gBAChC,4BAA4B,EAAE,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,0CAAE,4BAA4B;aAChG,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;;AAnEM,+CAAwB,GAAG,IAAI,CAAC","sourcesContent":["import { context, trace } from '@opentelemetry/api';\nimport { ZoneContextManager } from '@opentelemetry/context-zone';\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport { Resource, ResourceAttributes } from '@opentelemetry/resources';\nimport { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\n\nimport { BaseInstrumentation, Transport, VERSION } from '@grafana/faro-web-sdk';\n\nimport { FaroTraceExporter } from './faroTraceExporter';\nimport { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';\nimport { getSamplingDecision } from './sampler';\nimport { FaroSessionSpanProcessor } from './sessionSpanProcessor';\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: ResourceAttributes = {};\n\n if (this.config.app.name) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = this.config.app.name;\n }\n\n if (this.config.app.version) {\n attributes[SemanticResourceAttributes.SERVICE_VERSION] = this.config.app.version;\n }\n\n if (this.config.app.environment) {\n attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT] = this.config.app.environment;\n }\n\n Object.assign(attributes, options.resourceAttributes);\n\n const resource = Resource.default().merge(new Resource(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 });\n\n provider.addSpanProcessor(\n options.spanProcessor ??\n new FaroSessionSpanProcessor(\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 provider.register({\n propagator: options.propagator ?? new W3CTraceContextPropagator(),\n contextManager: options.contextManager ?? new ZoneContextManager(),\n });\n\n registerInstrumentations({\n instrumentations:\n options.instrumentations ??\n getDefaultOTELInstrumentations({\n ignoreUrls: this.getIgnoreUrls(),\n propagateTraceHeaderCorsUrls: this.options.instrumentationOptions?.propagateTraceHeaderCorsUrls,\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"]}
@@ -0,0 +1,8 @@
1
+ import { SamplingDecision } from '@opentelemetry/sdk-trace-web';
2
+ export function getSamplingDecision(sessionMeta = {}) {
3
+ var _a;
4
+ const isSessionSampled = ((_a = sessionMeta.attributes) === null || _a === void 0 ? void 0 : _a['isSampled']) === 'true';
5
+ const samplingDecision = isSessionSampled ? SamplingDecision.RECORD_AND_SAMPLED : SamplingDecision.NOT_RECORD;
6
+ return samplingDecision;
7
+ }
8
+ //# sourceMappingURL=sampler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.js","sourceRoot":"","sources":["../../src/sampler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIhE,MAAM,UAAU,mBAAmB,CAAC,cAA2B,EAAE;;IAC/D,MAAM,gBAAgB,GAAG,CAAA,MAAA,WAAW,CAAC,UAAU,0CAAG,WAAW,CAAC,MAAK,MAAM,CAAC;IAC1E,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,CAAC,gBAAgB,CAAC,UAAU,CAAC;IAE9G,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import { SamplingDecision } from '@opentelemetry/sdk-trace-web';\n\nimport type { MetaSession } from '@grafana/faro-web-sdk';\n\nexport function getSamplingDecision(sessionMeta: MetaSession = {}): SamplingDecision {\n const isSessionSampled = sessionMeta.attributes?.['isSampled'] === 'true';\n const samplingDecision = isSessionSampled ? SamplingDecision.RECORD_AND_SAMPLED : SamplingDecision.NOT_RECORD;\n\n return samplingDecision;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { IResourceSpans } from '@opentelemetry/otlp-transformer';
2
+ export declare function sendFaroEvents(resourceSpans?: IResourceSpans[]): void;
@@ -2,4 +2,5 @@ export { FaroTraceExporter } from './faroTraceExporter';
2
2
  export { FaroSessionSpanProcessor } from './sessionSpanProcessor';
3
3
  export { getDefaultOTELInstrumentations } from './getDefaultOTELInstrumentations';
4
4
  export { TracingInstrumentation } from './instrumentation';
5
+ export { getSamplingDecision } from './sampler';
5
6
  export type { FaroTraceExporterConfig, TracingInstrumentationOptions } from './types';
@@ -0,0 +1,3 @@
1
+ import { SamplingDecision } from '@opentelemetry/sdk-trace-web';
2
+ import type { MetaSession } from '@grafana/faro-web-sdk';
3
+ export declare function getSamplingDecision(sessionMeta?: MetaSession): SamplingDecision;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/faro-web-tracing",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
4
4
  "description": "Faro web tracing implementation.",
5
5
  "keywords": [
6
6
  "observability",
@@ -43,7 +43,7 @@
43
43
  "watch:compile": "yarn build:compile:cjs -w",
44
44
  "clean": "rimraf dist/ yarn-error.log",
45
45
  "quality": "run-s quality:*",
46
- "quality:test": "exit 0",
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
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}\"",
@@ -52,7 +52,7 @@
52
52
  "quality:circular-deps": "madge --circular ."
53
53
  },
54
54
  "dependencies": {
55
- "@grafana/faro-web-sdk": "^1.3.8",
55
+ "@grafana/faro-web-sdk": "^1.4.0",
56
56
  "@opentelemetry/api": "^1.7.0",
57
57
  "@opentelemetry/context-zone": "^1.18.1",
58
58
  "@opentelemetry/core": "^1.18.1",
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "6de2e06ee87af72a251966854284491f307341fb"
72
+ "gitHead": "2bf7781829e3d8dc5a0e51547e07daf4177b0844"
73
73
  }