dd-trace
Version:
Datadog APM tracing client for JavaScript
34 lines (30 loc) • 937 B
JavaScript
function headersToTextMap (msgHdrs) {
if (!msgHdrs || typeof msgHdrs[Symbol.iterator] !== 'function') return null
const textMap = {}
for (const [key, values] of msgHdrs) {
if (!Array.isArray(values) || values.length === 0) continue
// Trace headers are single-valued (injected via `set`, not `append`), so
// the first element is always the authoritative value.
textMap[key] = values[0]
}
return textMap
}
function getOperationName (type) {
switch (type) {
case 'publish':
return 'publish'
case 'request':
case 'requestMany':
return 'request'
default:
// Surface unrecognized operations explicitly rather than silently
// collapsing them into 'publish' — if NATS adds a new outbound API,
// this lets us see it in traces and fix the mapping deliberately.
return 'unknown'
}
}
module.exports = {
headersToTextMap,
getOperationName,
}