{"record":{"id":"fe3e4b7ae124cd86","repo":"microsoft/aspire","slug":"metric-exporter-w","errorCode":null,"errorMessage":"metric exporter: %w","messagePattern":"metric exporter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Templating/Templates/go-starter/api/telemetry.go","lineNumber":70,"sourceCode":"\t\ttraceOpts = append(traceOpts, otlptracegrpc.WithHeaders(headers))\n\t}\n\ttraceExp, err := otlptracegrpc.New(ctx, traceOpts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"trace exporter: %w\", err)\n\t}\n\ttp := sdktrace.NewTracerProvider(\n\t\tsdktrace.WithBatcher(traceExp),\n\t\tsdktrace.WithResource(res),\n\t)\n\totel.SetTracerProvider(tp)\n\n\tmetricOpts := []otlpmetricgrpc.Option{}\n\tif len(headers) > 0 {\n\t\tmetricOpts = append(metricOpts, otlpmetricgrpc.WithHeaders(headers))\n\t}\n\tmetricExp, err := otlpmetricgrpc.New(ctx, metricOpts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"metric exporter: %w\", err)\n\t}\n\tmp := sdkmetric.NewMeterProvider(\n\t\tsdkmetric.WithReader(sdkmetric.NewPeriodicReader(metricExp)),\n\t\tsdkmetric.WithResource(res),\n\t)\n\totel.SetMeterProvider(mp)\n\n\tif err := runtime.Start(runtime.WithMeterProvider(mp)); err != nil {\n\t\treturn nil, fmt.Errorf(\"runtime metrics: %w\", err)\n\t}\n\n\tlogOpts := []otlploggrpc.Option{}\n\tif len(headers) > 0 {\n\t\tlogOpts = append(logOpts, otlploggrpc.WithHeaders(headers))\n\t}\n\tlogExp, err := otlploggrpc.New(ctx, logOpts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"log exporter: %w\", err)","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Templating/Templates/go-starter/api/telemetry.go#L52-L88","documentation":"setupOTel wraps the error from otlpmetricgrpc.New, which builds the gRPC OTLP metric exporter. Creation fails when the OTLP endpoint/URL is invalid or exporter options (TLS, headers, timeout) are inconsistent. The wrap \"metric exporter: %w\" preserves the root cause.","triggerScenarios":"otlpmetricgrpc.New returns an error due to a malformed endpoint URL, invalid retry/timeout configuration, or bad TLS credentials, when setting up metrics via setupOTel.","commonSituations":"Wrong OTEL_EXPORTER_OTLP_ENDPOINT value, endpoint given as http://host:port while WithEndpoint expects host:port, misconfigured metrics collector address.","solutions":["Check the metrics OTLP endpoint for a valid scheme and host:port and log the unwrapped error.","Match the endpoint to the exporter type: use WithEndpoint(host:port) or WithEndpointURL(full url) consistently for the SDK version in use.","Verify the collector/dashboard metrics port is open and reachable.","Keep trace and metric exporters pointed at the same protocol (both grpc or both http)."],"exampleFix":"// before\nmetricExp, err := otlpmetricgrpc.New(ctx, metricOpts...)\nif err != nil {\n    return nil, fmt.Errorf(\"metric exporter: %w\", err)\n}\n// after\nif ep := os.Getenv(\"OTEL_EXPORTER_OTLP_ENDPOINT\"); ep == \"\" {\n    log.Println(\"OTEL_EXPORTER_OTLP_ENDPOINT not set; metrics disabled\")\n    return nil, nil\n}\nmetricExp, err := otlpmetricgrpc.New(ctx, metricOpts...)\nif err != nil {\n    return nil, fmt.Errorf(\"metric exporter: %w\", err)\n}","handlingStrategy":"validation","validationCode":"ep := os.Getenv(\"OTEL_EXPORTER_OTLP_ENDPOINT\")\nif u, err := url.Parse(ep); err != nil || u.Host == \"\" {\n    return fmt.Errorf(\"invalid metrics OTLP endpoint %q\", ep)\n}","typeGuard":null,"tryCatchPattern":"if err := setupOTel(...); err != nil {\n    log.Printf(\"metrics exporter unavailable: %v\", err) // degrade gracefully\n}","preventionTips":["Validate endpoint host:port before building the exporter.","Use the same endpoint style for all OTLP signals.","Confirm collector ports are open before startup.","Pin OTLP SDK versions."],"tags":["go","opentelemetry","grpc","metrics","telemetry"],"backgroundTag":"invalid-url-format","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}