fix: generated semconv helpers skipping attributes#7964
Merged
dmathieu merged 8 commits intoopen-telemetry:mainfrom Mar 4, 2026
Merged
fix: generated semconv helpers skipping attributes#7964dmathieu merged 8 commits intoopen-telemetry:mainfrom
dmathieu merged 8 commits intoopen-telemetry:mainfrom
Conversation
9 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7964 +/- ##
=====================================
Coverage 81.6% 81.6%
=====================================
Files 304 304
Lines 23384 23384
=====================================
+ Hits 19086 19090 +4
+ Misses 3909 3905 -4
Partials 389 389 🚀 New features to boost your workflow:
|
MrAlias
approved these changes
Mar 3, 2026
pellared
reviewed
Mar 3, 2026
Member
pellared
left a comment
There was a problem hiding this comment.
Can you please add a changelog entry for v1.39.0 (no need for v1.40.0 as this was not released yet) under "Fixed" section?
9c508fc to
356af2f
Compare
Contributor
Author
|
Hey @pellared! Updated the changelog, rebased with main and regenerated the code just in case |
Contributor
Author
|
Want me to include the regenerated v1.40.0 with the fix in this PR? |
MrAlias
reviewed
Mar 3, 2026
Contributor
yes |
97ae6dd to
c521e65
Compare
Contributor
Author
Done @MrAlias ! |
Member
|
This needs an approval from an approver who is not working for Splunk. |
dmathieu
approved these changes
Mar 4, 2026
pellared
added a commit
that referenced
this pull request
Mar 6, 2026
### Added - Add `go.opentelemetry.io/otel/semconv/v1.40.0` package. The package contains semantic conventions from the `v1.40.0` version of the OpenTelemetry Semantic Conventions. See the [migration documentation](./semconv/v1.40.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.39.0`. (#7985) - Add `Err` and `SetErr` on `Record` in `go.opentelemetry.io/otel/log` to attach an error and set record exception attributes in `go.opentelemetry.io/otel/log/sdk`. (#7924) ### Changed - `TracerProvider.ForceFlush` in `go.opentelemetry.io/otel/sdk/trace` joins errors together and continues iteration through SpanProcessors as opposed to returning the first encountered error without attempting exports on subsequent SpanProcessors. (#7856) ### Fixed - Fix missing `request.GetBody` in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` to correctly handle HTTP2 GOAWAY frame. (#7931) - Fix semconv v1.39.0 generated metric helpers skipping required attributes when extra attributes were empty. (#7964) - Preserve W3C TraceFlags bitmask (including the random Trace ID flag) during trace context extraction and injection in `go.opentelemetry.io/otel/propagation`. (#7834) ### Removed - Drop support for [Go 1.24]. (#7984)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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!