You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
edba765831
This is related to issue #7938. ### The Bug Semconv code generator Jinja2 template (instrument.j2) had an early return optimization that skipped required attributes when no extra optional attributes were passed. The root cause seemed to be two macros in semconv/templates/registry/go/instrument.j2: - add_method_with_optional (for counters/updowncounters) - record_method_with_optional (for histograms/gauges) Both had `if len(attrs) == 0 { m.Inst.Add(ctx, incr); return }`, which bypassed required attributes entirely. ### The Fix I added a conditional check to verify when required attributes exist `(req_attr | length > 0)`, the early return now passes them via metric.WithAttributes(...). When there are no required attributes, the original fast path is preserved. I also regenerated the semconv `v1.39.0`, but if thats not desired due to existing clients, let me know. It is my first time contributing here and any feedback is appreciated! --------- Co-authored-by: Robert Pająk <pellared@hotmail.com>