{"record":{"id":"5dbc7c16175c7b0d","repo":"microsoft/aspire","slug":"trace-exporter-w","errorCode":null,"errorMessage":"trace exporter: %w","messagePattern":"trace exporter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Templating/Templates/go-starter/api/telemetry.go","lineNumber":56,"sourceCode":"\t\tresource.Default(),\n\t\tresource.NewWithAttributes(\n\t\t\tsemconv.SchemaURL,\n\t\t\tsemconv.ServiceName(serviceName),\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"otel resource: %w\", err)\n\t}\n\n\theaders := otlpHeaders()\n\n\ttraceOpts := []otlptracegrpc.Option{}\n\tif len(headers) > 0 {\n\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),","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Templating/Templates/go-starter/api/telemetry.go#L38-L74","documentation":"setupOTel wraps the error from otlptracegrpc.New, which constructs the gRPC OTLP trace exporter. This exporter creation can fail when the configured OTLP endpoint URL is malformed or unsupported, or when a required dependency (e.g. TLS credentials) is invalid. The error is wrapped with \"trace exporter: %w\" so the underlying cause is preserved.","triggerScenarios":"Calling setupOTel with an invalid otlpEndpoint (e.g. missing scheme, unsupported scheme such as http:// vs grpc target parsing) causes otlptracegrpc.New to return an error; also caused by invalid TLS/credentials options.","commonSituations":"Misconfigured OTEL_EXPORTER_OTLP_ENDPOINT / endpoint URL in the AppHost environment, wrong scheme format passed through headers/endpoint wiring, or switching exporter protocol (grpc vs http) without updating the endpoint.","solutions":["Verify the OTLP endpoint URL has a valid scheme (http:// or https://) and host:port.","Print the underlying error (%v of the wrapped err) to see the exact gRPC/URL failure.","Ensure the exporter/collector (e.g. Aspire dashboard OTLP endpoint) is reachable and the address is correct.","Confirm the OTLP Go SDK versions match (go.opentelemetry.io/otel + otlp exporters)."],"exampleFix":"// before\ntraceExp, err := otlptracegrpc.New(ctx, traceOpts...)\n// after\nendpoint := os.Getenv(\"OTEL_EXPORTER_OTLP_ENDPOINT\")\nu, err := url.Parse(endpoint)\nif err != nil || u.Scheme == \"\" {\n    log.Fatalf(\"invalid OTLP endpoint %q: %v\", endpoint, err)\n}\ntraceOpts = append(traceOpts, otlptracegrpc.WithEndpoint(u.Host))\ntraceExp, err := otlptracegrpc.New(ctx, traceOpts...)","handlingStrategy":"validation","validationCode":"ep := os.Getenv(\"OTEL_EXPORTER_OTLP_ENDPOINT\")\nif u, err := url.Parse(ep); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid OTLP endpoint %q\", ep)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    return nil, fmt.Errorf(\"trace exporter: %w\", err)\n}\n// caller:\nif err := setupOTel(...); err != nil {\n    log.Printf(\"otel setup failed, continuing without traces: %v\", err)\n}","preventionTips":["Always launch via the AppHost so OTEL endpoint env vars are valid.","Use url.Parse to validate the endpoint before exporter construction.","Keep OTLP Go SDK exporter versions aligned.","Log wrapped errors to surface root causes."],"tags":["go","opentelemetry","grpc","telemetry","url"],"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"}