Skip to content

Commit 32f6541

Browse files
authored
[exporter/datadog] Deprecate TagsConfig.GetHostTags method (open-telemetry#8975)
* [exporter/datadog] Deprecate GetHostTags method * Also add `nolint` to silence all the linters * Add CHANGELOG entry
1 parent e52d6be commit 32f6541

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
- `datadogexporter`: Deprecate `service` setting in favor of `service.name` semantic convention (#8784)
1919
- `datadogexporter`: Deprecate `version` setting in favor of `service.version` semantic convention (#8784)
20+
- `datadogexporter`: Deprecate `GetHostTags` method from `TagsConfig` struct (#8975)
2021

2122
### 🚀 New components 🚀
2223

exporter/datadogexporter/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ type TagsConfig struct {
244244
}
245245

246246
// GetHostTags gets the host tags extracted from the configuration
247+
// Deprecated: [v0.49.0] Access fields explicitly instead.
247248
func (t *TagsConfig) GetHostTags() []string {
248249
tags := t.Tags
249250

exporter/datadogexporter/hostmetadata.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,33 @@
1515
package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"
1616

1717
import (
18+
"fmt"
19+
"strings"
20+
1821
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
1922
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata"
2023
)
2124

25+
// getHostTags gets the host tags extracted from the configuration.
26+
func getHostTags(t *config.TagsConfig) []string {
27+
tags := t.Tags
28+
29+
if len(tags) == 0 {
30+
//lint:ignore SA1019 Will be removed when environment variable detection is removed
31+
tags = strings.Split(t.EnvVarTags, " ") //nolint
32+
}
33+
34+
if t.Env != "none" {
35+
tags = append(tags, fmt.Sprintf("env:%s", t.Env))
36+
}
37+
return tags
38+
}
39+
2240
// newMetadataConfigfromConfig creates a new metadata pusher config from the main config.
2341
func newMetadataConfigfromConfig(cfg *config.Config) metadata.PusherConfig {
2442
return metadata.PusherConfig{
2543
ConfigHostname: cfg.Hostname,
26-
ConfigTags: cfg.GetHostTags(),
44+
ConfigTags: getHostTags(&cfg.TagsConfig),
2745
MetricsEndpoint: cfg.Metrics.Endpoint,
2846
APIKey: cfg.API.Key,
2947
UseResourceMetadata: cfg.UseResourceMetadata,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
22+
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
23+
)
24+
25+
func TestHostTags(t *testing.T) {
26+
tc := config.TagsConfig{
27+
Hostname: "customhost",
28+
Env: "customenv",
29+
// Service and version should be only used for traces
30+
Service: "customservice",
31+
Version: "customversion",
32+
Tags: []string{"key1:val1", "key2:val2"},
33+
}
34+
35+
assert.ElementsMatch(t,
36+
[]string{
37+
"env:customenv",
38+
"key1:val1",
39+
"key2:val2",
40+
},
41+
getHostTags(&tc),
42+
)
43+
44+
tc = config.TagsConfig{
45+
Hostname: "customhost",
46+
Env: "customenv",
47+
// Service and version should be only used for traces
48+
Service: "customservice",
49+
Version: "customversion",
50+
Tags: []string{"key1:val1", "key2:val2"},
51+
EnvVarTags: "key3:val3 key4:val4",
52+
}
53+
54+
assert.ElementsMatch(t,
55+
[]string{
56+
"env:customenv",
57+
"key1:val1",
58+
"key2:val2",
59+
},
60+
getHostTags(&tc),
61+
)
62+
63+
tc = config.TagsConfig{
64+
Hostname: "customhost",
65+
Env: "customenv",
66+
// Service and version should be only used for traces
67+
Service: "customservice",
68+
Version: "customversion",
69+
EnvVarTags: "key3:val3 key4:val4",
70+
}
71+
72+
assert.ElementsMatch(t,
73+
[]string{
74+
"env:customenv",
75+
"key3:val3",
76+
"key4:val4",
77+
},
78+
getHostTags(&tc),
79+
)
80+
}

0 commit comments

Comments
 (0)