Skip to content

Commit

Permalink
[exporter/datadog] add instrumentation_scope_metadata_as_tags (#11135)
Browse files Browse the repository at this point in the history
* add `instrumentation_scope_metadata_as_tags`

* update CHANGELOG

* fix lint

* add the version that deprecates instrumentation_scope_metadata_as_tags

* add this change to Enhancements section

* fix typo
  • Loading branch information
keisku authored Jun 22, 2022
1 parent 2b7a3c7 commit bfdaa34
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### 🚩 Deprecations 🚩

- `datadogexporter`: Deprecate `instrumentation_library_metadata_as_tags` (#11135)
- `datadogexporter`: Deprecate `Sanitize` method of `Config` struct (#8829)
- `observiqexporter`: Deprecate the observiq exporter (#10977)
- `honeycombexporter`: Deprecate honeycomb exporter (#10318)
Expand All @@ -32,6 +33,7 @@
- `tailsamplingprocessor`: New sampler added that allows to sample based on minimum number of spans
- `datadogexporter`: Some config validation and unmarshaling steps are now done on `Validate` and `Unmarshal` instead of `Sanitize` (#8829)
- `datadogexporter`: Add `exporter.datadog.hostname.preview` feature flag and related warnings (#10926)
- `datadogexporter`: Add `instrumentation_scope_metadata_as_tags` instead of `instrumentation_library_metadata_as_tags` in favor of https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0 (#11135)
- `examples`: Add an example for scraping Couchbase metrics (#10894)
- `filestorageextension`: Add background compaction capability (#9327)
- `googlecloudpubsubreceiver`: Added new `Endpoint` and `Insecure` connection configuration options. (#10845)
Expand Down
6 changes: 6 additions & 0 deletions exporter/datadogexporter/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,15 @@ type MetricsExporterConfig struct {
// resource attributes into metric labels, which are then converted into tags
ResourceAttributesAsTags bool `mapstructure:"resource_attributes_as_tags"`

// Deprecated: [0.54.0] Use InstrumentationScopeMetadataAsTags instead in favor of https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0
// Both must not be enabled at the same time.
// 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"`

// InstrumentationScopeMetadataAsTags, if set to true, adds the name and version of the
// instrumentation scope that created a metric to the metric tags
InstrumentationScopeMetadataAsTags bool `mapstructure:"instrumentation_scope_metadata_as_tags"`
}

// TracesConfig defines the traces exporter specific configuration options
Expand Down
1 change: 1 addition & 0 deletions exporter/datadogexporter/config/warn_envvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func futureDefaultConfig() *Config {
ExporterConfig: MetricsExporterConfig{
ResourceAttributesAsTags: false,
InstrumentationLibraryMetadataAsTags: false,
InstrumentationScopeMetadataAsTags: false,
},
HistConfig: HistogramConfig{
Mode: "distributions",
Expand Down
26 changes: 17 additions & 9 deletions exporter/datadogexporter/example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exporters:
## @params use_resource_metadata - boolean - optional - default: true
## Deprecated: [v0.49.0] Use `host_metadata::hostname_source` instead.
## This option will be removed in v0.52.0.
#
#
# use_resource_metadata: true

## @param only_metadata - boolean - optional - default: false
Expand Down Expand Up @@ -132,27 +132,35 @@ exporters:
#
# resource_attributes_as_tags: false

## Deprecated: [0.54.0] use instrumentation_scope_metadata_as_tags instead in favor of
## https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0
## Both must not be enabled at the same time.
## @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 instrumentation_scope_metadata_as_tags - string - optional - default: false
## Set to true to add metadata about the instrumentation scope that created a metric.
#
# instrumentation_scope_metadata_as_tags: false

## @param histograms - custom object - optional
## Histograms specific configuration.
## @param mode - string - optional - default: distributions
## How to report histograms. Valid values are:
##
##
## - `distributions` to report metrics as Datadog distributions (recommended).
## - `nobuckets` to not report bucket metrics,
## - `counters` to report one metric per histogram bucket.
#
# mode: distributions

## @param send_count_sum_metrics - boolean - optional - default: false
## Whether to report sum and count as separate histogram metrics.
#
# send_count_sum_metrics: false

## @param sums - custom object - optional
## Sums specific configuration.
## @param cumulative_monotonic_mode - string - optional - default: to_delta
Expand All @@ -167,7 +175,7 @@ exporters:
## Summaries specific configuration.
## @param mode - string - optional - default: gauges
## How to report summaries. Valid values are:
##
##
## - `noquantiles` to not report quantile metrics
## - `gauges` to report one gauge metric per quantile.
#
Expand All @@ -188,15 +196,15 @@ exporters:
## A blacklist of regular expressions can be provided to disable certain traces based on their resource name
## all entries must be surrounded by double quotes and separated by commas.
#
# ignore_resources: ["(GET|POST) /healthcheck"]
# ignore_resources: ["(GET|POST) /healthcheck"]

## @param span_name_remappings - map of key/value pairs - optional
## A map of Datadog span operation name keys and preferred name valuues to update those names to. This can be used to
## automatically map Datadog Span Operation Names to an updated value, and is useful when a user wants to
## shorten or modify span names to something more user friendly in the case of instrumentation libraries with
## particularly verbose names.
#
# span_name_remappings:
# span_name_remappings:
# io.opentelemetry.javaagent.spring.client: spring.client
# instrumentation:express.server: express
# go.opentelemetry.io_contrib_instrumentation_net_http_otelhttp.client: http.client
Expand All @@ -207,7 +215,7 @@ exporters:
## https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/1909
#
# span_name_as_resource_name: true

## @param host_metadata - custom object - optional
## Host metadata specific configuration.
## Host metadata is the information used for populating the infrastructure list, the host map and providing host tags functionality within the Datadog app.
Expand Down Expand Up @@ -237,7 +245,7 @@ exporters:
## @param tags - list of strings - optional - default: empty list
## List of host tags to be sent as part of the host metadata.
## These tags will be attached to telemetry signals that have the host metadata hostname.
##
##
## To attach tags to telemetry signals regardless of the host, use a processor instead.
#
# tags: []
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/example/example_k8s_manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This manifest file is meant as an example of how to deploy otel-agent as daemonset and otel-collector as a standalone service.
# Using this example should correctly identifies hostnames for individual k8s nodes.
# Using this example should correctly identifies hostnames for individual k8s nodes.
# This is meant as an example only and may differ depending on deployment scenario and specifics of the environment the collector is used.
---
# The k8sattributes processor may require additional
Expand Down
1 change: 1 addition & 0 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (f *factory) createDefaultConfig() config.Exporter {
ExporterConfig: ddconfig.MetricsExporterConfig{
ResourceAttributesAsTags: false,
InstrumentationLibraryMetadataAsTags: false,
InstrumentationScopeMetadataAsTags: false,
},
HistConfig: ddconfig.HistogramConfig{
Mode: "distributions",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 instrumentationscope // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/internal/instrumentationscope"

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/internal/utils"

"go.opentelemetry.io/collector/pdata/pcommon"
)

const (
instrumentationScopeTag = "instrumentation_scope"
instrumentationScopeVersionTag = "instrumentation_scope_version"
)

// TagsFromInstrumentationScopeMetadata takes the name and version of
// the instrumentation scope and converts them to Datadog tags.
func TagsFromInstrumentationScopeMetadata(il pcommon.InstrumentationScope) []string {
return []string{
utils.FormatKeyValueTag(instrumentationScopeTag, il.Name()),
utils.FormatKeyValueTag(instrumentationScopeVersionTag, il.Version()),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 instrumentationscope

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
)

func TestTagsFromInstrumentationScopeMetadata(t *testing.T) {
tests := []struct {
name string
version string
expectedTags []string
}{
{"test-il", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationScopeTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationScopeVersionTag, "1.0.0")}},
{"test-il", "", []string{fmt.Sprintf("%s:%s", instrumentationScopeTag, "test-il"), fmt.Sprintf("%s:%s", instrumentationScopeVersionTag, "n/a")}},
{"", "1.0.0", []string{fmt.Sprintf("%s:%s", instrumentationScopeTag, "n/a"), fmt.Sprintf("%s:%s", instrumentationScopeVersionTag, "1.0.0")}},
{"", "", []string{fmt.Sprintf("%s:%s", instrumentationScopeTag, "n/a"), fmt.Sprintf("%s:%s", instrumentationScopeVersionTag, "n/a")}},
}

for _, testInstance := range tests {
il := pcommon.NewInstrumentationScope()
il.SetName(testInstance.name)
il.SetVersion(testInstance.version)
tags := TagsFromInstrumentationScopeMetadata(il)

assert.ElementsMatch(t, testInstance.expectedTags, tags)
}
}
22 changes: 17 additions & 5 deletions exporter/datadogexporter/internal/model/translator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import (

type translatorConfig struct {
// metrics export behavior
HistMode HistogramMode
SendCountSum bool
Quantiles bool
SendMonotonic bool
ResourceAttributesAsTags bool
HistMode HistogramMode
SendCountSum bool
Quantiles bool
SendMonotonic bool
ResourceAttributesAsTags bool
// Deprecated: [0.54.0] Use InstrumentationScopeMetadataAsTags instead in favor of
// https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0
// Both must not be enabled at the same time.
InstrumentationLibraryMetadataAsTags bool
InstrumentationScopeMetadataAsTags bool

// cache configuration
sweepInterval int64
Expand Down Expand Up @@ -98,6 +102,14 @@ func WithInstrumentationLibraryMetadataAsTags() Option {
}
}

// WithInstrumentationScopeMetadataAsTags sets instrumentation scope metadata as tags.
func WithInstrumentationScopeMetadataAsTags() Option {
return func(t *translatorConfig) error {
t.InstrumentationScopeMetadataAsTags = true
return nil
}
}

// HistogramMode is an export mode for OTLP Histogram metrics.
type HistogramMode string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/attributes"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/internal/instrumentationlibrary"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/internal/instrumentationscope"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/source"
)

Expand Down Expand Up @@ -59,6 +60,7 @@ func New(logger *zap.Logger, options ...Option) (*Translator, error) {
SendMonotonic: true,
ResourceAttributesAsTags: false,
InstrumentationLibraryMetadataAsTags: false,
InstrumentationScopeMetadataAsTags: false,
sweepInterval: 1800,
deltaTTL: 3600,
fallbackSourceProvider: &noSourceProvider{},
Expand Down Expand Up @@ -459,7 +461,9 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume
metricsArray := ilm.Metrics()

var additionalTags []string
if t.cfg.InstrumentationLibraryMetadataAsTags {
if t.cfg.InstrumentationScopeMetadataAsTags {
additionalTags = append(attributeTags, instrumentationscope.TagsFromInstrumentationScopeMetadata(ilm.Scope())...)
} else if t.cfg.InstrumentationLibraryMetadataAsTags {
additionalTags = append(attributeTags, instrumentationlibrary.TagsFromInstrumentationLibraryMetadata(ilm.Scope())...)
} else {
additionalTags = attributeTags
Expand Down
Loading

0 comments on commit bfdaa34

Please sign in to comment.