claude-code
claude-code copied to clipboard
[BUG] OTEL_EXPORTER_OTLP_METRICS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL not set breaking launch of Claude Code
Environment
- Claude CLI version: 1.0.31
- Operating System: macOS Intel Sequioa 15.4.1
- Terminal: kitty
Bug Description
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL and not set causing claude cli to not run/work
claude
file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:707
`);return Z(D,Y)},Q.push(G)}else if(I==="otlp"){let G=process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL?.trim()||process.env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim();switch(G){case"grpc":Q.push(new Vg0.OTLPMetricExporter);break;case"http/json":Q.push(new Cg0.OTLPMetricExporter);break;case"http/protobuf":Q.push(new Xg0.OTLPMetricExporter);break;default:throw new Error(`Unknown protocol set in OTEL_EXPORTER_OTLP_METRICS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL env var: ${G}`)}}else if(I==="prometheus")Q.push(new Kg0.PrometheusExporter);else throw new Error(`Unknown exporter type set in OTEL_EXPORTER_OTLP_METRICS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL env var: ${I}`);return Q.map((I)=>{if("export"in I)return new td1.PeriodicExportingMetricReader({exporter:I,exportIntervalMillis:B});return I})}function gW6(){let A=(process.env.OTEL_LOGS_EXPORTER||"").trim().split(",").filter(Boolean),B=[];for(let Q of A)if(Q==="console")B.push(new wh.ConsoleLogRecordExporter);else if(Q==="otlp"){let I=process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL?.trim()||process.env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim();switch(I){case"grpc":B.push(new zg0.OTLPLogExporter);break;case"http/json":B.push(new wg0.OTLPLogExporter);break;case"http/protobuf":B.push(new Hg0.OTLPLogExporter);break;default:throw new Error(`Unknown protocol set in OTEL_EXPORTER_OTLP_LOGS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL env var: ${I}`)}}else throw new Error(`Unknown exporter type set in OTEL_LOGS_EXPORTER env var: ${Q}`);return B}function Fg0(){return Boolean(process.env.CLAUDE_CODE_ENABLE_TELEMETRY)}function hW6(){let A=new rd1;return new td1.PeriodicExportingMetricReader({exporter:A,exportIntervalMillis:60000})}function mW6(){return!1}function Eg0(){vW6(),FY1.diag.setLogger(new sd1,FY1.DiagLogLevel.ERROR);let A=[];if(Fg0())A.push(...bW6());if(mW6())A.push(hW6());let B=Pr.resourceFromAttributes({[VY1.ATTR_SERVICE_NAME]:"claude-code",[VY1.ATTR_SERVICE_VERSION]:{ISSUES_EXPLAINER:"report the issue at https://github.com/anthropics/claude-code/issues",PACKAGE_URL:"@anthropic-ai/claude-code",README_URL:"https://docs.anthropic.com/s/claude-code",VERSION:"1.0.31"}.VERSION}),Q=Pr.envDetector.detect(),I=Pr.resourceFromAttributes(Q.attributes||{}),G=B.merge(I),Z=new XY1.MeterProvider({resource:G,views:[],readers:A});if(Fg0()){let Y=gW6();if(Y.length>0){let W=new wh.LoggerProvider({resource:G});for(let F of Y)W.addLogRecordProcessor(new wh.BatchLogRecordProcessor(F,{scheduledDelayMillis:parseInt(process.env.OTEL_LOGS_EXPORT_INTERVAL||fW6.toString())}));od1.logs.setGlobalLoggerProvider(W),I9A(W);let J=od1.logs.getLogger("com.anthropic.claude_code.events",{ISSUES_EXPLAINER:"report the issue at https://github.com/anthropics/claude-code/issues",PACKAGE_URL:"@anthropic-ai/claude-code",README_URL:"https://docs.anthropic.com/s/claude-code",VERSION:"1.0.31"}.VERSION);Z9A(J)}}return bG1(async()=>{let Y=parseInt(process.env.CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS||"1000");try{let W=[Z.shutdown()],J=Q9A();if(J)W.push(J.shutdown());await Promise.race([Promise.all(W),new Promise((F,X)=>setTimeout(()=>X(new Error("OpenTelemetry shutdown timeout")),Y))])}catch(W){if(W instanceof Error&&W.message.includes("timeout"))q6(`
^
Error: Unknown protocol set in OTEL_EXPORTER_OTLP_METRICS_PROTOCOL or OTEL_EXPORTER_OTLP_PROTOCOL env var: undefined
at bW6 (file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:707:354)
at Eg0 (file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:707:1799)
at jM6 (file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:716:1704)
at file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:716:1599
at Q (file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:526:17199)
at Pq5 (file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2489:9264)
at file:///Users/tommymallis/.local/share/fnm/node-versions/v22.6.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2501:3380
Noting that this was due to setting env in ~/claude/setting.json. I believe I got this from AI just generating this base file for me.
Removing the env key and values fixed the issue
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp"
},
@whoop-t Thanks! You saved my n hours 🥇
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.