Skip to content

Commit c94b43c

Browse files
Add measurement processor support (#493)
1 parent dc5bdc6 commit c94b43c

File tree

12 files changed

+73
-18
lines changed

12 files changed

+73
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## Unreleased
1010

11-
## [1.18.5](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.4) - 2023-06-26)
11+
## [1.18.6](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.6) - 2023-06-27)
12+
13+
- Support experimental `MeasurementProcessor` in the LS metrics SDK. [#493](https://github.com/lightstep/otel-launcher-go/pull/493)
14+
15+
## [1.18.5](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.5) - 2023-06-26)
1216

1317
- Correct the translation of Span StatusCode. [#495](https://github.com/lightstep/otel-launcher-go/pull/495)
1418

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.18.5
1+
1.18.6

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/lightstep/otel-launcher-go
33
go 1.18
44

55
require (
6-
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
7-
github.com/lightstep/otel-launcher-go/pipelines v1.18.5
6+
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.6
7+
github.com/lightstep/otel-launcher-go/pipelines v1.18.6
88
github.com/sethvargo/go-envconfig v0.8.3
99
github.com/stretchr/testify v1.8.4
1010
go.opentelemetry.io/otel v1.16.0
@@ -42,8 +42,8 @@ require (
4242
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
4343
github.com/knadh/koanf v1.5.0 // indirect
4444
github.com/lightstep/go-expohisto v1.0.0 // indirect
45-
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.5 // indirect
46-
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
45+
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.6 // indirect
46+
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6 // indirect
4747
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
4848
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
4949
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect

launcher/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package launcher
1616

17-
const version = "1.18.5"
17+
const version = "1.18.6"

lightstep/sdk/metric/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,14 @@ attribute filters are applied.
182182
When the aggregator's output grows to `AggregatorCardinalityLimit`,
183183
new attribute sets will be replaced by the overflow attribute set,
184184
which is `{ otel.metric.overflow=true }`.
185+
186+
#### MeasurementProcessor
187+
188+
The `MeasurementProcessor` interface that makes it possible to extend
189+
the set of attributes from synchronous instrument events, which allows
190+
metric attributes to be generated from the OpenTelemetry request
191+
context and/or W3C Tracecontext baggage.
192+
193+
This hook also supports removing attributes from metric events based
194+
on attribute value before they are aggregated, for example to
195+
dynamically configure allowed cardinality values.

lightstep/sdk/metric/example/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/example
33
go 1.18
44

55
require (
6-
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
6+
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.6
77
github.com/lightstep/otel-launcher-go/pipelines v1.8.0
88
go.opentelemetry.io/proto/otlp v0.20.0
99
)
@@ -35,7 +35,7 @@ require (
3535
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
3636
github.com/knadh/koanf v1.5.0 // indirect
3737
github.com/lightstep/go-expohisto v1.0.0 // indirect
38-
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
38+
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6 // indirect
3939
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
4040
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
4141
github.com/mitchellh/copystructure v1.2.0 // indirect

lightstep/sdk/metric/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/golang/mock v1.6.0
1111
github.com/google/go-cmp v0.5.9
1212
github.com/lightstep/go-expohisto v1.0.0
13-
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5
13+
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6
1414
github.com/stretchr/testify v1.8.4
1515
go.opentelemetry.io/collector v0.79.0
1616
go.opentelemetry.io/collector/component v0.79.0

lightstep/sdk/metric/internal/syncstate/sync.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (inst *Observer) ObserveFloat64(ctx context.Context, num float64, cfg OpCon
327327
}
328328

329329
// Observe performs a generic update for any synchronous instrument.
330-
func Observe[N number.Any, Traits number.Traits[N]](_ context.Context, inst *Observer, num N, cfg OpConfig) {
330+
func Observe[N number.Any, Traits number.Traits[N]](ctx context.Context, inst *Observer, num N, cfg OpConfig) {
331331
if inst == nil {
332332
// Instrument was completely disabled by the view.
333333
return
@@ -339,15 +339,20 @@ func Observe[N number.Any, Traits number.Traits[N]](_ context.Context, inst *Obs
339339
return
340340
}
341341

342-
var rec *recordKV
342+
var keyValues []attribute.KeyValue
343343
if cfg.KeyValues != nil {
344-
rec = acquireUninitializedKV[N](inst, cfg.KeyValues)
344+
keyValues = cfg.KeyValues
345345
} else {
346346
// TODO: This is a new code path for optimization,
347347
// for now fall back to the slow path.
348-
rec = acquireUninitializedKV[N](inst, cfg.Attributes.ToSlice())
348+
keyValues = cfg.Attributes.ToSlice()
349349
}
350350

351+
if inst.performance.MeasurementProcessor != nil {
352+
keyValues = inst.performance.MeasurementProcessor.Process(ctx, keyValues)
353+
}
354+
rec := acquireUninitializedKV[N](inst, keyValues)
355+
351356
defer rec.refMapped.unref()
352357

353358
rec.readAccumulator().(viewstate.Updater[N]).Update(num)

lightstep/sdk/metric/internal/syncstate/sync_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@ var (
5353
Now: endTime,
5454
}
5555

56+
testKeyVal = attribute.String("test", "test-value")
57+
5658
safePerf = sdkinstrument.Performance{
5759
IgnoreCollisions: false,
5860
InactiveCollectionPeriods: 1,
61+
MeasurementProcessor: &testMeasurementProcessor{
62+
attrs: []attribute.KeyValue{
63+
testKeyVal,
64+
},
65+
},
5966
}
6067

6168
unsafePerf = sdkinstrument.Performance{
@@ -99,6 +106,16 @@ var (
99106
)
100107
)
101108

109+
type testMeasurementProcessor struct {
110+
attrs []attribute.KeyValue
111+
}
112+
113+
func (mp *testMeasurementProcessor) Process(ctx context.Context, inAttrs []attribute.KeyValue) []attribute.KeyValue {
114+
outAttrs := make([]attribute.KeyValue, 0, len(mp.attrs)+len(inAttrs))
115+
outAttrs = append(outAttrs, inAttrs...)
116+
return append(outAttrs, mp.attrs...)
117+
}
118+
102119
func TestSyncStateDeltaConcurrencyInt(t *testing.T) {
103120
testSyncStateConcurrency[int64, number.Int64Traits](t, deltaUpdate[int64], deltaSelector)
104121
}
@@ -310,6 +327,7 @@ func TestSyncStatePartialNoopInstrument(t *testing.T) {
310327
test.Point(startTime, endTime,
311328
expectHist,
312329
aggregation.CumulativeTemporality,
330+
testKeyVal,
313331
),
314332
),
315333
)
@@ -397,6 +415,7 @@ func TestOutOfRangeValues(t *testing.T) {
397415
startTime, endTime,
398416
negOne,
399417
aggregation.CumulativeTemporality,
418+
testKeyVal,
400419
))
401420
}
402421

lightstep/sdk/metric/sdkinstrument/performance.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
package sdkinstrument
1616

17+
import (
18+
"context"
19+
20+
"go.opentelemetry.io/otel/attribute"
21+
)
22+
1723
// DefaultInactiveCollectionPeriods is how many collection periods to
1824
// delay before removing records from memory.
1925
const DefaultInactiveCollectionPeriods = 10
@@ -48,6 +54,16 @@ type Performance struct {
4854
// AggregatorCardinalityLimit is a hard limit on output
4955
// cardinality for all aggregators in the SDK.
5056
AggregatorCardinalityLimit uint32
57+
58+
// MeasurementProcessor supports modifying the attributes
59+
// based on context. Only applies to synchronous instruments.
60+
MeasurementProcessor MeasurementProcessor
61+
}
62+
63+
// MeasurementProcessor allows applications to extend metric events
64+
// based on context.
65+
type MeasurementProcessor interface {
66+
Process(ctx context.Context, inAttrs []attribute.KeyValue) (outAttrs []attribute.KeyValue)
5167
}
5268

5369
// Validate returns a Performance object with 0 values replaced by

0 commit comments

Comments
 (0)