Skip to content

Commit

Permalink
[datadogexporter]: Do not rely on collector to resolve envvar when po…
Browse files Browse the repository at this point in the history
…ssible to resolve them (#6122)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Nov 4, 2021
1 parent c1b1ce4 commit 92f0cc3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
19 changes: 10 additions & 9 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package datadogexporter

import (
"context"
"os"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
Expand Down Expand Up @@ -53,21 +54,21 @@ func createDefaultConfig() config.Exporter {
QueueSettings: exporterhelper.DefaultQueueSettings(),

API: ddconfig.APIConfig{
Key: "$DD_API_KEY", // Must be set if using API
Site: "$DD_SITE", // If not provided, set during config sanitization
Key: os.Getenv("DD_API_KEY"), // Must be set if using API
Site: os.Getenv("DD_SITE"), // If not provided, set during config sanitization
},

TagsConfig: ddconfig.TagsConfig{
Hostname: "$DD_HOST",
Env: "$DD_ENV",
Service: "$DD_SERVICE",
Version: "$DD_VERSION",
EnvVarTags: "$DD_TAGS", // Only taken into account if Tags is not set
Hostname: os.Getenv("DD_HOST"),
Env: os.Getenv("DD_ENV"),
Service: os.Getenv("DD_SERVICE"),
Version: os.Getenv("DD_VERSION"),
EnvVarTags: os.Getenv("DD_TAGS"), // Only taken into account if Tags is not set
},

Metrics: ddconfig.MetricsConfig{
TCPAddr: confignet.TCPAddr{
Endpoint: "$DD_URL", // If not provided, set during config sanitization
Endpoint: os.Getenv("DD_URL"), // If not provided, set during config sanitization
},
SendMonotonic: true,
DeltaTTL: 3600,
Expand All @@ -85,7 +86,7 @@ func createDefaultConfig() config.Exporter {
Traces: ddconfig.TracesConfig{
SampleRate: 1,
TCPAddr: confignet.TCPAddr{
Endpoint: "$DD_APM_URL", // If not provided, set during config sanitization
Endpoint: os.Getenv("DD_APM_URL"), // If not provided, set during config sanitization
},
IgnoreResources: []string{},
},
Expand Down
38 changes: 29 additions & 9 deletions exporter/datadogexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ import (

// Test that the factory creates the default configuration
func TestCreateDefaultConfig(t *testing.T) {
assert.NoError(t, os.Setenv("DD_API_KEY", "API_KEY"))
assert.NoError(t, os.Setenv("DD_SITE", "SITE"))
assert.NoError(t, os.Setenv("DD_URL", "URL"))
assert.NoError(t, os.Setenv("DD_APM_URL", "APM_URL"))
assert.NoError(t, os.Setenv("DD_HOST", "HOST"))
assert.NoError(t, os.Setenv("DD_ENV", "ENV"))
assert.NoError(t, os.Setenv("DD_SERVICE", "SERVICE"))
assert.NoError(t, os.Setenv("DD_VERSION", "VERSION"))
assert.NoError(t, os.Setenv("DD_TAGS", "TAGS"))
defer func() {
assert.NoError(t, os.Unsetenv("DD_API_KEY"))
assert.NoError(t, os.Unsetenv("DD_SITE"))
assert.NoError(t, os.Unsetenv("DD_URL"))
assert.NoError(t, os.Unsetenv("DD_APM_URL"))
assert.NoError(t, os.Unsetenv("DD_HOST"))
assert.NoError(t, os.Unsetenv("DD_ENV"))
assert.NoError(t, os.Unsetenv("DD_SERVICE"))
assert.NoError(t, os.Unsetenv("DD_VERSION"))
assert.NoError(t, os.Unsetenv("DD_TAGS"))
}()
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

Expand All @@ -49,13 +69,13 @@ func TestCreateDefaultConfig(t *testing.T) {
QueueSettings: exporterhelper.DefaultQueueSettings(),

API: ddconfig.APIConfig{
Key: "$DD_API_KEY",
Site: "$DD_SITE",
Key: "API_KEY",
Site: "SITE",
},

Metrics: ddconfig.MetricsConfig{
TCPAddr: confignet.TCPAddr{
Endpoint: "$DD_URL",
Endpoint: "URL",
},
DeltaTTL: 3600,
SendMonotonic: true,
Expand All @@ -69,17 +89,17 @@ func TestCreateDefaultConfig(t *testing.T) {
Traces: ddconfig.TracesConfig{
SampleRate: 1,
TCPAddr: confignet.TCPAddr{
Endpoint: "$DD_APM_URL",
Endpoint: "APM_URL",
},
IgnoreResources: []string{},
},

TagsConfig: ddconfig.TagsConfig{
Hostname: "$DD_HOST",
Env: "$DD_ENV",
Service: "$DD_SERVICE",
Version: "$DD_VERSION",
EnvVarTags: "$DD_TAGS",
Hostname: "HOST",
Env: "ENV",
Service: "SERVICE",
Version: "VERSION",
EnvVarTags: "TAGS",
},

SendMetadata: true,
Expand Down

0 comments on commit 92f0cc3

Please sign in to comment.