Skip to content

Commit

Permalink
ddtrace/tracer: update the tag naming convention for otel env var tel…
Browse files Browse the repository at this point in the history
…emetry metrics (#2760)

Co-authored-by: Diana Shevchenko <[email protected]>
  • Loading branch information
khanayan123 and dianashevchenko authored Jul 3, 2024
1 parent 5525e1a commit 127fa9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ddtrace/tracer/otel_dd_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ func getDDorOtelConfig(configName string) string {

val := os.Getenv(config.dd)
if otVal := os.Getenv(config.ot); otVal != "" {
ddPrefix := "config.datadog:"
otelPrefix := "config.opentelemetry:"
if val != "" {
log.Warn("Both %v and %v are set, using %v=%v", config.ot, config.dd, config.dd, val)
telemetry.GlobalClient.Count(telemetry.NamespaceTracers, "otel.env.hiding", 1.0, []string{config.dd, config.ot}, true)
telemetry.GlobalClient.Count(telemetry.NamespaceTracers, "otel.env.hiding", 1.0, []string{ddPrefix + config.dd, otelPrefix + config.ot}, true)
} else {
v, err := config.remapper(otVal)
if err != nil {
log.Warn(err.Error())
telemetry.GlobalClient.Count(telemetry.NamespaceTracers, "otel.env.invalid", 1.0, []string{config.dd, config.ot}, true)
telemetry.GlobalClient.Count(telemetry.NamespaceTracers, "otel.env.invalid", 1.0, []string{ddPrefix + config.dd, otelPrefix + config.ot}, true)
}
val = v
}
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/otel_dd_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func TestAssessSource(t *testing.T) {
t.Setenv("OTEL_SERVICE_NAME", "123")
v := getDDorOtelConfig("service")
assert.Equal(t, "abc", v)
telemetryClient.AssertCalled(t, "Count", telemetry.NamespaceTracers, "otel.env.hiding", 1.0, []string{"DD_SERVICE", "OTEL_SERVICE_NAME"}, true)
telemetryClient.AssertCalled(t, "Count", telemetry.NamespaceTracers, "otel.env.hiding", 1.0, []string{"config.datadog:DD_SERVICE", "config.opentelemetry:OTEL_SERVICE_NAME"}, true)
})
t.Run("invalid-ot", func(t *testing.T) {
telemetryClient := new(telemetrytest.MockClient)
defer telemetry.MockGlobalClient(telemetryClient)()
t.Setenv("OTEL_LOG_LEVEL", "nonesense")
v := getDDorOtelConfig("debugMode")
assert.Equal(t, "", v)
telemetryClient.AssertCalled(t, "Count", telemetry.NamespaceTracers, "otel.env.invalid", 1.0, []string{"DD_TRACE_DEBUG", "OTEL_LOG_LEVEL"}, true)
telemetryClient.AssertCalled(t, "Count", telemetry.NamespaceTracers, "otel.env.invalid", 1.0, []string{"config.datadog:DD_TRACE_DEBUG", "config.opentelemetry:OTEL_LOG_LEVEL"}, true)
})
}

0 comments on commit 127fa9a

Please sign in to comment.