@multiplayer-app/session-recorder-common 1.0.1-alpha.1 → 1.0.1-alpha.2

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.
@@ -1,8 +1,17 @@
1
1
  import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
2
- import { OTLPExporterConfigBase, OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';
3
- export interface SessionRecorderBrowserTraceExporterConfig extends OTLPExporterConfigBase {
2
+ export interface SessionRecorderBrowserTraceExporterConfig {
3
+ /** URL for the OTLP endpoint. Defaults to Multiplayer's default traces endpoint. */
4
+ url?: string;
4
5
  /** API key for authentication. Required. */
5
6
  apiKey: string;
7
+ /** Additional headers to include in requests */
8
+ headers?: Record<string, string>;
9
+ /** Request timeout in milliseconds */
10
+ timeoutMillis?: number;
11
+ /** Whether to use keep-alive connections */
12
+ keepAlive?: boolean;
13
+ /** Maximum number of concurrent requests */
14
+ concurrencyLimit?: number;
6
15
  /** Whether to use postMessage fallback for cross-origin requests */
7
16
  usePostMessageFallback?: boolean;
8
17
  /** PostMessage type identifier */
@@ -15,7 +24,8 @@ export interface SessionRecorderBrowserTraceExporterConfig extends OTLPExporterC
15
24
  * Exports traces via HTTP to Multiplayer's OTLP endpoint with browser-specific optimizations
16
25
  * Only exports spans with trace IDs starting with Multiplayer prefixes
17
26
  */
18
- export declare class SessionRecorderBrowserTraceExporter extends OTLPExporterBase<ReadableSpan[]> implements SpanExporter {
27
+ export declare class SessionRecorderBrowserTraceExporter implements SpanExporter {
28
+ private exporter;
19
29
  private usePostMessage;
20
30
  private readonly postMessageType;
21
31
  private readonly postMessageTargetOrigin;
@@ -27,5 +37,7 @@ export declare class SessionRecorderBrowserTraceExporter extends OTLPExporterBas
27
37
  shutdown(): Promise<void>;
28
38
  private exportViaPostMessage;
29
39
  private _serializeSpan;
40
+ private _createExporter;
41
+ setApiKey(apiKey: string): void;
30
42
  }
31
43
  //# sourceMappingURL=SessionRecorderBrowserTraceExporter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SessionRecorderBrowserTraceExporter.d.ts","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderBrowserTraceExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,mCAAmC,CAAA;AAU1C,MAAM,WAAW,yCACf,SAAQ,sBAAsB;IAC9B,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,kCAAkC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gCAAgC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC;AAED;;;;GAIG;AACH,qBAAa,mCACX,SAAQ,gBAAgB,CAAC,YAAY,EAAE,CACvC,YAAW,YAAY;IAEvB,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAQ;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;gBAEtD,MAAM,EAAE,yCAAyC;IA2FpD,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GAAG,IAAI;IA+BvF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,OAAO,CAAC,oBAAoB;IAqB5B,OAAO,CAAC,cAAc;CAwBvB"}
1
+ {"version":3,"file":"SessionRecorderBrowserTraceExporter.d.ts","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderBrowserTraceExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAQ1E,MAAM,WAAW,yCAAyC;IACxD,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,oEAAoE;IACpE,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,kCAAkC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gCAAgC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC;AAED;;;;GAIG;AACH,qBAAa,mCAAoC,YAAW,YAAY;IACtE,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAQ;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;gBAEtD,MAAM,EAAE,yCAAyC;IA2B7D,MAAM,CACJ,KAAK,EAAE,YAAY,EAAE,EACrB,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GACjD,IAAI;IA+BP,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,OAAO,CAAC,oBAAoB;IAqB5B,OAAO,CAAC,cAAc;IAyBtB,OAAO,CAAC,eAAe;IAevB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAKhC"}
@@ -1,18 +1,3 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
1
  var __assign = (this && this.__assign) || function () {
17
2
  __assign = Object.assign || function(t) {
18
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -24,120 +9,21 @@ var __assign = (this && this.__assign) || function () {
24
9
  };
25
10
  return __assign.apply(this, arguments);
26
11
  };
27
- var __rest = (this && this.__rest) || function (s, e) {
28
- var t = {};
29
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
- t[p] = s[p];
31
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
- t[p[i]] = s[p[i]];
35
- }
36
- return t;
37
- };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- import { OTLPExporterBase, } from '@opentelemetry/otlp-exporter-base';
55
- import { createLegacyOtlpBrowserExportDelegate, } from '@opentelemetry/otlp-exporter-base/browser-http';
12
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
56
13
  import { MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL, MULTIPLAYER_TRACE_DEBUG_PREFIX, MULTIPLAYER_TRACE_CONTINUOUS_DEBUG_PREFIX, } from '../constants/constants.base';
57
14
  /**
58
15
  * Browser-specific trace exporter for Session Recorder
59
16
  * Exports traces via HTTP to Multiplayer's OTLP endpoint with browser-specific optimizations
60
17
  * Only exports spans with trace IDs starting with Multiplayer prefixes
61
18
  */
62
- var SessionRecorderBrowserTraceExporter = /** @class */ (function (_super) {
63
- __extends(SessionRecorderBrowserTraceExporter, _super);
19
+ var SessionRecorderBrowserTraceExporter = /** @class */ (function () {
64
20
  function SessionRecorderBrowserTraceExporter(config) {
65
- var _this = this;
66
- var _a = config.url, url = _a === void 0 ? MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL : _a, apiKey = config.apiKey, _b = config.headers, headers = _b === void 0 ? {} : _b, _c = config.postMessageType, postMessageType = _c === void 0 ? 'MULTIPLAYER_SESSION_DEBUGGER_LIB' : _c, _d = config.postMessageTargetOrigin, postMessageTargetOrigin = _d === void 0 ? '*' : _d, restConfig = __rest(config, ["url", "apiKey", "headers", "postMessageType", "postMessageTargetOrigin"]);
67
- var _config = __assign(__assign({}, restConfig), { url: url, headers: __assign({ 'Content-Type': 'application/x-protobuf', 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0', 'Authorization': apiKey }, headers) });
68
- _this = _super.call(this, createLegacyOtlpBrowserExportDelegate(_config, {
69
- serializeRequest: function (spans) {
70
- // Create a simple trace service request structure
71
- var request = {
72
- resourceSpans: spans.map(function (span) { return ({
73
- resource: {
74
- attributes: Object.entries(span.resource.attributes).map(function (_a) {
75
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
76
- return ({
77
- key: key,
78
- value: { stringValue: String(value) },
79
- });
80
- }),
81
- },
82
- scopeSpans: [{
83
- spans: [{
84
- traceId: span.spanContext().traceId,
85
- spanId: span.spanContext().spanId,
86
- parentSpanId: span.spanContext().spanId, // Using spanId as fallback
87
- name: span.name,
88
- kind: span.kind,
89
- startTimeUnixNano: span.startTime[0] * 1e9 + span.startTime[1],
90
- endTimeUnixNano: span.endTime ? span.endTime[0] * 1e9 + span.endTime[1] : undefined,
91
- attributes: Object.entries(span.attributes).map(function (_a) {
92
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
93
- return ({
94
- key: key,
95
- value: { stringValue: String(value) },
96
- });
97
- }),
98
- events: span.events.map(function (event) { return ({
99
- timeUnixNano: event.time[0] * 1e9 + event.time[1],
100
- name: event.name,
101
- attributes: Object.entries(event.attributes || {}).map(function (_a) {
102
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
103
- return ({
104
- key: key,
105
- value: { stringValue: String(value) },
106
- });
107
- }),
108
- }); }),
109
- links: span.links.map(function (link) { return ({
110
- traceId: link.context.traceId,
111
- spanId: link.context.spanId,
112
- attributes: Object.entries(link.attributes || {}).map(function (_a) {
113
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
114
- return ({
115
- key: key,
116
- value: { stringValue: String(value) },
117
- });
118
- }),
119
- }); }),
120
- status: {
121
- code: span.status.code,
122
- message: span.status.message || '',
123
- },
124
- }],
125
- }],
126
- }); }),
127
- };
128
- var encoder = new TextEncoder();
129
- return encoder.encode(JSON.stringify(request));
130
- },
131
- deserializeResponse: function (arg) {
132
- var decoder = new TextDecoder();
133
- return JSON.parse(decoder.decode(arg));
134
- },
135
- }, 'v1/traces', { 'Content-Type': 'application/json' })) || this;
136
- _this.usePostMessage = false;
137
- _this.config = config;
138
- _this.postMessageType = postMessageType;
139
- _this.postMessageTargetOrigin = postMessageTargetOrigin;
140
- return _this;
21
+ this.usePostMessage = false;
22
+ var _a = config.url, url = _a === void 0 ? MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL : _a, apiKey = config.apiKey, _b = config.headers, headers = _b === void 0 ? {} : _b, _c = config.timeoutMillis, timeoutMillis = _c === void 0 ? 30000 : _c, _d = config.keepAlive, keepAlive = _d === void 0 ? true : _d, _e = config.concurrencyLimit, concurrencyLimit = _e === void 0 ? 20 : _e, _f = config.postMessageType, postMessageType = _f === void 0 ? 'MULTIPLAYER_SESSION_DEBUGGER_LIB' : _f, _g = config.postMessageTargetOrigin, postMessageTargetOrigin = _g === void 0 ? '*' : _g;
23
+ this.config = __assign(__assign({}, config), { url: url, apiKey: apiKey, headers: headers, timeoutMillis: timeoutMillis, keepAlive: keepAlive, concurrencyLimit: concurrencyLimit });
24
+ this.postMessageType = postMessageType;
25
+ this.postMessageTargetOrigin = postMessageTargetOrigin;
26
+ this.exporter = this._createExporter();
141
27
  }
142
28
  SessionRecorderBrowserTraceExporter.prototype.export = function (spans, resultCallback) {
143
29
  var _this = this;
@@ -156,7 +42,7 @@ var SessionRecorderBrowserTraceExporter = /** @class */ (function (_super) {
156
42
  this.exportViaPostMessage(filteredSpans, resultCallback);
157
43
  return;
158
44
  }
159
- _super.prototype.export.call(this, filteredSpans, function (result) {
45
+ this.exporter.export(filteredSpans, function (result) {
160
46
  if (result.code === 0) {
161
47
  resultCallback(result);
162
48
  }
@@ -170,7 +56,7 @@ var SessionRecorderBrowserTraceExporter = /** @class */ (function (_super) {
170
56
  });
171
57
  };
172
58
  SessionRecorderBrowserTraceExporter.prototype.shutdown = function () {
173
- return Promise.resolve();
59
+ return this.exporter.shutdown();
174
60
  };
175
61
  SessionRecorderBrowserTraceExporter.prototype.exportViaPostMessage = function (spans, resultCallback) {
176
62
  var _this = this;
@@ -191,6 +77,7 @@ var SessionRecorderBrowserTraceExporter = /** @class */ (function (_super) {
191
77
  }
192
78
  };
193
79
  SessionRecorderBrowserTraceExporter.prototype._serializeSpan = function (span) {
80
+ var _a;
194
81
  var spanContext = span.spanContext();
195
82
  return {
196
83
  _spanContext: spanContext,
@@ -204,7 +91,7 @@ var SessionRecorderBrowserTraceExporter = /** @class */ (function (_super) {
204
91
  startTime: span.startTime,
205
92
  duration: span.duration,
206
93
  attributes: span.attributes,
207
- parentSpanId: spanContext.spanId, // Using spanId as parentSpanId is not available in newer versions
94
+ parentSpanId: (_a = span.parentSpanContext) === null || _a === void 0 ? void 0 : _a.spanId,
208
95
  droppedAttributesCount: span.droppedAttributesCount,
209
96
  droppedEventsCount: span.droppedEventsCount,
210
97
  droppedLinksCount: span.droppedLinksCount,
@@ -214,7 +101,20 @@ var SessionRecorderBrowserTraceExporter = /** @class */ (function (_super) {
214
101
  },
215
102
  };
216
103
  };
104
+ SessionRecorderBrowserTraceExporter.prototype._createExporter = function () {
105
+ return new OTLPTraceExporter({
106
+ url: this.config.url,
107
+ headers: __assign({ 'Content-Type': 'application/x-protobuf', 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0', 'authorization': this.config.apiKey }, (this.config.headers || {})),
108
+ timeoutMillis: this.config.timeoutMillis,
109
+ keepAlive: this.config.keepAlive,
110
+ concurrencyLimit: this.config.concurrencyLimit,
111
+ });
112
+ };
113
+ SessionRecorderBrowserTraceExporter.prototype.setApiKey = function (apiKey) {
114
+ this.config.apiKey = apiKey;
115
+ this.exporter = this._createExporter();
116
+ };
217
117
  return SessionRecorderBrowserTraceExporter;
218
- }(OTLPExporterBase));
118
+ }());
219
119
  export { SessionRecorderBrowserTraceExporter };
220
120
  //# sourceMappingURL=SessionRecorderBrowserTraceExporter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SessionRecorderBrowserTraceExporter.js","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderBrowserTraceExporter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAEL,gBAAgB,GACjB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EACL,qCAAqC,GACtC,MAAM,gDAAgD,CAAA;AACvD,OAAO,EACL,iDAAiD,EACjD,8BAA8B,EAC9B,yCAAyC,GAC1C,MAAM,6BAA6B,CAAA;AAcpC;;;;GAIG;AACH;IACU,uDA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AAsB;YACnD,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,QAAQ,EAAE;gBACR,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU;gBACpC,sBAAsB,EAAE,IAAI,CAAC,QAAQ,CAAC,sBAAsB;aAC7D;SACF,CAAA;IACH,CAAC;IACH,0CAAC;AAAD,CAAC,AApLD,CACU,gBAAgB,GAmLzB","sourcesContent":["import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'\nimport {\n OTLPExporterConfigBase,\n OTLPExporterBase,\n} from '@opentelemetry/otlp-exporter-base'\nimport {\n createLegacyOtlpBrowserExportDelegate,\n} from '@opentelemetry/otlp-exporter-base/browser-http'\nimport {\n MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,\n MULTIPLAYER_TRACE_DEBUG_PREFIX,\n MULTIPLAYER_TRACE_CONTINUOUS_DEBUG_PREFIX,\n} from '../constants/constants.base'\n\nexport interface SessionRecorderBrowserTraceExporterConfig\n extends OTLPExporterConfigBase {\n /** API key for authentication. Required. */\n apiKey: string\n /** Whether to use postMessage fallback for cross-origin requests */\n usePostMessageFallback?: boolean\n /** PostMessage type identifier */\n postMessageType?: string\n /** PostMessage target origin */\n postMessageTargetOrigin?: string\n}\n\n/**\n * Browser-specific trace exporter for Session Recorder\n * Exports traces via HTTP to Multiplayer's OTLP endpoint with browser-specific optimizations\n * Only exports spans with trace IDs starting with Multiplayer prefixes\n */\nexport class SessionRecorderBrowserTraceExporter\n extends OTLPExporterBase<ReadableSpan[]>\n implements SpanExporter {\n\n private usePostMessage: boolean = false\n private readonly postMessageType: string\n private readonly postMessageTargetOrigin: string\n private readonly config: SessionRecorderBrowserTraceExporterConfig\n\n constructor(config: SessionRecorderBrowserTraceExporterConfig) {\n const {\n url = MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,\n apiKey,\n headers = {},\n postMessageType = 'MULTIPLAYER_SESSION_DEBUGGER_LIB',\n postMessageTargetOrigin = '*',\n ...restConfig\n } = config\n\n const _config = {\n ...restConfig,\n url,\n headers: {\n 'Content-Type': 'application/x-protobuf',\n 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',\n 'Authorization': apiKey,\n ...headers,\n },\n }\n\n super(\n createLegacyOtlpBrowserExportDelegate(\n _config,\n {\n serializeRequest: (spans: ReadableSpan[]) => {\n // Create a simple trace service request structure\n const request = {\n resourceSpans: spans.map(span => ({\n resource: {\n attributes: Object.entries(span.resource.attributes).map(([key, value]) => ({\n key,\n value: { stringValue: String(value) },\n })),\n },\n scopeSpans: [{\n spans: [{\n traceId: span.spanContext().traceId,\n spanId: span.spanContext().spanId,\n parentSpanId: span.spanContext().spanId, // Using spanId as fallback\n name: span.name,\n kind: span.kind,\n startTimeUnixNano: span.startTime[0] * 1e9 + span.startTime[1],\n endTimeUnixNano: span.endTime ? span.endTime[0] * 1e9 + span.endTime[1] : undefined,\n attributes: Object.entries(span.attributes).map(([key, value]) => ({\n key,\n value: { stringValue: String(value) },\n })),\n events: span.events.map(event => ({\n timeUnixNano: event.time[0] * 1e9 + event.time[1],\n name: event.name,\n attributes: Object.entries(event.attributes || {}).map(([key, value]) => ({\n key,\n value: { stringValue: String(value) },\n })),\n })),\n links: span.links.map(link => ({\n traceId: link.context.traceId,\n spanId: link.context.spanId,\n attributes: Object.entries(link.attributes || {}).map(([key, value]) => ({\n key,\n value: { stringValue: String(value) },\n })),\n })),\n status: {\n code: span.status.code,\n message: span.status.message || '',\n },\n }],\n }],\n })),\n }\n\n const encoder = new TextEncoder()\n return encoder.encode(JSON.stringify(request))\n },\n deserializeResponse: (arg: Uint8Array) => {\n const decoder = new TextDecoder()\n return JSON.parse(decoder.decode(arg))\n },\n },\n 'v1/traces',\n { 'Content-Type': 'application/json' },\n ),\n )\n\n this.config = config\n this.postMessageType = postMessageType\n this.postMessageTargetOrigin = postMessageTargetOrigin\n }\n\n override export(spans: ReadableSpan[], resultCallback: (result: { code: number }) => void): void {\n // Filter spans to only include those with Multiplayer trace prefixes\n const filteredSpans = spans.filter(span => {\n const traceId = span.spanContext().traceId\n return traceId.startsWith(MULTIPLAYER_TRACE_DEBUG_PREFIX) ||\n traceId.startsWith(MULTIPLAYER_TRACE_CONTINUOUS_DEBUG_PREFIX)\n })\n\n // Only proceed if there are filtered spans\n if (filteredSpans.length === 0) {\n resultCallback({ code: 0 })\n return\n }\n\n if (this.usePostMessage) {\n this.exportViaPostMessage(filteredSpans, resultCallback)\n return\n }\n\n super.export(filteredSpans, (result) => {\n if (result.code === 0) {\n resultCallback(result)\n } else if (this.config.usePostMessageFallback) {\n this.usePostMessage = true\n this.exportViaPostMessage(filteredSpans, resultCallback)\n } else {\n resultCallback(result)\n }\n })\n }\n\n override shutdown(): Promise<void> {\n return Promise.resolve()\n }\n\n private exportViaPostMessage(spans: ReadableSpan[], resultCallback: (result: { code: number }) => void): void {\n if (typeof window === 'undefined') {\n resultCallback({ code: 1 })\n return\n }\n\n try {\n window.postMessage(\n {\n action: 'traces',\n type: this.postMessageType,\n payload: spans.map(span => this._serializeSpan(span)),\n },\n this.postMessageTargetOrigin,\n )\n resultCallback({ code: 0 })\n } catch (e) {\n resultCallback({ code: 1 })\n }\n }\n\n private _serializeSpan(span: ReadableSpan): any {\n const spanContext = span.spanContext()\n return {\n _spanContext: spanContext,\n name: span.name,\n kind: span.kind,\n links: span.links,\n ended: span.ended,\n events: span.events,\n status: span.status,\n endTime: span.endTime,\n startTime: span.startTime,\n duration: span.duration,\n attributes: span.attributes,\n parentSpanId: spanContext.spanId, // Using spanId as parentSpanId is not available in newer versions\n droppedAttributesCount: span.droppedAttributesCount,\n droppedEventsCount: span.droppedEventsCount,\n droppedLinksCount: span.droppedLinksCount,\n resource: {\n attributes: span.resource.attributes,\n asyncAttributesPending: span.resource.asyncAttributesPending,\n },\n }\n }\n}\n"]}
1
+ {"version":3,"file":"SessionRecorderBrowserTraceExporter.js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AvB;QACE,OAAO,IAAI,iBAAiB,CAAC;YAC3B,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG;YACpB,OAAO,aACL,cAAc,EAAE,wBAAwB,EACxC,YAAY,EAAE,gDAAgD,EAC9D,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,IAChC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAC/B;YACD,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;YACxC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB;SAC/C,CAAC,CAAA;IACJ,CAAC;IAED,uDAAS,GAAT,UAAU,MAAc;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;QAE3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAA;IACxC,CAAC;IACH,0CAAC;AAAD,CAAC,AA1ID,IA0IC","sourcesContent":["import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'\nimport {\n MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,\n MULTIPLAYER_TRACE_DEBUG_PREFIX,\n MULTIPLAYER_TRACE_CONTINUOUS_DEBUG_PREFIX,\n} from '../constants/constants.base'\n\nexport interface SessionRecorderBrowserTraceExporterConfig {\n /** URL for the OTLP endpoint. Defaults to Multiplayer's default traces endpoint. */\n url?: string\n /** API key for authentication. Required. */\n apiKey: string\n /** Additional headers to include in requests */\n headers?: Record<string, string>\n /** Request timeout in milliseconds */\n timeoutMillis?: number\n /** Whether to use keep-alive connections */\n keepAlive?: boolean\n /** Maximum number of concurrent requests */\n concurrencyLimit?: number\n /** Whether to use postMessage fallback for cross-origin requests */\n usePostMessageFallback?: boolean\n /** PostMessage type identifier */\n postMessageType?: string\n /** PostMessage target origin */\n postMessageTargetOrigin?: string\n}\n\n/**\n * Browser-specific trace exporter for Session Recorder\n * Exports traces via HTTP to Multiplayer's OTLP endpoint with browser-specific optimizations\n * Only exports spans with trace IDs starting with Multiplayer prefixes\n */\nexport class SessionRecorderBrowserTraceExporter implements SpanExporter {\n private exporter: OTLPTraceExporter\n private usePostMessage: boolean = false\n private readonly postMessageType: string\n private readonly postMessageTargetOrigin: string\n private readonly config: SessionRecorderBrowserTraceExporterConfig\n\n constructor(config: SessionRecorderBrowserTraceExporterConfig) {\n const {\n url = MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,\n apiKey,\n headers = {},\n timeoutMillis = 30000,\n keepAlive = true,\n concurrencyLimit = 20,\n postMessageType = 'MULTIPLAYER_SESSION_DEBUGGER_LIB',\n postMessageTargetOrigin = '*',\n } = config\n\n this.config = {\n ...config,\n url,\n apiKey,\n headers,\n timeoutMillis,\n keepAlive,\n concurrencyLimit,\n }\n this.postMessageType = postMessageType\n this.postMessageTargetOrigin = postMessageTargetOrigin\n\n this.exporter = this._createExporter()\n }\n\n export(\n spans: ReadableSpan[],\n resultCallback: (result: { code: number }) => void,\n ): void {\n // Filter spans to only include those with Multiplayer trace prefixes\n const filteredSpans = spans.filter(span => {\n const traceId = span.spanContext().traceId\n return traceId.startsWith(MULTIPLAYER_TRACE_DEBUG_PREFIX) ||\n traceId.startsWith(MULTIPLAYER_TRACE_CONTINUOUS_DEBUG_PREFIX)\n })\n\n // Only proceed if there are filtered spans\n if (filteredSpans.length === 0) {\n resultCallback({ code: 0 })\n return\n }\n\n if (this.usePostMessage) {\n this.exportViaPostMessage(filteredSpans, resultCallback)\n return\n }\n\n this.exporter.export(filteredSpans, (result) => {\n if (result.code === 0) {\n resultCallback(result)\n } else if (this.config.usePostMessageFallback) {\n this.usePostMessage = true\n this.exportViaPostMessage(filteredSpans, resultCallback)\n } else {\n resultCallback(result)\n }\n })\n }\n\n shutdown(): Promise<void> {\n return this.exporter.shutdown()\n }\n\n private exportViaPostMessage(spans: ReadableSpan[], resultCallback: (result: { code: number }) => void): void {\n if (typeof window === 'undefined') {\n resultCallback({ code: 1 })\n return\n }\n\n try {\n window.postMessage(\n {\n action: 'traces',\n type: this.postMessageType,\n payload: spans.map(span => this._serializeSpan(span)),\n },\n this.postMessageTargetOrigin,\n )\n resultCallback({ code: 0 })\n } catch (e) {\n resultCallback({ code: 1 })\n }\n }\n\n private _serializeSpan(span: ReadableSpan): any {\n const spanContext = span.spanContext()\n return {\n _spanContext: spanContext,\n name: span.name,\n kind: span.kind,\n links: span.links,\n ended: span.ended,\n events: span.events,\n status: span.status,\n endTime: span.endTime,\n startTime: span.startTime,\n duration: span.duration,\n attributes: span.attributes,\n parentSpanId: span.parentSpanContext?.spanId,\n droppedAttributesCount: span.droppedAttributesCount,\n droppedEventsCount: span.droppedEventsCount,\n droppedLinksCount: span.droppedLinksCount,\n resource: {\n attributes: span.resource.attributes,\n asyncAttributesPending: span.resource.asyncAttributesPending,\n },\n }\n }\n\n private _createExporter(): OTLPTraceExporter {\n return new OTLPTraceExporter({\n url: this.config.url,\n headers: {\n 'Content-Type': 'application/x-protobuf',\n 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',\n 'authorization': this.config.apiKey,\n ...(this.config.headers || {}),\n },\n timeoutMillis: this.config.timeoutMillis,\n keepAlive: this.config.keepAlive,\n concurrencyLimit: this.config.concurrencyLimit,\n })\n }\n\n setApiKey(apiKey: string): void {\n this.config.apiKey = apiKey\n\n this.exporter = this._createExporter()\n }\n}\n"]}