UNPKG

@multiplayer-app/otlp-core

Version:

Multiplayer otlp core

45 lines 1.81 kB
/** * Trace Exporters for Web */ var MultiplayerPostMessageExporter = /** @class */ (function () { function MultiplayerPostMessageExporter(_a) { var _b = _a === void 0 ? {} : _a, _c = _b.targetWindow, targetWindow = _c === void 0 ? window : _c, _d = _b.targetOrigin, targetOrigin = _d === void 0 ? '*' : _d, _e = _b.type, type = _e === void 0 ? 'MULTIPLAYER_SPANS' : _e; this.targetWindow = targetWindow; this.targetOrigin = targetOrigin; this.type = type; } MultiplayerPostMessageExporter.prototype.export = function (spans, resultCallback) { var _this = this; try { this.targetWindow.postMessage({ type: this.type, payload: spans.map(function (span) { return _this._serializeSpan(span); }), }, this.targetOrigin); resultCallback({ code: 0 }); } catch (e) { console.error('[PostMessageExporter] export failed:', e); resultCallback({ code: 1 }); } }; MultiplayerPostMessageExporter.prototype.shutdown = function () { return Promise.resolve(); }; MultiplayerPostMessageExporter.prototype._serializeSpan = function (span) { return { traceId: span.spanContext().traceId, spanId: span.spanContext().spanId, parentSpanId: span.parentSpanId, name: span.name, startTime: span.startTime, endTime: span.endTime, attributes: span.attributes, events: span.events, status: span.status, resource: span.resource.attributes, }; }; return MultiplayerPostMessageExporter; }()); export { MultiplayerPostMessageExporter }; //# sourceMappingURL=MultiplayerPostMessageExporter.js.map