diff --git a/module/apmotel/gatherer.go b/module/apmotel/gatherer.go index 275696ad1..4398b6bf5 100644 --- a/module/apmotel/gatherer.go +++ b/module/apmotel/gatherer.go @@ -60,7 +60,9 @@ func (e Gatherer) GatherMetrics(ctx context.Context, out *apm.Metrics) error { for _, sm := range scopeMetrics.Metrics { switch m := sm.Data.(type) { - case metricdata.Histogram: + case metricdata.Histogram[int64]: + addHistogramMetric(out, sm, m) + case metricdata.Histogram[float64]: addHistogramMetric(out, sm, m) case metricdata.Sum[int64]: for _, dp := range m.DataPoints { @@ -87,7 +89,7 @@ func (e Gatherer) GatherMetrics(ctx context.Context, out *apm.Metrics) error { return nil } -func addHistogramMetric(out *apm.Metrics, sm metricdata.Metrics, m metricdata.Histogram) { +func addHistogramMetric[T int64 | float64](out *apm.Metrics, sm metricdata.Metrics, m metricdata.Histogram[T]) { for _, dp := range m.DataPoints { if len(dp.BucketCounts) != len(dp.Bounds)+1 || len(dp.Bounds) == 0 { continue diff --git a/module/apmotel/gatherer_test.go b/module/apmotel/gatherer_test.go index 6b9bec0c0..a2792d3aa 100644 --- a/module/apmotel/gatherer_test.go +++ b/module/apmotel/gatherer_test.go @@ -49,7 +49,7 @@ func TestGatherer(t *testing.T) { recordMetrics: func(ctx context.Context, meter metric.Meter) { counter, err := meter.Float64Counter("foo") assert.NoError(t, err) - counter.Add(ctx, 5, attribute.Key("A").String("B")) + counter.Add(ctx, 5, metric.WithAttributes(attribute.Key("A").String("B"))) }, expectedMetrics: []model.Metrics{ { @@ -69,7 +69,7 @@ func TestGatherer(t *testing.T) { recordMetrics: func(ctx context.Context, meter metric.Meter) { counter, err := meter.Int64Counter("foo") assert.NoError(t, err) - counter.Add(ctx, 5, attribute.Key("A").String("B")) + counter.Add(ctx, 5, metric.WithAttributes(attribute.Key("A").String("B"))) }, expectedMetrics: []model.Metrics{ { @@ -89,7 +89,7 @@ func TestGatherer(t *testing.T) { recordMetrics: func(ctx context.Context, meter metric.Meter) { counter, err := meter.Float64UpDownCounter("foo") assert.NoError(t, err) - counter.Add(ctx, 5, attribute.Key("A").String("B")) + counter.Add(ctx, 5, metric.WithAttributes(attribute.Key("A").String("B"))) }, expectedMetrics: []model.Metrics{ { @@ -109,7 +109,7 @@ func TestGatherer(t *testing.T) { recordMetrics: func(ctx context.Context, meter metric.Meter) { counter, err := meter.Float64UpDownCounter("foo") assert.NoError(t, err) - counter.Add(ctx, 5, attribute.Key("A").String("B")) + counter.Add(ctx, 5, metric.WithAttributes(attribute.Key("A").String("B"))) }, expectedMetrics: []model.Metrics{ { @@ -129,44 +129,44 @@ func TestGatherer(t *testing.T) { recordMetrics: func(ctx context.Context, meter metric.Meter) { counter, err := meter.Float64Histogram("histogram_foo") assert.NoError(t, err) - counter.Record(ctx, 3.4, + counter.Record(ctx, 3.4, metric.WithAttributes( attribute.Key("code").String("200"), attribute.Key("method").String("GET"), - ) - counter.Record(ctx, 3.4, + )) + counter.Record(ctx, 3.4, metric.WithAttributes( attribute.Key("code").String("200"), attribute.Key("method").String("GET"), - ) - counter.Record(ctx, 3.4, + )) + counter.Record(ctx, 3.4, metric.WithAttributes( attribute.Key("code").String("200"), attribute.Key("method").String("GET"), - ) + )) - counter.Record(ctx, 5.5, + counter.Record(ctx, 5.5, metric.WithAttributes( attribute.Key("code").String("302"), attribute.Key("method").String("GET"), - ) - counter.Record(ctx, 5.5, + )) + counter.Record(ctx, 5.5, metric.WithAttributes( attribute.Key("code").String("302"), attribute.Key("method").String("GET"), - ) - counter.Record(ctx, 5.5, + )) + counter.Record(ctx, 5.5, metric.WithAttributes( attribute.Key("code").String("302"), attribute.Key("method").String("GET"), - ) + )) - counter.Record(ctx, 11.2, + counter.Record(ctx, 11.2, metric.WithAttributes( attribute.Key("code").String("302"), attribute.Key("method").String("GET"), - ) - counter.Record(ctx, 11.2, + )) + counter.Record(ctx, 11.2, metric.WithAttributes( attribute.Key("code").String("302"), attribute.Key("method").String("GET"), - ) - counter.Record(ctx, 11.2, + )) + counter.Record(ctx, 11.2, metric.WithAttributes( attribute.Key("code").String("302"), attribute.Key("method").String("GET"), - ) + )) }, expectedMetrics: []model.Metrics{ { @@ -202,7 +202,7 @@ func TestGatherer(t *testing.T) { recordMetrics: func(ctx context.Context, meter metric.Meter) { counter, err := meter.Int64Histogram("foo") assert.NoError(t, err) - counter.Record(ctx, 5, attribute.Key("A").String("B")) + counter.Record(ctx, 5, metric.WithAttributes(attribute.Key("A").String("B"))) }, expectedMetrics: []model.Metrics{ { @@ -255,10 +255,10 @@ func TestGathererWithCustomView(t *testing.T) { counter, err := meter.Float64Histogram("histogram_foo") assert.NoError(t, err) - counter.Record(ctx, 3.4, + counter.Record(ctx, 3.4, metric.WithAttributes( attribute.Key("code").String("200"), attribute.Key("method").String("GET"), - ) + )) metrics := gatherMetrics(gatherer) diff --git a/module/apmotel/go.mod b/module/apmotel/go.mod index e5463aa9f..641ab73f3 100644 --- a/module/apmotel/go.mod +++ b/module/apmotel/go.mod @@ -4,11 +4,11 @@ require ( github.com/stretchr/testify v1.8.2 go.elastic.co/apm/module/apmhttp/v2 v2.4.1 go.elastic.co/apm/v2 v2.4.1 - go.opentelemetry.io/otel v1.14.0 - go.opentelemetry.io/otel/metric v0.37.0 - go.opentelemetry.io/otel/sdk v1.14.0 - go.opentelemetry.io/otel/sdk/metric v0.37.0 - go.opentelemetry.io/otel/trace v1.14.0 + go.opentelemetry.io/otel v1.15.1 + go.opentelemetry.io/otel/metric v0.38.1 + go.opentelemetry.io/otel/sdk v1.15.1 + go.opentelemetry.io/otel/sdk/metric v0.38.1 + go.opentelemetry.io/otel/trace v1.15.1 ) require ( @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/elastic/go-sysinfo v1.7.1 // indirect github.com/elastic/go-windows v1.0.1 // indirect - github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect @@ -24,7 +24,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/procfs v0.7.3 // indirect go.elastic.co/fastjson v1.1.0 // indirect - golang.org/x/sys v0.6.0 // indirect + golang.org/x/sys v0.7.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect howett.net/plist v1.0.0 // indirect ) diff --git a/module/apmotel/go.sum b/module/apmotel/go.sum index d0c88e6e4..eb28d6545 100644 --- a/module/apmotel/go.sum +++ b/module/apmotel/go.sum @@ -9,8 +9,8 @@ github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6 github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0= github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -45,16 +45,16 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= -go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= -go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= -go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs= -go.opentelemetry.io/otel/metric v0.37.0/go.mod h1:DmdaHfGt54iV6UKxsV9slj2bBRJcKC1B1uvDLIioc1s= -go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= -go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM= -go.opentelemetry.io/otel/sdk/metric v0.37.0 h1:haYBBtZZxiI3ROwSmkZnI+d0+AVzBWeviuYQDeBWosU= -go.opentelemetry.io/otel/sdk/metric v0.37.0/go.mod h1:mO2WV1AZKKwhwHTV3AKOoIEb9LbUaENZDuGUQd+j4A0= -go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= -go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= +go.opentelemetry.io/otel v1.15.1 h1:3Iwq3lfRByPaws0f6bU3naAqOR1n5IeDWd9390kWHa8= +go.opentelemetry.io/otel v1.15.1/go.mod h1:mHHGEHVDLal6YrKMmk9LqC4a3sF5g+fHfrttQIB1NTc= +go.opentelemetry.io/otel/metric v0.38.1 h1:2MM7m6wPw9B8Qv8iHygoAgkbejed59uUR6ezR5T3X2s= +go.opentelemetry.io/otel/metric v0.38.1/go.mod h1:FwqNHD3I/5iX9pfrRGZIlYICrJv0rHEUl2Ln5vdIVnQ= +go.opentelemetry.io/otel/sdk v1.15.1 h1:5FKR+skgpzvhPQHIEfcwMYjCBr14LWzs3uSqKiQzETI= +go.opentelemetry.io/otel/sdk v1.15.1/go.mod h1:8rVtxQfrbmbHKfqzpQkT5EzZMcbMBwTzNAggbEAM0KA= +go.opentelemetry.io/otel/sdk/metric v0.38.1 h1:EkO5wI4NT/fUaoPMGc0fKV28JaWe7q4vfVpEVasGb+8= +go.opentelemetry.io/otel/sdk/metric v0.38.1/go.mod h1:Rn4kSXFF9ZQZ5lL1pxQjCbK4seiO+U7s0ncmIFJaj34= +go.opentelemetry.io/otel/trace v1.15.1 h1:uXLo6iHJEzDfrNC0L0mNjItIp06SyaBQxu5t3xMlngY= +go.opentelemetry.io/otel/trace v1.15.1/go.mod h1:IWdQG/5N1x7f6YUlmdLeJvH9yxtuJAfc4VW5Agv9r/8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -71,9 +71,8 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=