UNPKG

@dash0hq/sdk-web

Version:

Dash0's Web SDK to collect telemetry from end-users' web browsers

19 lines (18 loc) 821 B
import { EVENT_NAME, LOG_SEVERITIES } from "../semantic-conventions"; import { sendLog } from "../transport"; import { addCommonAttributes } from "../attributes"; import { addAttribute, toAnyValue } from "../utils/otel"; import { nowNanos, toNanosTs } from "../utils"; export function sendEvent(name, opts) { const attributes = []; addCommonAttributes(attributes); Object.entries(opts?.attributes ?? {}).forEach(([key, value]) => addAttribute(attributes, key, value)); addAttribute(attributes, EVENT_NAME, name); sendLog({ timeUnixNano: opts?.timestamp != null ? toNanosTs(opts.timestamp) : nowNanos(), attributes, body: toAnyValue(opts?.data), severityText: opts?.severity, severityNumber: opts?.severity ? LOG_SEVERITIES[opts.severity] : undefined, }); }