@multiplayer-app/session-recorder-common 1.1.0 → 1.1.1-alpha.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.
Files changed (26) hide show
  1. package/dist/esm/exporters/SessionRecorderBrowserTraceExporter.d.ts +2 -2
  2. package/dist/esm/exporters/SessionRecorderBrowserTraceExporter.d.ts.map +1 -1
  3. package/dist/esm/exporters/SessionRecorderBrowserTraceExporter.js +2 -1
  4. package/dist/esm/exporters/SessionRecorderBrowserTraceExporter.js.map +1 -1
  5. package/dist/esm/exporters/SessionRecorderHttpTraceExporter.d.ts.map +1 -1
  6. package/dist/esm/exporters/SessionRecorderHttpTraceExporter.js +14 -5
  7. package/dist/esm/exporters/SessionRecorderHttpTraceExporter.js.map +1 -1
  8. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  9. package/dist/esnext/exporters/SessionRecorderBrowserTraceExporter.d.ts +2 -2
  10. package/dist/esnext/exporters/SessionRecorderBrowserTraceExporter.d.ts.map +1 -1
  11. package/dist/esnext/exporters/SessionRecorderBrowserTraceExporter.js +2 -2
  12. package/dist/esnext/exporters/SessionRecorderBrowserTraceExporter.js.map +1 -1
  13. package/dist/esnext/exporters/SessionRecorderHttpTraceExporter.d.ts.map +1 -1
  14. package/dist/esnext/exporters/SessionRecorderHttpTraceExporter.js +3 -5
  15. package/dist/esnext/exporters/SessionRecorderHttpTraceExporter.js.map +1 -1
  16. package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
  17. package/dist/src/exporters/SessionRecorderBrowserTraceExporter.d.ts +2 -2
  18. package/dist/src/exporters/SessionRecorderBrowserTraceExporter.d.ts.map +1 -1
  19. package/dist/src/exporters/SessionRecorderBrowserTraceExporter.js +2 -2
  20. package/dist/src/exporters/SessionRecorderBrowserTraceExporter.js.map +1 -1
  21. package/dist/src/exporters/SessionRecorderHttpTraceExporter.d.ts.map +1 -1
  22. package/dist/src/exporters/SessionRecorderHttpTraceExporter.js +3 -5
  23. package/dist/src/exporters/SessionRecorderHttpTraceExporter.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/exporters/SessionRecorderBrowserTraceExporter.ts +3 -4
  26. package/src/exporters/SessionRecorderHttpTraceExporter.ts +3 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SessionRecorderBrowserTraceExporter.js","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderBrowserTraceExporter.ts"],"names":[],"mappings":";;;AACA,sFAA2E;AAC3E,gEAIoC;AAuBpC;;;;GAIG;AACH,MAAa,mCAAmC;IAO9C,YAAY,MAAiD;QALrD,mBAAc,GAAY,KAAK,CAAA;QAMrC,MAAM,EACJ,GAAG,GAAG,kEAAiD,EACvD,MAAM,EACN,OAAO,GAAG,EAAE,EACZ,aAAa,GAAG,KAAK,EACrB,SAAS,GAAG,IAAI,EAChB,gBAAgB,GAAG,EAAE,EACrB,eAAe,GAAG,kCAAkC,EACpD,uBAAuB,GAAG,GAAG,GAC9B,GAAG,MAAM,CAAA;QAEV,IAAI,CAAC,MAAM,mCACN,MAAM,KACT,GAAG;YACH,MAAM;YACN,OAAO;YACP,aAAa;YACb,SAAS;YACT,gBAAgB,GACjB,CAAA;QACD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAA;QAEtD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAA;IACxC,CAAC;IAED,MAAM,CACJ,KAAqB,EACrB,cAAkD;QAElD,qEAAqE;QACrE,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACxC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAA;YAC1C,OAAO,OAAO,CAAC,UAAU,CAAC,+CAA8B,CAAC;gBACvD,OAAO,CAAC,UAAU,CAAC,0DAAyC,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;QAEF,2CAA2C;Q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I,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,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;QAE3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAA;IACxC,CAAC;CACF;AA1ID,kFA0IC","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/json',\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"]}
1
+ {"version":3,"file":"SessionRecorderBrowserTraceExporter.js","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderBrowserTraceExporter.ts"],"names":[],"mappings":";;;AACA,sFAA2E;AAC3E,gEAIoC;AAuBpC;;;;GAIG;AACH,MAAa,mCAAmC;IAO9C,YAAY,SAAoD,EAAE;QAL1D,mBAAc,GAAY,KAAK,CAAA;QAMrC,MAAM,EACJ,GAAG,GAAG,kEAAiD,EACvD,MAAM,EACN,OAAO,GAAG,EAAE,EACZ,aAAa,GAAG,KAAK,EACrB,SAAS,GAAG,IAAI,EAChB,gBAAgB,GAAG,EAAE,EACrB,eAAe,GAAG,kCAAkC,EACpD,uBAAuB,GAAG,GAAG,GAC9B,GAAG,MAAM,CAAA;QAEV,IAAI,CAAC,MAAM,mCACN,MAAM,KACT,GA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;YAC3B,YAAY,EAAE,MAAA,IAAI,CAAC,iBAAiB,0CAAE,MAAM;YAC5C,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;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;IAEO,eAAe;QACrB,OAAO,IAAI,4CAAiB,CAAC;YAC3B,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG;YACpB,OAAO,gCACL,cAAc,EAAE,kBAAkB,IAC/B,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GACnE,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,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;QAE3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAA;IACxC,CAAC;CACF;AAzID,kFAyIC","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/json',\n ...(this.config.apiKey ? { '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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SessionRecorderHttpTraceExporter.d.ts","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderHttpTraceExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAO3E,MAAM,WAAW,sCAAsC;IACrD,+FAA+F;IAC/F,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED;;;;GAIG;AACH,qBAAa,gCAAiC,SAAQ,iBAAiB;gBACzD,MAAM,EAAE,sCAAsC;IAsBjD,MAAM,CACb,KAAK,EAAE,GAAG,EAAE,EACZ,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GACjD,IAAI;CAcR"}
1
+ {"version":3,"file":"SessionRecorderHttpTraceExporter.d.ts","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderHttpTraceExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAO3E,MAAM,WAAW,sCAAsC;IACrD,+FAA+F;IAC/F,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED;;;;GAIG;AACH,qBAAa,gCAAiC,SAAQ,iBAAiB;gBACzD,MAAM,EAAE,sCAAsC;IAwBjD,MAAM,CACb,KAAK,EAAE,GAAG,EAAE,EACZ,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GACjD,IAAI;CAcR"}
@@ -13,11 +13,9 @@ class SessionRecorderHttpTraceExporter extends exporter_trace_otlp_http_1.OTLPTr
13
13
  const { url = constants_base_1.MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL, apiKey, timeoutMillis = 30000, keepAlive = true, concurrencyLimit = 20, } = config;
14
14
  super({
15
15
  url,
16
- headers: {
17
- 'Content-Type': 'application/json',
18
- 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',
19
- 'Authorization': apiKey,
20
- },
16
+ headers: Object.assign({ 'Content-Type': 'application/json', 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0' }, apiKey
17
+ ? { 'Authorization': apiKey }
18
+ : {}),
21
19
  timeoutMillis,
22
20
  keepAlive,
23
21
  concurrencyLimit,
@@ -1 +1 @@
1
- {"version":3,"file":"SessionRecorderHttpTraceExporter.js","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderHttpTraceExporter.ts"],"names":[],"mappings":";;;AAAA,sFAA2E;AAC3E,gEAIoC;AAepC;;;;GAIG;AACH,MAAa,gCAAiC,SAAQ,4CAAiB;IACrE,YAAY,MAA8C;QACxD,MAAM,EACJ,GAAG,GAAG,kEAAiD,EACvD,MAAM,EACN,aAAa,GAAG,KAAK,EACrB,SAAS,GAAG,IAAI,EAChB,gBAAgB,GAAG,EAAE,GACtB,GAAG,MAAM,CAAA;QAEV,KAAK,CAAC;YACJ,GAAG;YACH,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,gDAAgD;gBAC9D,eAAe,EAAE,MAAM;aACxB;YACD,aAAa;YACb,SAAS;YACT,gBAAgB;SACjB,CAAC,CAAA;IACJ,CAAC;IAEQ,MAAM,CACb,KAAY,EACZ,cAAkD;QAElD,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACxC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAA;YAC1C,OAAO,OAAO,CAAC,UAAU,CAAC,+CAA8B,CAAC;gBACvD,OAAO,CAAC,UAAU,CAAC,0DAAyC,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;QAEF,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;YAC3B,OAAM;QACR,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;IAC7C,CAAC;CACF;AAxCD,4EAwCC","sourcesContent":["import { 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 SessionRecorderHttpTraceExporterConfig {\n /** The URL to send traces to. Defaults to MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL */\n url?: string\n /** API key for authentication. Required. */\n apiKey: string\n /** Timeout for HTTP requests in milliseconds. Defaults to 30000 */\n timeoutMillis?: number\n /** Whether to keep the connection alive. Defaults to true */\n keepAlive?: boolean\n /** Maximum number of concurrent requests. Defaults to 20 */\n concurrencyLimit?: number\n}\n\n/**\n * HTTP trace exporter for Session Recorder\n * Exports traces via HTTP to Multiplayer's OTLP endpoint\n * Only exports spans with trace IDs starting with Multiplayer prefixes\n */\nexport class SessionRecorderHttpTraceExporter extends OTLPTraceExporter {\n constructor(config: SessionRecorderHttpTraceExporterConfig) {\n const {\n url = MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,\n apiKey,\n timeoutMillis = 30000,\n keepAlive = true,\n concurrencyLimit = 20,\n } = config\n\n super({\n url,\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',\n 'Authorization': apiKey,\n },\n timeoutMillis,\n keepAlive,\n concurrencyLimit,\n })\n }\n\n override export(\n spans: any[],\n resultCallback: (result: { code: number }) => void,\n ): void {\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 if (filteredSpans.length === 0) {\n resultCallback({ code: 0 })\n return\n }\n\n super.export(filteredSpans, resultCallback)\n }\n}\n"]}
1
+ {"version":3,"file":"SessionRecorderHttpTraceExporter.js","sourceRoot":"","sources":["../../../src/exporters/SessionRecorderHttpTraceExporter.ts"],"names":[],"mappings":";;;AAAA,sFAA2E;AAC3E,gEAIoC;AAepC;;;;GAIG;AACH,MAAa,gCAAiC,SAAQ,4CAAiB;IACrE,YAAY,MAA8C;QACxD,MAAM,EACJ,GAAG,GAAG,kEAAiD,EACvD,MAAM,EACN,aAAa,GAAG,KAAK,EACrB,SAAS,GAAG,IAAI,EAChB,gBAAgB,GAAG,EAAE,GACtB,GAAG,MAAM,CAAA;QAEV,KAAK,CAAC;YACJ,GAAG;YACH,OAAO,kBACL,cAAc,EAAE,kBAAkB,EAClC,YAAY,EAAE,gDAAgD,IAC3D,MAAM;gBACP,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE;gBAC7B,CAAC,CAAC,EAAE,CACP;YACD,aAAa;YACb,SAAS;YACT,gBAAgB;SACjB,CAAC,CAAA;IACJ,CAAC;IAEQ,MAAM,CACb,KAAY,EACZ,cAAkD;QAElD,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACxC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAA;YAC1C,OAAO,OAAO,CAAC,UAAU,CAAC,+CAA8B,CAAC;gBACvD,OAAO,CAAC,UAAU,CAAC,0DAAyC,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;QAEF,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;YAC3B,OAAM;QACR,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;IAC7C,CAAC;CACF;AA1CD,4EA0CC","sourcesContent":["import { 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 SessionRecorderHttpTraceExporterConfig {\n /** The URL to send traces to. Defaults to MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL */\n url?: string\n /** API key for authentication. Required. */\n apiKey: string\n /** Timeout for HTTP requests in milliseconds. Defaults to 30000 */\n timeoutMillis?: number\n /** Whether to keep the connection alive. Defaults to true */\n keepAlive?: boolean\n /** Maximum number of concurrent requests. Defaults to 20 */\n concurrencyLimit?: number\n}\n\n/**\n * HTTP trace exporter for Session Recorder\n * Exports traces via HTTP to Multiplayer's OTLP endpoint\n * Only exports spans with trace IDs starting with Multiplayer prefixes\n */\nexport class SessionRecorderHttpTraceExporter extends OTLPTraceExporter {\n constructor(config: SessionRecorderHttpTraceExporterConfig) {\n const {\n url = MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,\n apiKey,\n timeoutMillis = 30000,\n keepAlive = true,\n concurrencyLimit = 20,\n } = config\n\n super({\n url,\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',\n ...apiKey\n ? { 'Authorization': apiKey }\n : {},\n },\n timeoutMillis,\n keepAlive,\n concurrencyLimit,\n })\n }\n\n override export(\n spans: any[],\n resultCallback: (result: { code: number }) => void,\n ): void {\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 if (filteredSpans.length === 0) {\n resultCallback({ code: 0 })\n return\n }\n\n super.export(filteredSpans, resultCallback)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplayer-app/session-recorder-common",
3
- "version": "1.1.0",
3
+ "version": "1.1.1-alpha.0",
4
4
  "description": "Multiplayer Fullstack Session Recorder - opentelemetry",
5
5
  "author": {
6
6
  "name": "Multiplayer Software, Inc.",
@@ -10,7 +10,7 @@ export interface SessionRecorderBrowserTraceExporterConfig {
10
10
  /** URL for the OTLP endpoint. Defaults to Multiplayer's default traces endpoint. */
11
11
  url?: string
12
12
  /** API key for authentication. Required. */
13
- apiKey: string
13
+ apiKey?: string
14
14
  /** Additional headers to include in requests */
15
15
  headers?: Record<string, string>
16
16
  /** Request timeout in milliseconds */
@@ -39,7 +39,7 @@ export class SessionRecorderBrowserTraceExporter implements SpanExporter {
39
39
  private readonly postMessageTargetOrigin: string
40
40
  private readonly config: SessionRecorderBrowserTraceExporterConfig
41
41
 
42
- constructor(config: SessionRecorderBrowserTraceExporterConfig) {
42
+ constructor(config: SessionRecorderBrowserTraceExporterConfig = {}) {
43
43
  const {
44
44
  url = MULTIPLAYER_OTEL_DEFAULT_TRACES_EXPORTER_HTTP_URL,
45
45
  apiKey,
@@ -155,8 +155,7 @@ export class SessionRecorderBrowserTraceExporter implements SpanExporter {
155
155
  url: this.config.url,
156
156
  headers: {
157
157
  'Content-Type': 'application/json',
158
- 'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',
159
- 'Authorization': this.config.apiKey,
158
+ ...(this.config.apiKey ? { 'Authorization': this.config.apiKey } : {}),
160
159
  ...(this.config.headers || {}),
161
160
  },
162
161
  timeoutMillis: this.config.timeoutMillis,
@@ -38,7 +38,9 @@ export class SessionRecorderHttpTraceExporter extends OTLPTraceExporter {
38
38
  headers: {
39
39
  'Content-Type': 'application/json',
40
40
  'User-Agent': '@multiplayer-app/session-recorder-common/1.0.0',
41
- 'Authorization': apiKey,
41
+ ...apiKey
42
+ ? { 'Authorization': apiKey }
43
+ : {},
42
44
  },
43
45
  timeoutMillis,
44
46
  keepAlive,