{"record":{"id":"9260e229eb442aaa","repo":"microsoft/aspire","slug":"otel-resource-w","errorCode":null,"errorMessage":"otel resource: %w","messagePattern":"otel resource: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Templating/Templates/go-starter/api/telemetry.go","lineNumber":45,"sourceCode":")\n\n// setupOTel returns a shutdown func that flushes pending telemetry.\nfunc setupOTel(ctx context.Context, serviceName string) (func(context.Context) error, error) {\n\tif os.Getenv(\"OTEL_EXPORTER_OTLP_ENDPOINT\") == \"\" {\n\t\t// No exporter configured — install no-op providers so the app still runs\n\t\t// (e.g., outside of `aspire run`).\n\t\treturn func(context.Context) error { return nil }, nil\n\t}\n\n\tres, err := resource.Merge(\n\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","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Templating/Templates/go-starter/api/telemetry.go#L27-L63","documentation":"setupOTel wraps a failure from the OpenTelemetry SDK's resource.Merge/resource.NewWithAttributes call: building the identifying resource (service.name etc.) that is attached to traces, metrics, and logs. A wrapped \"otel resource: %w\" error means the telemetry resource could not be constructed, so the starter API aborts startup before installing providers.","triggerScenarios":"resource.Merge returns an error — in practice when the default resource detection (OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME env parsing, host/OS detectors) produces conflicting schema URLs or invalid attributes, merged with the semconv v1.40.0 resource built here in the go-starter template's main().","commonSituations":"Malformed OTEL_RESOURCE_ATTRIBUTES or OTEL_SERVICE_NAME environment variables injected alongside OTEL_EXPORTER_OTLP_ENDPOINT; conflicting schema URLs between resource.Default() and the explicit semconv.SchemaURL after an OTel SDK version upgrade; corrupted env in containers where Aspire injects OTLP config.","solutions":["Inspect and fix OTEL_RESOURCE_ATTRIBUTES / OTEL_SERVICE_NAME env values (must be valid key=value pairs per the OTel spec)","Align the OTel SDK and semconv package versions so resource.Default()'s schema URL matches semconv.SchemaURL (upgrade both together)","Unset conflicting OTEL_RESOURCE_ATTRIBUTES temporarily to confirm the env var is the cause","As a last resort, construct the resource solely with resource.NewWithAttributes instead of merging with resource.Default()"],"exampleFix":"// before\nres, err := resource.Merge(resource.Default(), resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceName(serviceName)))\nif err != nil {\n\treturn nil, fmt.Errorf(\"otel resource: %w\", err)\n}\n\n// after\n// e.g. fix the injected env first:\n// OTEL_RESOURCE_ATTRIBUTES=service.namespace=aspire  (valid k=v list)\n// or skip conflicting defaults:\nres, err := resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceName(serviceName))\nif err != nil {\n\treturn nil, fmt.Errorf(\"otel resource: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if attrs := os.Getenv(\"OTEL_RESOURCE_ATTRIBUTES\"); !validOTelAttrs(attrs) {\n\treturn errors.New(\"invalid OTEL_RESOURCE_ATTRIBUTES\")\n}","typeGuard":null,"tryCatchPattern":"shutdown, err := setupOTel(ctx, serviceName)\nif err != nil {\n\t// optional: log and continue without telemetry\n\tlog.Printf(\"telemetry disabled: %v\", err)\n\tshutdown = func(context.Context) error { return nil }\n}","preventionTips":["Keep OTel SDK and semconv package versions aligned","Validate OTEL_RESOURCE_ATTRIBUTES/OTEL_SERVICE_NAME env values","Fail-soft: consider running without telemetry instead of aborting startup","Pin the OTel resource schema URL consistently across exporters"],"tags":["go","opentelemetry","telemetry","resource","configuration"],"backgroundTag":"invalid-config-value","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"}