Skip to content

Commit

Permalink
Add measurement processor support (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak authored Jun 27, 2023
1 parent dc5bdc6 commit c94b43c
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

## [1.18.5](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.4) - 2023-06-26)
## [1.18.6](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.6) - 2023-06-27)

- Support experimental `MeasurementProcessor` in the LS metrics SDK. [#493](https://github.com/lightstep/otel-launcher-go/pull/493)

## [1.18.5](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.5) - 2023-06-26)

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

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.5
1.18.6
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/lightstep/otel-launcher-go
go 1.18

require (
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
github.com/lightstep/otel-launcher-go/pipelines v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.6
github.com/lightstep/otel-launcher-go/pipelines v1.18.6
github.com/sethvargo/go-envconfig v0.8.3
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.16.0
Expand Down Expand Up @@ -42,8 +42,8 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lightstep/go-expohisto v1.0.0 // indirect
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.5 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.6 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion launcher/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

package launcher

const version = "1.18.5"
const version = "1.18.6"
11 changes: 11 additions & 0 deletions lightstep/sdk/metric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,14 @@ attribute filters are applied.
When the aggregator's output grows to `AggregatorCardinalityLimit`,
new attribute sets will be replaced by the overflow attribute set,
which is `{ otel.metric.overflow=true }`.

#### MeasurementProcessor

The `MeasurementProcessor` interface that makes it possible to extend
the set of attributes from synchronous instrument events, which allows
metric attributes to be generated from the OpenTelemetry request
context and/or W3C Tracecontext baggage.

This hook also supports removing attributes from metric events based
on attribute value before they are aggregated, for example to
dynamically configure allowed cardinality values.
4 changes: 2 additions & 2 deletions lightstep/sdk/metric/example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/example
go 1.18

require (
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.6
github.com/lightstep/otel-launcher-go/pipelines v1.8.0
go.opentelemetry.io/proto/otlp v0.20.0
)
Expand Down Expand Up @@ -35,7 +35,7 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lightstep/go-expohisto v1.0.0 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/lightstep/go-expohisto v1.0.0
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector v0.79.0
go.opentelemetry.io/collector/component v0.79.0
Expand Down
13 changes: 9 additions & 4 deletions lightstep/sdk/metric/internal/syncstate/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (inst *Observer) ObserveFloat64(ctx context.Context, num float64, cfg OpCon
}

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

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

if inst.performance.MeasurementProcessor != nil {
keyValues = inst.performance.MeasurementProcessor.Process(ctx, keyValues)
}
rec := acquireUninitializedKV[N](inst, keyValues)

defer rec.refMapped.unref()

rec.readAccumulator().(viewstate.Updater[N]).Update(num)
Expand Down
19 changes: 19 additions & 0 deletions lightstep/sdk/metric/internal/syncstate/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ var (
Now: endTime,
}

testKeyVal = attribute.String("test", "test-value")

safePerf = sdkinstrument.Performance{
IgnoreCollisions: false,
InactiveCollectionPeriods: 1,
MeasurementProcessor: &testMeasurementProcessor{
attrs: []attribute.KeyValue{
testKeyVal,
},
},
}

unsafePerf = sdkinstrument.Performance{
Expand Down Expand Up @@ -99,6 +106,16 @@ var (
)
)

type testMeasurementProcessor struct {
attrs []attribute.KeyValue
}

func (mp *testMeasurementProcessor) Process(ctx context.Context, inAttrs []attribute.KeyValue) []attribute.KeyValue {
outAttrs := make([]attribute.KeyValue, 0, len(mp.attrs)+len(inAttrs))
outAttrs = append(outAttrs, inAttrs...)
return append(outAttrs, mp.attrs...)
}

func TestSyncStateDeltaConcurrencyInt(t *testing.T) {
testSyncStateConcurrency[int64, number.Int64Traits](t, deltaUpdate[int64], deltaSelector)
}
Expand Down Expand Up @@ -310,6 +327,7 @@ func TestSyncStatePartialNoopInstrument(t *testing.T) {
test.Point(startTime, endTime,
expectHist,
aggregation.CumulativeTemporality,
testKeyVal,
),
),
)
Expand Down Expand Up @@ -397,6 +415,7 @@ func TestOutOfRangeValues(t *testing.T) {
startTime, endTime,
negOne,
aggregation.CumulativeTemporality,
testKeyVal,
))
}

Expand Down
16 changes: 16 additions & 0 deletions lightstep/sdk/metric/sdkinstrument/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

package sdkinstrument

import (
"context"

"go.opentelemetry.io/otel/attribute"
)

// DefaultInactiveCollectionPeriods is how many collection periods to
// delay before removing records from memory.
const DefaultInactiveCollectionPeriods = 10
Expand Down Expand Up @@ -48,6 +54,16 @@ type Performance struct {
// AggregatorCardinalityLimit is a hard limit on output
// cardinality for all aggregators in the SDK.
AggregatorCardinalityLimit uint32

// MeasurementProcessor supports modifying the attributes
// based on context. Only applies to synchronous instruments.
MeasurementProcessor MeasurementProcessor
}

// MeasurementProcessor allows applications to extend metric events
// based on context.
type MeasurementProcessor interface {
Process(ctx context.Context, inAttrs []attribute.KeyValue) (outAttrs []attribute.KeyValue)
}

// Validate returns a Performance object with 0 values replaced by
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/trace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/f5/otel-arrow-adapter v0.0.0-20230612212022-445aac7c6ae8
github.com/google/go-cmp v0.5.9
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector v0.79.0
go.opentelemetry.io/collector/component v0.79.0
Expand Down
6 changes: 3 additions & 3 deletions pipelines/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ require (
)

require (
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.6
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.6
go.opentelemetry.io/collector v0.79.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0
)
Expand Down Expand Up @@ -79,7 +79,7 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lightstep/go-expohisto v1.0.0 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.6 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down

0 comments on commit c94b43c

Please sign in to comment.