MCPcopy Create free account
hub / github.com/Noumena-Network/code / getOtelHeadersFromHelper

Function getOtelHeadersFromHelper

src/utils/auth.ts:2048–2118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2046const DEFAULT_OTEL_HEADERS_DEBOUNCE_MS = 29 * 60 * 1000 // 29 minutes
2047
2048export function getOtelHeadersFromHelper(): Record<string, string> {
2049 const otelHeadersHelper = getConfiguredOtelHeadersHelper()
2050
2051 if (!otelHeadersHelper) {
2052 return {}
2053 }
2054
2055 // Return cached headers if still valid (debounce)
2056 const debounceMs = parseInt(
2057 process.env.CLAUDE_CODE_OTEL_HEADERS_HELPER_DEBOUNCE_MS ||
2058 DEFAULT_OTEL_HEADERS_DEBOUNCE_MS.toString(),
2059 )
2060 if (
2061 cachedOtelHeaders &&
2062 Date.now() - cachedOtelHeadersTimestamp < debounceMs
2063 ) {
2064 return cachedOtelHeaders
2065 }
2066
2067 if (isOtelHeadersHelperFromProjectOrLocalSettings()) {
2068 // Check if trust has been established for this project
2069 const hasTrust = checkHasTrustDialogAccepted()
2070 if (!hasTrust) {
2071 return {}
2072 }
2073 }
2074
2075 try {
2076 const result = execSyncWithDefaults_DEPRECATED(otelHeadersHelper, {
2077 timeout: 30000, // 30 seconds - allows for auth service latency
2078 })
2079 ?.toString()
2080 .trim()
2081 if (!result) {
2082 throw new Error('otelHeadersHelper did not return a valid value')
2083 }
2084
2085 const headers = jsonParse(result)
2086 if (
2087 typeof headers !== 'object' ||
2088 headers === null ||
2089 Array.isArray(headers)
2090 ) {
2091 throw new Error(
2092 'otelHeadersHelper must return a JSON object with string key-value pairs',
2093 )
2094 }
2095
2096 // Validate all values are strings
2097 for (const [key, value] of Object.entries(headers)) {
2098 if (typeof value !== 'string') {
2099 throw new Error(
2100 `otelHeadersHelper returned non-string value for key "${key}": ${typeof value}`,
2101 )
2102 }
2103 }
2104
2105 // Cache the result

Callers 1

Calls 9

jsonParseFunction · 0.85
entriesMethod · 0.80
logErrorFunction · 0.70
errorMessageFunction · 0.70
toStringMethod · 0.65

Tested by

no test coverage detected