{"record":{"id":"de2377e856766494","repo":"caddyserver/caddy","slug":"building-otlp-metrics-resource-w","errorCode":null,"errorMessage":"building OTLP metrics resource: %w","messagePattern":"building OTLP metrics resource: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/metrics.go","lineNumber":202,"sourceCode":"\t// NewMetricReader. It is NOT a MetricOption and must not be passed as one.\n\t// Users can still override the source by setting OTEL_METRICS_PRODUCERS.\n\treg := ctx.GetMetricsRegistry()\n\tautoexport.WithFallbackMetricProducer(func(context.Context) (sdkmetric.Producer, error) {\n\t\treturn otelprom.NewMetricProducer(otelprom.WithGatherer(reg)), nil\n\t})\n\n\treader, err := autoexport.NewMetricReader(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating OTLP metric reader: %w\", err)\n\t}\n\n\tversion, _ := caddy.Version()\n\tres, err := resource.Merge(resource.Default(), resource.NewSchemaless(\n\t\tsemconv.WebEngineName(ServerHeader),\n\t\tsemconv.WebEngineVersion(version),\n\t))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"building OTLP metrics resource: %w\", err)\n\t}\n\n\tm.meterProvider = sdkmetric.NewMeterProvider(\n\t\tsdkmetric.WithResource(res),\n\t\tsdkmetric.WithReader(reader),\n\t)\n\n\treturn nil\n}\n\n// shutdown flushes and tears down the OTLP MeterProvider if one was provisioned.\n// Both ForceFlush and Shutdown are always attempted so that a flush failure\n// does not prevent the reader goroutines from being stopped; errors from both\n// are returned joined.\nfunc (m *Metrics) shutdown(ctx context.Context) error {\n\tif m == nil || m.meterProvider == nil {\n\t\treturn nil\n\t}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/metrics.go#L184-L220","documentation":"After creating the metric reader, Caddy merges resource.Default() with a schemaless resource carrying WebEngineName/WebEngineVersion via resource.Merge. Per OTel semantics, merging resources whose schema URLs conflict returns an error, which is wrapped as 'building OTLP metrics resource'. The error path also exists because NewSchemaless construction itself can fail (invalid attribute values).","triggerScenarios":"resource.Merge conflict is possible when default resource detection yields attributes with a schema URL that conflicts with the schemaless addition — rare, but can happen with OTEL_RESOURCE_ATTRIBUTES or OTEL_SERVICE_NAME producing conflicting-detection results; more practically, malformed OTEL_RESOURCE_ATTRIBUTES values (bad key/value pairs) poison resource.Default().","commonSituations":"Containers where multiple resource detectors (env, host, cloud) produce inconsistent schema URLs; hand-written OTEL_RESOURCE_ATTRIBUTES with syntax errors; OTel library version combinations with known merge-conflict bugs.","solutions":["Sanitize OTEL_RESOURCE_ATTRIBUTES: comma-separated key=value pairs with valid keys/values; remove stray quotes/semicolons.","Simplify detection: temporarily unset OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME to isolate the conflict.","Align otel library versions (go.mod tidy/upgrade) to a consistent release line.","If unneeded, disable the OTLP metrics block and rely on the local Prometheus endpoint exposed by `metrics`."],"exampleFix":"# before\nexport OTEL_RESOURCE_ATTRIBUTES=\"service.name=caddy;bad-entry\"\n\n# after\nexport OTEL_RESOURCE_ATTRIBUTES=\"service.name=caddy\"","handlingStrategy":"validation","validationCode":"# Shell: keep OTEL_RESOURCE_ATTRIBUTES well-formed key=value pairs\nexport OTEL_RESOURCE_ATTRIBUTES=\"service.name=caddy,service.namespace=edge\"\n# avoid semicolons, stray quotes, empty keys","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate OTEL_RESOURCE_ATTRIBUTES syntax before deploy.","Isolate merge conflicts by unsetting OTEL_SERVICE_NAME / _RESOURCE_ATTRIBUTES temporarily.","Keep otel library versions on one consistent release line."],"tags":["caddy","metrics","opentelemetry","resource","environment"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}