@multiplayer-app/otlp-core
Version:
Multiplayer otlp core
41 lines • 1.3 kB
JavaScript
/**
* Trace Exporters for Web
*/
export class MultiplayerPostMessageExporter {
constructor({ targetWindow = window, targetOrigin = '*', type = 'MULTIPLAYER_SPANS', } = {}) {
this.targetWindow = targetWindow;
this.targetOrigin = targetOrigin;
this.type = type;
}
export(spans, resultCallback) {
try {
this.targetWindow.postMessage({
type: this.type,
payload: spans.map(span => this._serializeSpan(span)),
}, this.targetOrigin);
resultCallback({ code: 0 });
}
catch (e) {
console.error('[PostMessageExporter] export failed:', e);
resultCallback({ code: 1 });
}
}
shutdown() {
return Promise.resolve();
}
_serializeSpan(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,
};
}
}
//# sourceMappingURL=MultiplayerPostMessageExporter.js.map