1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Files
opentelemetry-go/semconv
Victor edba765831 fix: generated semconv helpers skipping attributes (#7964)
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>
2026-03-04 14:20:36 +01:00
..
2024-04-23 17:29:17 +02:00
2024-10-20 07:50:39 -07:00
2025-02-04 07:52:00 -08:00
2026-01-30 18:15:17 +01:00
2026-01-30 18:15:17 +01:00
2025-12-03 19:55:44 -08:00
2024-03-26 20:13:54 +01:00