Skip to content

Commit

Permalink
[pkg/otlp/metrics] Make NewTranslator take a component.TelemetrySetti…
Browse files Browse the repository at this point in the history
…ngs instead of a logger (#218)

* [pkg/otlp/metrics] Make NewTranslator take a component.TelemetrySettings instead of a logger

* Add changelog entry

* make gen-licenses
  • Loading branch information
mx-psi authored Dec 12, 2023
1 parent 5432be0 commit 3086b1d
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 18 deletions.
16 changes: 16 additions & 0 deletions .chloggen/mx-psi_counter-hostname.yaml
Original file line number Diff line number Diff line change
@@ -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:
22 changes: 22 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> | Jason Mooberry <[email protected]> | Sergey Shepelev <[email protected]> | Alex Edwards <[email protected]>"
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
Expand All @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions pkg/otlp/metrics/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
32 changes: 31 additions & 1 deletion pkg/otlp/metrics/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
10 changes: 6 additions & 4 deletions pkg/otlp/metrics/histograms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions pkg/otlp/metrics/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/otlp/metrics/metrics_translator_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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...,
)

Expand Down
11 changes: 7 additions & 4 deletions pkg/otlp/metrics/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...,
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/otlp/metrics/mixed_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions pkg/otlp/metrics/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
Expand Down
Loading

0 comments on commit 3086b1d

Please sign in to comment.