MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getOTLPExporterConfig

Function getOTLPExporterConfig

src/utils/telemetry/instrumentation.ts:768–825  ·  view source on GitHub ↗

* Get configuration for OTLP exporters including: * - HTTP agent options (proxy, mTLS) * - Dynamic headers via otelHeadersHelper or static headers from env var

()

Source from the content-addressed store, hash-verified

766 * - Dynamic headers via otelHeadersHelper or static headers from env var
767 */
768function getOTLPExporterConfig() {
769 const proxyUrl = getProxyUrl()
770 const mtlsConfig = getMTLSConfig()
771 const settings = getSettings_DEPRECATED()
772
773 // Build base config
774 const config: Record<string, unknown> = {}
775
776 // Parse static headers from env var once (doesn't change at runtime)
777 const staticHeaders = parseOtelHeadersEnvVar()
778
779 // If otelHeadersHelper is configured, use async headers function for dynamic refresh
780 // Otherwise just return static headers if any exist
781 if (settings?.otelHeadersHelper) {
782 config.headers = async (): Promise<Record<string, string>> => {
783 const dynamicHeaders = getOtelHeadersFromHelper()
784 return { ...staticHeaders, ...dynamicHeaders }
785 }
786 } else if (Object.keys(staticHeaders).length > 0) {
787 config.headers = async (): Promise<Record<string, string>> => staticHeaders
788 }
789
790 // Check if we should bypass proxy for OTEL endpoint
791 const otelEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT
792 if (!proxyUrl || (otelEndpoint && shouldBypassProxy(otelEndpoint))) {
793 // No proxy configured or OTEL endpoint should bypass proxy
794 const caCerts = getCACertificates()
795 if (mtlsConfig || caCerts) {
796 config.httpAgentOptions = {
797 ...mtlsConfig,
798 ...(caCerts && { ca: caCerts }),
799 }
800 }
801 return config
802 }
803
804 // Return an HttpAgentFactory function that creates our proxy agent
805 const caCerts = getCACertificates()
806 const agentFactory = (_protocol: string) => {
807 // Create and return the proxy agent with mTLS and CA cert config
808 const proxyAgent =
809 mtlsConfig || caCerts
810 ? new HttpsProxyAgent(proxyUrl, {
811 ...(mtlsConfig && {
812 cert: mtlsConfig.cert,
813 key: mtlsConfig.key,
814 passphrase: mtlsConfig.passphrase,
815 }),
816 ...(caCerts && { ca: caCerts }),
817 })
818 : new HttpsProxyAgent(proxyUrl)
819
820 return proxyAgent
821 }
822
823 config.httpAgentOptions = agentFactory
824 return config
825}

Callers 3

getOtlpReadersFunction · 0.85
getOtlpLogExportersFunction · 0.85
getOtlpTraceExportersFunction · 0.85

Calls 5

getProxyUrlFunction · 0.85
parseOtelHeadersEnvVarFunction · 0.85
getOtelHeadersFromHelperFunction · 0.85
shouldBypassProxyFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected