From 3086b1dbb451b58ef2a3e35178b76f17c6069ed2 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 12 Dec 2023 14:20:54 +0100 Subject: [PATCH] [pkg/otlp/metrics] Make NewTranslator take a component.TelemetrySettings instead of a logger (#218) * [pkg/otlp/metrics] Make NewTranslator take a component.TelemetrySettings instead of a logger * Add changelog entry * make gen-licenses --- .chloggen/mx-psi_counter-hostname.yaml | 16 ++++++++++ LICENSE-3rdparty.csv | 22 +++++++++++++ pkg/otlp/metrics/go.mod | 14 ++++++++ pkg/otlp/metrics/go.sum | 32 ++++++++++++++++++- pkg/otlp/metrics/histograms_test.go | 10 +++--- pkg/otlp/metrics/metrics_translator.go | 5 +-- .../metrics_translator_benchmark_test.go | 5 ++- pkg/otlp/metrics/metrics_translator_test.go | 11 ++++--- pkg/otlp/metrics/mixed_metrics_test.go | 6 ++-- pkg/otlp/metrics/summary_test.go | 4 +-- pkg/otlp/metrics/testhelper_test.go | 4 +-- 11 files changed, 111 insertions(+), 18 deletions(-) create mode 100755 .chloggen/mx-psi_counter-hostname.yaml diff --git a/.chloggen/mx-psi_counter-hostname.yaml b/.chloggen/mx-psi_counter-hostname.yaml new file mode 100755 index 00000000..d00a8f1d --- /dev/null +++ b/.chloggen/mx-psi_counter-hostname.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component (e.g. pkg/quantile) +component: pkg/otlp/metrics + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Change signature of `NewTranslator` to accept `component.TelemetrySettings` instead of `zap.Logger` + +# The PR related to this change +issues: [218] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 14c0b783..b230ed96 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -173,12 +173,24 @@ pkg/otlp/metrics,github.com/golang/protobuf/ptypes,BSD-3-Clause,Copyright 2010 T pkg/otlp/metrics,github.com/golang/protobuf/ptypes/any,BSD-3-Clause,Copyright 2010 The Go Authors. All rights reserved pkg/otlp/metrics,github.com/golang/protobuf/ptypes/duration,BSD-3-Clause,Copyright 2010 The Go Authors. All rights reserved pkg/otlp/metrics,github.com/golang/protobuf/ptypes/timestamp,BSD-3-Clause,Copyright 2010 The Go Authors. All rights reserved +pkg/otlp/metrics,github.com/hashicorp/go-version,MPL-2.0,"copyright doctrines of fair use, fair dealing, or other equivalents" pkg/otlp/metrics,github.com/json-iterator/go,MIT,Copyright (c) 2016 json-iterator +pkg/otlp/metrics,github.com/knadh/koanf/maps,MIT,"Copyright (c) 2019, Kailash Nadh. https://github.com/knadh" +pkg/otlp/metrics,github.com/knadh/koanf/providers/confmap,MIT,"Copyright (c) 2019, Kailash Nadh. https://github.com/knadh" +pkg/otlp/metrics,github.com/knadh/koanf/v2,MIT,"Copyright (c) 2019, Kailash Nadh. https://github.com/knadh" +pkg/otlp/metrics,github.com/mitchellh/copystructure,MIT,Copyright (c) 2014 Mitchell Hashimoto +pkg/otlp/metrics,github.com/mitchellh/mapstructure,MIT,Copyright (c) 2013 Mitchell Hashimoto +pkg/otlp/metrics,github.com/mitchellh/reflectwalk,MIT,Copyright (c) 2013 Mitchell Hashimoto pkg/otlp/metrics,github.com/modern-go/concurrent,Apache-2.0,Copyright (c) 2018 Tao Wen pkg/otlp/metrics,github.com/modern-go/reflect2,Apache-2.0,Copyright (c) 2018 Tao Wen pkg/otlp/metrics,github.com/patrickmn/go-cache,MIT,"Copyright (c) 2012-2017 Patrick Mylund Nielsen and the go-cache contributors | This is a list of people who have contributed code to go-cache. They, or their | employers, are the copyright holders of the contributed code. Contributed code | is subject to the license restrictions listed in LICENSE (as they were when the | code was contributed.) | Dustin Sallings | Jason Mooberry | Sergey Shepelev | Alex Edwards " pkg/otlp/metrics,github.com/philhofer/fwd,MIT,"Copyright (c) 2014-2015, Philip Hofer" pkg/otlp/metrics,github.com/tinylib/msgp/msgp,MIT,Copyright (c) 2014 Philip Hofer | Copyright (c) 2009 The Go Authors (license at http://golang.org) where indicated +pkg/otlp/metrics,go.opentelemetry.io/collector/component,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/collector/config/configtelemetry,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/collector/confmap,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/collector/confmap/internal/mapstructure,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/collector/featuregate,Apache-2.0,Copyright The OpenTelemetry Authors pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/internal,Apache-2.0,Copyright The OpenTelemetry Authors pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/internal/data,Apache-2.0,Copyright The OpenTelemetry Authors pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1,Apache-2.0,Copyright The OpenTelemetry Authors @@ -194,6 +206,16 @@ pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/internal/otlp,Apache-2.0,Co pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/pcommon,Apache-2.0,Copyright The OpenTelemetry Authors pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/pmetric,Apache-2.0,Copyright The OpenTelemetry Authors pkg/otlp/metrics,go.opentelemetry.io/collector/semconv/v1.6.1,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/attribute,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/codes,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/internal,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/internal/attribute,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/metric,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/metric/embedded,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/metric/noop,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/trace,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/trace/embedded,Apache-2.0,Copyright The OpenTelemetry Authors +pkg/otlp/metrics,go.opentelemetry.io/otel/trace/noop,Apache-2.0,Copyright The OpenTelemetry Authors pkg/otlp/metrics,go.uber.org/multierr,MIT,"Copyright (c) 2017-2021 Uber Technologies, Inc" pkg/otlp/metrics,go.uber.org/zap,MIT,"Copyright (c) 2016-2017 Uber Technologies, Inc" pkg/otlp/metrics,go.uber.org/zap/buffer,MIT,"Copyright (c) 2016-2017 Uber Technologies, Inc" diff --git a/pkg/otlp/metrics/go.mod b/pkg/otlp/metrics/go.mod index c37b6fdc..0c41f89a 100644 --- a/pkg/otlp/metrics/go.mod +++ b/pkg/otlp/metrics/go.mod @@ -12,6 +12,7 @@ require ( github.com/lightstep/go-expohisto v1.0.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/stretchr/testify v1.8.4 + go.opentelemetry.io/collector/component v0.91.0 go.opentelemetry.io/collector/pdata v1.0.0 go.uber.org/zap v1.26.0 golang.org/x/exp v0.0.0-20230321023759-10a507213a29 @@ -21,13 +22,26 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/hashicorp/go-version v1.6.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/knadh/koanf/maps v0.1.1 // indirect + github.com/knadh/koanf/providers/confmap v0.1.0 // indirect + github.com/knadh/koanf/v2 v2.0.1 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/philhofer/fwd v1.1.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/tinylib/msgp v1.1.8 // indirect + go.opentelemetry.io/collector/config/configtelemetry v0.91.0 // indirect + go.opentelemetry.io/collector/confmap v0.91.0 // indirect + go.opentelemetry.io/collector/featuregate v1.0.0 // indirect go.opentelemetry.io/collector/semconv v0.90.1 // indirect + go.opentelemetry.io/otel v1.21.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.14.0 // indirect diff --git a/pkg/otlp/metrics/go.sum b/pkg/otlp/metrics/go.sum index f1e4df31..35cdbb95 100644 --- a/pkg/otlp/metrics/go.sum +++ b/pkg/otlp/metrics/go.sum @@ -7,24 +7,40 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs= +github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU= +github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU= +github.com/knadh/koanf/v2 v2.0.1 h1:1dYGITt1I23x8cfx8ZnldtezdyaZtfAuRtIFOiRzK7g= +github.com/knadh/koanf/v2 v2.0.1/go.mod h1:ZeiIlIDXTE7w1lMT6UVcNiRAS2/rCeLn/GdLNvY1Dus= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/lightstep/go-expohisto v1.0.0 h1:UPtTS1rGdtehbbAF7o/dhkWLTDI73UifG8LbfQI7cA4= github.com/lightstep/go-expohisto v1.0.0/go.mod h1:xDXD0++Mu2FOaItXtdDfksfgxfV0z1TMPa+e/EUd0cs= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 h1:BpfhmLKZf+SjVanKKhCgf3bg+511DmU9eDQTen7LLbY= +github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -49,10 +65,24 @@ github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37w github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.opentelemetry.io/collector/component v0.91.0 h1:aBT1i2zGyfh9PalYJLfXVvQp+osHyalwyDFselI1CtA= +go.opentelemetry.io/collector/component v0.91.0/go.mod h1:2KBHvjNFdU7oOjsObQeC4Ta2Ef607OISU5obznW00fw= +go.opentelemetry.io/collector/config/configtelemetry v0.91.0 h1:mEwvqrYfwUJ7LwYfpcF9M8z7LHFoYaKhEPhnERD/88E= +go.opentelemetry.io/collector/config/configtelemetry v0.91.0/go.mod h1:+LAXM5WFMW/UbTlAuSs6L/W72WC+q8TBJt/6z39FPOU= +go.opentelemetry.io/collector/confmap v0.91.0 h1:7U2MT+u74oEzq/WWrpXSLKB7nX5jPNC4drwtQdYfwKk= +go.opentelemetry.io/collector/confmap v0.91.0/go.mod h1:uxV+fZ85kG31oovL6Cl3fAMQ3RRPwUvfAbbA9WT1Yhk= +go.opentelemetry.io/collector/featuregate v1.0.0 h1:5MGqe2v5zxaoo73BUOvUTunftX5J8RGrbFsC2Ha7N3g= +go.opentelemetry.io/collector/featuregate v1.0.0/go.mod h1:xGbRuw+GbutRtVVSEy3YR2yuOlEyiUMhN2M9DJljgqY= go.opentelemetry.io/collector/pdata v1.0.0 h1:ECP2jnLztewsHmL1opL8BeMtWVc7/oSlKNhfY9jP8ec= go.opentelemetry.io/collector/pdata v1.0.0/go.mod h1:TsDFgs4JLNG7t6x9D8kGswXUz4mme+MyNChHx8zSF6k= go.opentelemetry.io/collector/semconv v0.90.1 h1:2fkQZbefQBbIcNb9Rk1mRcWlFZgQOk7CpST1e1BK8eg= go.opentelemetry.io/collector/semconv v0.90.1/go.mod h1:j/8THcqVxFna1FpvA2zYIsUperEtOaRaqoLYIN4doWw= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= diff --git a/pkg/otlp/metrics/histograms_test.go b/pkg/otlp/metrics/histograms_test.go index 18278483..9d3135d9 100644 --- a/pkg/otlp/metrics/histograms_test.go +++ b/pkg/otlp/metrics/histograms_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" @@ -85,7 +86,7 @@ func TestDeltaHistogramTranslatorOptions(t *testing.T) { for _, testinstance := range tests { t.Run(testinstance.name, func(t *testing.T) { - translator, err := NewTranslator(zap.NewNop(), testinstance.options...) + translator, err := NewTranslator(componenttest.NewNopTelemetrySettings(), testinstance.options...) if testinstance.err != "" { assert.EqualError(t, err, testinstance.err) return @@ -150,7 +151,7 @@ func TestCumulativeHistogramTranslatorOptions(t *testing.T) { for _, testinstance := range tests { t.Run(testinstance.name, func(t *testing.T) { - translator, err := NewTranslator(zap.NewNop(), testinstance.options...) + translator, err := NewTranslator(componenttest.NewNopTelemetrySettings(), testinstance.options...) require.NoError(t, err) AssertTranslatorMap(t, translator, testinstance.otlpfile, testinstance.ddogfile) }) @@ -277,9 +278,10 @@ func TestExponentialHistogramTranslatorOptions(t *testing.T) { for _, testinstance := range tests { t.Run(testinstance.name, func(t *testing.T) { + set := componenttest.NewNopTelemetrySettings() core, observed := observer.New(zapcore.DebugLevel) - testLogger := zap.New(core) - translator, err := NewTranslator(testLogger, testinstance.options...) + set.Logger = zap.New(core) + translator, err := NewTranslator(set, testinstance.options...) require.NoError(t, err) AssertTranslatorMap(t, translator, testinstance.otlpfile, testinstance.ddogfile) assert.Equal(t, testinstance.expectedUnknownMetricType, observed.FilterMessage("Unknown or unsupported metric type").Len()) diff --git a/pkg/otlp/metrics/metrics_translator.go b/pkg/otlp/metrics/metrics_translator.go index 586534c3..adccf345 100644 --- a/pkg/otlp/metrics/metrics_translator.go +++ b/pkg/otlp/metrics/metrics_translator.go @@ -23,6 +23,7 @@ import ( "strings" "time" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" @@ -62,7 +63,7 @@ type Metadata struct { } // NewTranslator creates a new translator with given options. -func NewTranslator(logger *zap.Logger, options ...TranslatorOption) (*Translator, error) { +func NewTranslator(set component.TelemetrySettings, options ...TranslatorOption) (*Translator, error) { cfg := translatorConfig{ HistMode: HistogramModeDistributions, SendHistogramAggregations: false, @@ -90,7 +91,7 @@ func NewTranslator(logger *zap.Logger, options ...TranslatorOption) (*Translator cache := newTTLCache(cfg.sweepInterval, cfg.deltaTTL) return &Translator{ prevPts: cache, - logger: logger.With(zap.String("component", "metrics translator")), + logger: set.Logger.With(zap.String("component", "metrics translator")), cfg: cfg, }, nil } diff --git a/pkg/otlp/metrics/metrics_translator_benchmark_test.go b/pkg/otlp/metrics/metrics_translator_benchmark_test.go index 8d665006..e07f6ae1 100644 --- a/pkg/otlp/metrics/metrics_translator_benchmark_test.go +++ b/pkg/otlp/metrics/metrics_translator_benchmark_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" @@ -52,8 +53,10 @@ func newBenchmarkTranslator(b *testing.B, logger *zap.Logger, opts ...Translator WithNumberMode(NumberModeCumulativeToDelta), }, opts...) + set := componenttest.NewNopTelemetrySettings() + set.Logger = logger tr, err := NewTranslator( - logger, + set, options..., ) diff --git a/pkg/otlp/metrics/metrics_translator_test.go b/pkg/otlp/metrics/metrics_translator_test.go index 0651307a..f7f26d72 100644 --- a/pkg/otlp/metrics/metrics_translator_test.go +++ b/pkg/otlp/metrics/metrics_translator_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" @@ -105,8 +106,10 @@ func newTranslator(t *testing.T, logger *zap.Logger) *Translator { WithHistogramAggregations(), } + set := componenttest.NewNopTelemetrySettings() + set.Logger = logger tr, err := NewTranslator( - logger, + set, options..., ) @@ -432,7 +435,7 @@ func TestMapRuntimeMetricsHasMapping(t *testing.T) { func TestMapRuntimeMetricsHasMappingCollector(t *testing.T) { ctx := context.Background() tr, err := NewTranslator( - zap.NewNop(), + componenttest.NewNopTelemetrySettings(), WithRemapping(), ) require.NoError(t, err) @@ -485,7 +488,7 @@ func TestMapSumRuntimeMetricWithAttributesHasMapping(t *testing.T) { func TestMapSumRuntimeMetricWithAttributesHasMappingCollector(t *testing.T) { ctx := context.Background() tr, err := NewTranslator( - zap.NewNop(), + componenttest.NewNopTelemetrySettings(), WithRemapping(), ) require.NoError(t, err) @@ -733,7 +736,7 @@ func TestMapRuntimeMetricsNoMapping(t *testing.T) { func TestMapSystemMetrics(t *testing.T) { ctx := context.Background() tr, err := NewTranslator( - zap.NewNop(), + componenttest.NewNopTelemetrySettings(), WithRemapping(), ) require.NoError(t, err) diff --git a/pkg/otlp/metrics/mixed_metrics_test.go b/pkg/otlp/metrics/mixed_metrics_test.go index 9e4e6e34..48c4f960 100644 --- a/pkg/otlp/metrics/mixed_metrics_test.go +++ b/pkg/otlp/metrics/mixed_metrics_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" @@ -142,9 +143,10 @@ func TestMapMetrics(t *testing.T) { for _, testinstance := range tests { t.Run(testinstance.name, func(t *testing.T) { + set := componenttest.NewNopTelemetrySettings() core, observed := observer.New(zapcore.DebugLevel) - testLogger := zap.New(core) - translator, err := NewTranslator(testLogger, testinstance.options...) + set.Logger = zap.New(core) + translator, err := NewTranslator(set, testinstance.options...) require.NoError(t, err) AssertTranslatorMap(t, translator, testinstance.otlpfile, testinstance.ddogfile) assert.Equal(t, testinstance.expectedUnknownMetricType, observed.FilterMessage("Unknown or unsupported metric type").Len()) diff --git a/pkg/otlp/metrics/summary_test.go b/pkg/otlp/metrics/summary_test.go index 2c95f30b..21ff2679 100644 --- a/pkg/otlp/metrics/summary_test.go +++ b/pkg/otlp/metrics/summary_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "go.uber.org/zap" + "go.opentelemetry.io/collector/component/componenttest" ) func TestSummaryMetrics(t *testing.T) { @@ -56,7 +56,7 @@ func TestSummaryMetrics(t *testing.T) { for _, testinstance := range tests { t.Run(testinstance.name, func(t *testing.T) { - translator, err := NewTranslator(zap.NewNop(), testinstance.options...) + translator, err := NewTranslator(componenttest.NewNopTelemetrySettings(), testinstance.options...) require.NoError(t, err) AssertTranslatorMap(t, translator, testinstance.otlpfile, testinstance.ddogfile) }) diff --git a/pkg/otlp/metrics/testhelper_test.go b/pkg/otlp/metrics/testhelper_test.go index a0bc17a3..0ec7311c 100644 --- a/pkg/otlp/metrics/testhelper_test.go +++ b/pkg/otlp/metrics/testhelper_test.go @@ -19,8 +19,8 @@ import ( "github.com/DataDog/opentelemetry-mapping-go/pkg/quantile/summary" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pmetric" - "go.uber.org/zap" ) // TestMetrics is the struct used for serializing Datadog metrics for generating testdata. @@ -225,7 +225,7 @@ func TestAssertTranslatorMapFailure(t *testing.T) { // Compare OTLP file with incorrect output ddogfile := "testdata/datadogdata/histogram/simple-delta_nobuckets-cs.json" - translator, err := NewTranslator(zap.NewNop(), WithHistogramMode(HistogramModeDistributions)) + translator, err := NewTranslator(componenttest.NewNopTelemetrySettings(), WithHistogramMode(HistogramModeDistributions)) require.NoError(t, err) mockTesting := &testingTMock{t} assert.False(t, AssertTranslatorMap(mockTesting, translator, otlpfile, ddogfile), "AssertTranslatorMap should have failed but did not")