UNPKG

@grafana/faro-transport-otlp-http

Version:

Faro transport which converts the Faro data model to the Otlp data model.

44 lines 1.44 kB
import { isArray, isBoolean, isInt, isNumber, isObject, isString } from '@grafana/faro-core'; export function toAttributeValue(value) { if (isString(value)) { return { stringValue: value }; } if (isInt(value)) { return { intValue: value }; } if (isNumber(value)) { return { doubleValue: value }; } if (isBoolean(value)) { return { boolValue: value }; } if (isArray(value)) { return { arrayValue: { values: value.map(toAttributeValue) } }; } if (value instanceof Uint8Array) { return { bytesValue: value }; } if (isObject(value)) { return { kvlistValue: { values: Object.entries(value) .map(([attributeName, attributeValue]) => toAttribute(attributeName, attributeValue)) .filter(isAttribute), }, }; } return {}; } export function toAttribute(attributeName, attributeValue) { if (attributeValue == null || attributeValue === '') { return undefined; } return { key: attributeName, value: toAttributeValue(attributeValue), }; } export function isAttribute(item) { return Boolean(item) && typeof (item === null || item === void 0 ? void 0 : item.key) === 'string' && typeof (item === null || item === void 0 ? void 0 : item.value) !== 'undefined'; } //# sourceMappingURL=attributeUtils.js.map