You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
11
11
### Added
12
12
13
13
- Add `Reset` method to `SpanRecorder` in `go.opentelemetry.io/otel/sdk/trace/tracetest`. (#5994)
14
+
- Add `EnabledInstrument` interface in `go.opentelemetry.io/otel/sdk/metric/internal/x`.
15
+
This is an experimental interface that is implemented by synchronous instruments provided by `go.opentelemetry.io/otel/sdk/metric`.
16
+
Users can use it to avoid performing computationally expensive operations when recording measurements.
17
+
It does not fall within the scope of the OpenTelemetry Go versioning and stability [policy](./VERSIONING.md) and it may be changed in backwards incompatible ways or removed in feature releases. (#6016)
Copy file name to clipboardExpand all lines: sdk/metric/internal/x/README.md
+19
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ See the [Compatibility and Stability](#compatibility-and-stability) section for
10
10
11
11
-[Cardinality Limit](#cardinality-limit)
12
12
-[Exemplars](#exemplars)
13
+
-[Instrument Enabled](#instrument-enabled)
13
14
14
15
### Cardinality Limit
15
16
@@ -102,6 +103,24 @@ Revert to the default exemplar filter (`"trace_based"`)
102
103
unset OTEL_METRICS_EXEMPLAR_FILTER
103
104
```
104
105
106
+
### Instrument Enabled
107
+
108
+
To help users avoid performing computationally expensive operations when recording measurements, synchronous instruments provide an `Enabled` method.
109
+
110
+
#### Examples
111
+
112
+
The following code shows an example of how to check if an instrument implements the `EnabledInstrument` interface before using the `Enabled` function to avoid doing an expensive computation:
113
+
114
+
```go
115
+
type enabledInstrument interface { Enabled(context.Context) bool }
116
+
117
+
ctr, err:= m.Int64Counter("expensive-counter")
118
+
c, ok:= ctr.(enabledInstrument)
119
+
if !ok || c.Enabled(context.Background()) {
120
+
c.Add(expensiveComputation())
121
+
}
122
+
```
123
+
105
124
## Compatibility and Stability
106
125
107
126
Experimental features do not fall within the scope of the OpenTelemetry Go versioning and stability [policy](../../../../VERSIONING.md).
0 commit comments