Skip to content

Conversation

ternua8
Copy link
Contributor

@ternua8 ternua8 commented Sep 30, 2025

Summary

Switch the metric x package to template-based generation, similar to trace.
Add the EnabledInstrument interface in a separate file for synchronous instruments.

Details

  • sdk/metric/internal/x/gen.go uses the shared x.go.tmpl to generate x.go and x_test.go.
  • EnabledInstrument interface is added in enabled_instrument.go to allow instruments to report if they are enabled.
  • Corresponding test added in enabled_instrument_test.go.
  • This approach keeps metric and trace packages consistent and avoids linter warnings on unused features.

Notes

  • The newFeature function generated by the template is currently unused in metric, but it is kept for consistency with trace.
  • No breaking changes are introduced; this is purely internal and experimental feature setup.

Copy link

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.2%. Comparing base (643e735) to head (071f8c8).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7430   +/-   ##
=====================================
  Coverage   86.1%   86.2%           
=====================================
  Files        291     291           
  Lines      25615   25620    +5     
=====================================
+ Hits       22059   22086   +27     
+ Misses      3183    3162   -21     
+ Partials     373     372    -1     
Files with missing lines Coverage Δ
sdk/metric/internal/x/x.go 100.0% <100.0%> (+100.0%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dashpole
Copy link
Contributor

Is there a tracking issue for EnabledInstrument?

@MrAlias
Copy link
Contributor

MrAlias commented Sep 30, 2025

Is there a tracking issue for EnabledInstrument?

@dashpole: It looks like that came from #6016: tracking issue #6002

@MrAlias MrAlias added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Sep 30, 2025
@MrAlias
Copy link
Contributor

MrAlias commented Sep 30, 2025

@ternua8 it looks like the linter is failing. Please run make or make lint to fix the issues.

@@ -0,0 +1,12 @@
package x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package x
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!

@MrAlias
Copy link
Contributor

MrAlias commented Oct 13, 2025

@ternua8 are you still able to work on this?

@ternua8
Copy link
Contributor Author

ternua8 commented Oct 14, 2025

Hey, just returned from vacation — I can pick this up again!

import "context"

// EnabledInstrument interface is implemented by synchronous instruments.
type EnabledInstrument interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the original comments?

ctx := t.Context()
enabled := ei.Enabled(ctx)

require.True(t, enabled, "Enabled() should return true")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps using assert.Implements(....) would be more appropriate.


import "context"

// EnabledInstrument interface is implemented by synchronous instruments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// EnabledInstrument interface is implemented by synchronous instruments.
// EnabledInstrument informs whether the instrument is enabled.
//
// EnabledInstrument interface is implemented by synchronous instruments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants