1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Commit Graph

5 Commits

Author SHA1 Message Date
Tyler Yahn b2b3250897 Semconv metric helper caller-slice mutation fix (#7993)
This PR addresses issue #7987 (issue (1)): generated semconv metric
helpers should not risk mutating caller-provided `attrs` backing arrays
when required attributes are appended.

Update the generator logic to merge required-attribute using capacity
clamping before append:

```
append(attrs[:len(attrs):len(attrs)], requiredAttrs...)
```

This guarantees append allocates a new backing array for the merged
slice instead of writing into caller memory when there are attributes
appended. It makes not allocations in the case attributes are not
appended.
2026-03-04 15:49:49 +01:00
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
Tyler Yahn 5dee2eb2dc Revert "Revert "Generate semconv/v1.40.0"" (#7985)
Reverts open-telemetry/opentelemetry-go#7978
2026-03-03 07:32:17 +01:00
Damien Mathieu 0d50f9008c Revert "Generate semconv/v1.40.0" (#7978)
Reverts open-telemetry/opentelemetry-go#7929
2026-03-02 11:06:31 +01:00
Christos Markou c38a4a57c3 Generate semconv/v1.40.0 (#7929)
Similar to https://github.com/open-telemetry/opentelemetry-go/pull/7783
for semconv/v1.40.0:
https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.40.0

---------

Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
2026-03-02 10:54:57 +01:00