From 51657472dd29f36e99c96d04be9af6948e7b8ee4 Mon Sep 17 00:00:00 2001 From: Kylian Serrania Date: Mon, 20 Sep 2021 18:03:05 +0200 Subject: [PATCH 1/4] [datadogexporter] Add option to send instrumentation library metadata with metrics --- exporter/datadogexporter/config/config.go | 4 +++ exporter/datadogexporter/example/config.yaml | 5 +++ exporter/datadogexporter/factory.go | 3 +- .../instrumentationlibrary/metadata.go | 21 +++++++++++ .../instrumentationlibrary/metadata_test.go | 31 ++++++++++++++++ .../internal/translator/metrics_translator.go | 35 +++++++++++-------- 6 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 exporter/datadogexporter/internal/instrumentationlibrary/metadata.go create mode 100644 exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go diff --git a/exporter/datadogexporter/config/config.go b/exporter/datadogexporter/config/config.go index 66cd66ae660d..f08e6af93e39 100644 --- a/exporter/datadogexporter/config/config.go +++ b/exporter/datadogexporter/config/config.go @@ -126,6 +126,10 @@ type MetricsExporterConfig struct { // ResourceAttributesAsTags, if set to true, will use the exporterhelper feature to transform all // resource attributes into metric labels, which are then converted into tags ResourceAttributesAsTags bool `mapstructure:"resource_attributes_as_tags"` + + // InstrumentationLibraryMetadataAsTags, if set to true, adds the name and version of the + // instrumentation library that created a metric to the metric tags + InstrumentationLibraryMetadataAsTags bool `mapstructure:"instrumentation_library_metadata_as_tags"` } // TracesConfig defines the traces exporter specific configuration options diff --git a/exporter/datadogexporter/example/config.yaml b/exporter/datadogexporter/example/config.yaml index acfd8d159e63..7f64dfb07be3 100644 --- a/exporter/datadogexporter/example/config.yaml +++ b/exporter/datadogexporter/example/config.yaml @@ -92,6 +92,11 @@ exporters: # # resource_attributes_as_tags: false + ## @param instrumentation_library_metadata_as_tags - string - optional - default: false + ## Set to true to add metadata about the instrumentation library that created a metric. + # + # instrumentation_library_metadata_as_tags: false + ## @param histograms - custom object - optional ## Histograms specific configuration. ## @param mode - string - optional - default: nobuckets diff --git a/exporter/datadogexporter/factory.go b/exporter/datadogexporter/factory.go index 922b7552e703..73a44b04ef86 100644 --- a/exporter/datadogexporter/factory.go +++ b/exporter/datadogexporter/factory.go @@ -69,7 +69,8 @@ func createDefaultConfig() config.Exporter { DeltaTTL: 3600, Quantiles: true, ExporterConfig: ddconfig.MetricsExporterConfig{ - ResourceAttributesAsTags: false, + ResourceAttributesAsTags: false, + InstrumentationLibraryMetadataAsTags: false, }, HistConfig: ddconfig.HistogramConfig{ Mode: "nobuckets", diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go new file mode 100644 index 000000000000..923a45f5046c --- /dev/null +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go @@ -0,0 +1,21 @@ +package instrumentationlibrary + +import ( + "fmt" + + "go.opentelemetry.io/collector/model/pdata" +) + +const ( + instrumentationLibraryTag = "instrumentation_library" + instrumentationLibraryVersionTag = "instrumentation_library_version" +) + +// TagsFromInstrumentationLibraryMetadata takes the name and version of +// the instrumentation library and converts them to Datadog tags. +func TagsFromInstrumentationLibraryMetadata(il pdata.InstrumentationLibrary) []string { + return []string{ + fmt.Sprintf("%s:%s", instrumentationLibraryTag, il.Name()), + fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, il.Version()), + } +} diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go new file mode 100644 index 000000000000..0e9e7756c0ea --- /dev/null +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go @@ -0,0 +1,31 @@ +package instrumentationlibrary + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/model/pdata" +) + +func TestTagsFromInstrumentationLibraryMetadata(t *testing.T) { + tests := []struct { + name string + version string + expectedTags []string + }{ + {"test-il", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "1.0.0")}}, + {"test-il", "", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "")}}, + {"", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, ""), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "1.0.0")}}, + } + + for _, testInstance := range tests { + fmt.Println(testInstance) + il := pdata.NewInstrumentationLibrary() + il.SetName(testInstance.name) + il.SetVersion(testInstance.version) + tags := TagsFromInstrumentationLibraryMetadata(il) + + assert.ElementsMatch(t, testInstance.expectedTags, tags) + } +} diff --git a/exporter/datadogexporter/internal/translator/metrics_translator.go b/exporter/datadogexporter/internal/translator/metrics_translator.go index 538ac2250d3e..c61c595b1650 100644 --- a/exporter/datadogexporter/internal/translator/metrics_translator.go +++ b/exporter/datadogexporter/internal/translator/metrics_translator.go @@ -29,6 +29,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/attributes" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/instrumentationlibrary" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/sketches" ) @@ -95,12 +96,12 @@ func (t *Translator) isSkippable(name string, v float64) bool { } // mapNumberMetrics maps double datapoints into Datadog metrics -func (t *Translator) mapNumberMetrics(name string, dt metrics.MetricDataType, slice pdata.NumberDataPointSlice, attrTags []string) []datadog.Metric { +func (t *Translator) mapNumberMetrics(name string, dt metrics.MetricDataType, slice pdata.NumberDataPointSlice, additionalTags []string) []datadog.Metric { ms := make([]datadog.Metric, 0, slice.Len()) for i := 0; i < slice.Len(); i++ { p := slice.At(i) tags := getTags(p.Attributes()) - tags = append(tags, attrTags...) + tags = append(tags, additionalTags...) var val float64 switch p.Type() { case pdata.MetricValueTypeDouble: @@ -121,13 +122,13 @@ func (t *Translator) mapNumberMetrics(name string, dt metrics.MetricDataType, sl } // mapNumberMonotonicMetrics maps monotonic datapoints into Datadog metrics -func (t *Translator) mapNumberMonotonicMetrics(name string, slice pdata.NumberDataPointSlice, attrTags []string) []datadog.Metric { +func (t *Translator) mapNumberMonotonicMetrics(name string, slice pdata.NumberDataPointSlice, additionalTags []string) []datadog.Metric { ms := make([]datadog.Metric, 0, slice.Len()) for i := 0; i < slice.Len(); i++ { p := slice.At(i) ts := uint64(p.Timestamp()) tags := getTags(p.Attributes()) - tags = append(tags, attrTags...) + tags = append(tags, additionalTags...) var val float64 switch p.Type() { @@ -229,7 +230,7 @@ func (t *Translator) getLegacyBuckets(name string, p pdata.HistogramDataPoint, d // We follow a similar approach to our OpenMetrics check: // we report sum and count by default; buckets count can also // be reported (opt-in) tagged by lower bound. -func (t *Translator) mapHistogramMetrics(name string, slice pdata.HistogramDataPointSlice, delta bool, attrTags []string) (ms []datadog.Metric, sl sketches.SketchSeriesList) { +func (t *Translator) mapHistogramMetrics(name string, slice pdata.HistogramDataPointSlice, delta bool, additionalTags []string) (ms []datadog.Metric, sl sketches.SketchSeriesList) { // Allocate assuming none are nil and no buckets ms = make([]datadog.Metric, 0, 2*slice.Len()) if t.cfg.HistConfig.Mode == histogramModeDistributions { @@ -239,7 +240,7 @@ func (t *Translator) mapHistogramMetrics(name string, slice pdata.HistogramDataP p := slice.At(i) ts := uint64(p.Timestamp()) tags := getTags(p.Attributes()) - tags = append(tags, attrTags...) + tags = append(tags, additionalTags...) if t.cfg.HistConfig.SendCountSum { count := float64(p.Count()) @@ -301,14 +302,14 @@ func getQuantileTag(quantile float64) string { } // mapSummaryMetrics maps summary datapoints into Datadog metrics -func (t *Translator) mapSummaryMetrics(name string, slice pdata.SummaryDataPointSlice, attrTags []string) []datadog.Metric { +func (t *Translator) mapSummaryMetrics(name string, slice pdata.SummaryDataPointSlice, additionalTags []string) []datadog.Metric { // Allocate assuming none are nil and no quantiles ms := make([]datadog.Metric, 0, 2*slice.Len()) for i := 0; i < slice.Len(); i++ { p := slice.At(i) ts := uint64(p.Timestamp()) tags := getTags(p.Attributes()) - tags = append(tags, attrTags...) + tags = append(tags, additionalTags...) // count and sum are increasing; we treat them as cumulative monotonic sums. { @@ -378,23 +379,29 @@ func (t *Translator) MapMetrics(md pdata.Metrics) (series []datadog.Metric, sl s for j := 0; j < ilms.Len(); j++ { ilm := ilms.At(j) metricsArray := ilm.Metrics() + + var additionalTags []string + if t.cfg.ExporterConfig.InstrumentationLibraryMetadataAsTags { + additionalTags = append(attributeTags, instrumentationlibrary.TagsFromInstrumentationLibraryMetadata(ilm.InstrumentationLibrary())...) + } + for k := 0; k < metricsArray.Len(); k++ { md := metricsArray.At(k) var datapoints []datadog.Metric var sketchesPoints sketches.SketchSeriesList switch md.DataType() { case pdata.MetricDataTypeGauge: - datapoints = t.mapNumberMetrics(md.Name(), metrics.Gauge, md.Gauge().DataPoints(), attributeTags) + datapoints = t.mapNumberMetrics(md.Name(), metrics.Gauge, md.Gauge().DataPoints(), additionalTags) case pdata.MetricDataTypeSum: switch md.Sum().AggregationTemporality() { case pdata.AggregationTemporalityCumulative: if t.cfg.SendMonotonic && isCumulativeMonotonic(md) { - datapoints = t.mapNumberMonotonicMetrics(md.Name(), md.Sum().DataPoints(), attributeTags) + datapoints = t.mapNumberMonotonicMetrics(md.Name(), md.Sum().DataPoints(), additionalTags) } else { - datapoints = t.mapNumberMetrics(md.Name(), metrics.Gauge, md.Sum().DataPoints(), attributeTags) + datapoints = t.mapNumberMetrics(md.Name(), metrics.Gauge, md.Sum().DataPoints(), additionalTags) } case pdata.AggregationTemporalityDelta: - datapoints = t.mapNumberMetrics(md.Name(), metrics.Count, md.Sum().DataPoints(), attributeTags) + datapoints = t.mapNumberMetrics(md.Name(), metrics.Count, md.Sum().DataPoints(), additionalTags) default: // pdata.AggregationTemporalityUnspecified or any other not supported type t.logger.Debug("Unknown or unsupported aggregation temporality", zap.String(metricName, md.Name()), @@ -406,7 +413,7 @@ func (t *Translator) MapMetrics(md pdata.Metrics) (series []datadog.Metric, sl s switch md.Histogram().AggregationTemporality() { case pdata.AggregationTemporalityCumulative, pdata.AggregationTemporalityDelta: delta := md.Histogram().AggregationTemporality() == pdata.AggregationTemporalityDelta - datapoints, sketchesPoints = t.mapHistogramMetrics(md.Name(), md.Histogram().DataPoints(), delta, attributeTags) + datapoints, sketchesPoints = t.mapHistogramMetrics(md.Name(), md.Histogram().DataPoints(), delta, additionalTags) default: // pdata.AggregationTemporalityUnspecified or any other not supported type t.logger.Debug("Unknown or unsupported aggregation temporality", zap.String("metric name", md.Name()), @@ -415,7 +422,7 @@ func (t *Translator) MapMetrics(md pdata.Metrics) (series []datadog.Metric, sl s continue } case pdata.MetricDataTypeSummary: - datapoints = t.mapSummaryMetrics(md.Name(), md.Summary().DataPoints(), attributeTags) + datapoints = t.mapSummaryMetrics(md.Name(), md.Summary().DataPoints(), additionalTags) default: // pdata.MetricDataTypeNone or any other not supported type t.logger.Debug("Unknown or unsupported metric type", zap.String(metricName, md.Name()), zap.Any("data type", md.DataType())) continue From 860e412536a66b5f626e4e02a9e73f457af6fcea Mon Sep 17 00:00:00 2001 From: Kylian Serrania Date: Fri, 24 Sep 2021 16:47:46 +0200 Subject: [PATCH 2/4] Add License text --- .../internal/instrumentationlibrary/metadata.go | 14 ++++++++++++++ .../instrumentationlibrary/metadata_test.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go index 923a45f5046c..2f6437bf8448 100644 --- a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go @@ -1,3 +1,17 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package instrumentationlibrary import ( diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go index 0e9e7756c0ea..d693cee1a9c6 100644 --- a/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go @@ -1,3 +1,17 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package instrumentationlibrary import ( From 57a1e0d9983beaa6b92991a11173a5b2f31d4b3e Mon Sep 17 00:00:00 2001 From: Kylian Serrania Date: Sat, 25 Sep 2021 11:47:55 +0200 Subject: [PATCH 3/4] Add tags formatting util --- .../instrumentationlibrary/metadata.go | 8 ++-- .../instrumentationlibrary/metadata_test.go | 6 +-- .../internal/translator/metrics_translator.go | 7 +--- .../datadogexporter/internal/utils/tags.go | 29 +++++++++++++++ .../internal/utils/tags_test.go | 37 +++++++++++++++++++ 5 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 exporter/datadogexporter/internal/utils/tags.go create mode 100644 exporter/datadogexporter/internal/utils/tags_test.go diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go index 2f6437bf8448..44166929bf43 100644 --- a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go @@ -15,9 +15,9 @@ package instrumentationlibrary import ( - "fmt" - "go.opentelemetry.io/collector/model/pdata" + + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/utils" ) const ( @@ -29,7 +29,7 @@ const ( // the instrumentation library and converts them to Datadog tags. func TagsFromInstrumentationLibraryMetadata(il pdata.InstrumentationLibrary) []string { return []string{ - fmt.Sprintf("%s:%s", instrumentationLibraryTag, il.Name()), - fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, il.Version()), + utils.FormatKeyValueTag(instrumentationLibraryTag, il.Name()), + utils.FormatKeyValueTag(instrumentationLibraryVersionTag, il.Version()), } } diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go index d693cee1a9c6..c84cd4539fdd 100644 --- a/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata_test.go @@ -29,12 +29,12 @@ func TestTagsFromInstrumentationLibraryMetadata(t *testing.T) { expectedTags []string }{ {"test-il", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "1.0.0")}}, - {"test-il", "", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "")}}, - {"", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, ""), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "1.0.0")}}, + {"test-il", "", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "n/a")}}, + {"", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "n/a"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "1.0.0")}}, + {"", "", []string{fmt.Sprintf("%s:%s", instrumentationLibraryTag, "n/a"), fmt.Sprintf("%s:%s", instrumentationLibraryVersionTag, "n/a")}}, } for _, testInstance := range tests { - fmt.Println(testInstance) il := pdata.NewInstrumentationLibrary() il.SetName(testInstance.name) il.SetVersion(testInstance.version) diff --git a/exporter/datadogexporter/internal/translator/metrics_translator.go b/exporter/datadogexporter/internal/translator/metrics_translator.go index c61c595b1650..8b2b7cbc4220 100644 --- a/exporter/datadogexporter/internal/translator/metrics_translator.go +++ b/exporter/datadogexporter/internal/translator/metrics_translator.go @@ -32,6 +32,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/instrumentationlibrary" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/sketches" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/utils" ) const metricName string = "metric name" @@ -65,11 +66,7 @@ func getTags(labels pdata.AttributeMap) []string { tags := make([]string, 0, labels.Len()) labels.Range(func(key string, value pdata.AttributeValue) bool { v := value.AsString() - if v == "" { - // Tags can't end with ":" so we replace empty values with "n/a" - v = "n/a" - } - tags = append(tags, fmt.Sprintf("%s:%s", key, v)) + tags = append(tags, utils.FormatKeyValueTag(key, v)) return true }) return tags diff --git a/exporter/datadogexporter/internal/utils/tags.go b/exporter/datadogexporter/internal/utils/tags.go new file mode 100644 index 000000000000..0c7625fbccc5 --- /dev/null +++ b/exporter/datadogexporter/internal/utils/tags.go @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package utils + +import ( + "fmt" +) + +// FormatKeyValueTag takes a key-value pair, and creates a tag string out of it +// Tags can't end with ":" so we replace empty values with "n/a" +func FormatKeyValueTag(key, value string) string { + // Should this check for empty keys, and return an error in that case? + if value == "" { + value = "n/a" + } + return fmt.Sprintf("%s:%s", key, value) +} diff --git a/exporter/datadogexporter/internal/utils/tags_test.go b/exporter/datadogexporter/internal/utils/tags_test.go new file mode 100644 index 000000000000..a70aec0a748b --- /dev/null +++ b/exporter/datadogexporter/internal/utils/tags_test.go @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package utils + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFormatKeyValueTag(t *testing.T) { + tests := []struct { + key string + value string + expectedTag string + }{ + {"a.test.tag", "a.test.value", fmt.Sprintf("%s:%s", "a.test.tag", "a.test.value")}, + {"a.test.tag", "", fmt.Sprintf("%s:%s", "a.test.tag", "n/a")}, + } + + for _, testInstance := range tests { + assert.Equal(t, testInstance.expectedTag, FormatKeyValueTag(testInstance.key, testInstance.value)) + } +} From 7786b88e195e15752e5ec7036dec1254d841817d Mon Sep 17 00:00:00 2001 From: Kylian Serrania Date: Mon, 27 Sep 2021 10:28:10 +0200 Subject: [PATCH 4/4] Address review comments --- .../internal/instrumentationlibrary/metadata.go | 6 +++--- .../internal/translator/metrics_translator.go | 2 +- .../datadogexporter/internal/{ => translator}/utils/tags.go | 1 - .../internal/{ => translator}/utils/tags_test.go | 5 ++--- 4 files changed, 6 insertions(+), 8 deletions(-) rename exporter/datadogexporter/internal/{ => translator}/utils/tags.go (92%) rename exporter/datadogexporter/internal/{ => translator}/utils/tags_test.go (85%) diff --git a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go index 44166929bf43..f4f46891601c 100644 --- a/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go +++ b/exporter/datadogexporter/internal/instrumentationlibrary/metadata.go @@ -17,7 +17,7 @@ package instrumentationlibrary import ( "go.opentelemetry.io/collector/model/pdata" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/utils" + translatorUtils "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/translator/utils" ) const ( @@ -29,7 +29,7 @@ const ( // the instrumentation library and converts them to Datadog tags. func TagsFromInstrumentationLibraryMetadata(il pdata.InstrumentationLibrary) []string { return []string{ - utils.FormatKeyValueTag(instrumentationLibraryTag, il.Name()), - utils.FormatKeyValueTag(instrumentationLibraryVersionTag, il.Version()), + translatorUtils.FormatKeyValueTag(instrumentationLibraryTag, il.Name()), + translatorUtils.FormatKeyValueTag(instrumentationLibraryVersionTag, il.Version()), } } diff --git a/exporter/datadogexporter/internal/translator/metrics_translator.go b/exporter/datadogexporter/internal/translator/metrics_translator.go index 8b2b7cbc4220..f6d7c396a566 100644 --- a/exporter/datadogexporter/internal/translator/metrics_translator.go +++ b/exporter/datadogexporter/internal/translator/metrics_translator.go @@ -32,7 +32,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/instrumentationlibrary" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/sketches" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/utils" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/translator/utils" ) const metricName string = "metric name" diff --git a/exporter/datadogexporter/internal/utils/tags.go b/exporter/datadogexporter/internal/translator/utils/tags.go similarity index 92% rename from exporter/datadogexporter/internal/utils/tags.go rename to exporter/datadogexporter/internal/translator/utils/tags.go index 0c7625fbccc5..e06c3dbc36ce 100644 --- a/exporter/datadogexporter/internal/utils/tags.go +++ b/exporter/datadogexporter/internal/translator/utils/tags.go @@ -21,7 +21,6 @@ import ( // FormatKeyValueTag takes a key-value pair, and creates a tag string out of it // Tags can't end with ":" so we replace empty values with "n/a" func FormatKeyValueTag(key, value string) string { - // Should this check for empty keys, and return an error in that case? if value == "" { value = "n/a" } diff --git a/exporter/datadogexporter/internal/utils/tags_test.go b/exporter/datadogexporter/internal/translator/utils/tags_test.go similarity index 85% rename from exporter/datadogexporter/internal/utils/tags_test.go rename to exporter/datadogexporter/internal/translator/utils/tags_test.go index a70aec0a748b..4d9450c21661 100644 --- a/exporter/datadogexporter/internal/utils/tags_test.go +++ b/exporter/datadogexporter/internal/translator/utils/tags_test.go @@ -15,7 +15,6 @@ package utils import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -27,8 +26,8 @@ func TestFormatKeyValueTag(t *testing.T) { value string expectedTag string }{ - {"a.test.tag", "a.test.value", fmt.Sprintf("%s:%s", "a.test.tag", "a.test.value")}, - {"a.test.tag", "", fmt.Sprintf("%s:%s", "a.test.tag", "n/a")}, + {"a.test.tag", "a.test.value", "a.test.tag:a.test.value"}, + {"a.test.tag", "", "a.test.tag:n/a"}, } for _, testInstance := range tests {