UNPKG

@grafana/faro-core

Version:
52 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeResourceSpans = mergeResourceSpans; exports.getTransportBody = getTransportBody; const const_1 = require("./const"); function mergeResourceSpans(traces, resourceSpans) { var _a, _b; if (resourceSpans === undefined) { return traces; } if (traces === undefined) { return { resourceSpans, }; } const currentResource = (_a = traces.resourceSpans) === null || _a === void 0 ? void 0 : _a[0]; if (currentResource === undefined) { return traces; } const currentSpans = (currentResource === null || currentResource === void 0 ? void 0 : currentResource.scopeSpans) || []; const newSpans = ((_b = resourceSpans === null || resourceSpans === void 0 ? void 0 : resourceSpans[0]) === null || _b === void 0 ? void 0 : _b.scopeSpans) || []; return Object.assign(Object.assign({}, traces), { resourceSpans: [ Object.assign(Object.assign({}, currentResource), { scopeSpans: [...currentSpans, ...newSpans] }), ] }); } function getTransportBody(item) { let body = { meta: {}, }; if (item[0] !== undefined) { body.meta = item[0].meta; } item.forEach((currentItem) => { switch (currentItem.type) { case const_1.TransportItemType.LOG: case const_1.TransportItemType.EVENT: case const_1.TransportItemType.EXCEPTION: case const_1.TransportItemType.MEASUREMENT: { const bk = const_1.transportItemTypeToBodyKey[currentItem.type]; const signals = body[bk]; body = Object.assign(Object.assign({}, body), { [bk]: signals === undefined ? [currentItem.payload] : [...signals, currentItem.payload] }); break; } case const_1.TransportItemType.TRACE: { body = Object.assign(Object.assign({}, body), { traces: mergeResourceSpans(body.traces, currentItem.payload.resourceSpans) }); break; } } }); return body; } //# sourceMappingURL=utils.js.map