Skip to content

Commit

Permalink
telemetry: submit orchestrion_usage counter metric
Browse files Browse the repository at this point in the history
To make it easier to get data about orchestrion usage, start submitting
a counter metric in telemetry for applications built with orchestrion.
  • Loading branch information
RomainMuller committed Dec 6, 2024
1 parent 9980c24 commit aa51e23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ddtrace/tracer/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package tracer

import (
"fmt"
"slices"
"strings"
"testing"

"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
)
Expand Down Expand Up @@ -108,9 +110,21 @@ func startTelemetry(c *config) {
Value: fmt.Sprintf("rate:%f_maxPerSecond:%f", rule.Rate, rule.MaxPerSecond)})
}
if c.orchestrionCfg.Enabled {
tags := make([]string, 0, len(c.orchestrionCfg.Metadata))
for k, v := range c.orchestrionCfg.Metadata {
telemetryConfigs = append(telemetryConfigs, telemetry.Configuration{Name: "orchestrion_" + k, Value: v})
tags = append(tags, k+":"+v)
}
if testing.Testing() {
// In tests, ensure tags are consistently ordered...
slices.Sort(tags)
}
telemetry.GlobalClient.Count(
telemetry.NamespaceTracers,
"orchestrion_usage", 1,
tags,
false, // Go-specific
)
}
telemetryConfigs = append(telemetryConfigs, additionalConfigs...)
telemetry.GlobalClient.ProductChange(telemetry.NamespaceTracers, true, telemetryConfigs)
Expand Down
8 changes: 8 additions & 0 deletions ddtrace/tracer/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,19 @@ func TestTelemetryEnabled(t *testing.T) {
telemetryClient := new(telemetrytest.MockClient)
defer telemetry.MockGlobalClient(telemetryClient)()

telemetryClient.On("Count",
telemetry.NamespaceTracers,
"orchestrion_usage", 1.0,
[]string{"k1:v1", "k2:v2"},
false,
).Return()

Start(WithOrchestrion(map[string]string{"k1": "v1", "k2": "v2"}))
defer Stop()

telemetry.Check(t, telemetryClient.Configuration, "orchestrion_enabled", true)
telemetry.Check(t, telemetryClient.Configuration, "orchestrion_k1", "v1")
telemetry.Check(t, telemetryClient.Configuration, "orchestrion_k2", "v2")
telemetryClient.AssertExpectations(t)
})
}
1 change: 0 additions & 1 deletion internal/telemetry/telemetrytest/telemetrytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (c *MockClient) Record(ns telemetry.Namespace, _ telemetry.MetricKind, name

// Count counts the value for the given metric
func (c *MockClient) Count(ns telemetry.Namespace, name string, val float64, tags []string, common bool) {
c.On("Count", ns, name, val, tags, common).Return()
_ = c.Called(ns, name, val, tags, common)
}

Expand Down

0 comments on commit aa51e23

Please sign in to comment.