From 29912774fefe9fe674f496454674e45af0853ad0 Mon Sep 17 00:00:00 2001 From: Andrew Glaude Date: Fri, 8 Nov 2024 11:19:41 -0500 Subject: [PATCH] Add CI Visibility data to client stats (APMSP-1241) (#2969) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dario Castañé --- ddtrace/tracer/payload.go | 2 +- ddtrace/tracer/stats.go | 6 ++++-- ddtrace/tracer/stats_test.go | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ddtrace/tracer/payload.go b/ddtrace/tracer/payload.go index 8b08e8a713..232387540a 100644 --- a/ddtrace/tracer/payload.go +++ b/ddtrace/tracer/payload.go @@ -81,7 +81,7 @@ func (p *payload) push(t spanList) error { return nil } -// itemCount returns the number of items available in the srteam. +// itemCount returns the number of items available in the stream. func (p *payload) itemCount() int { return int(atomic.LoadUint32(&p.count)) } diff --git a/ddtrace/tracer/stats.go b/ddtrace/tracer/stats.go index 3a85ebece0..da505623aa 100644 --- a/ddtrace/tracer/stats.go +++ b/ddtrace/tracer/stats.go @@ -13,6 +13,8 @@ import ( "github.com/DataDog/datadog-agent/pkg/obfuscate" "github.com/DataDog/datadog-agent/pkg/trace/stats" "gopkg.in/DataDog/dd-trace-go.v1/internal" + "gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/constants" + "gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/utils" "gopkg.in/DataDog/dd-trace-go.v1/internal/log" "github.com/DataDog/datadog-go/v5/statsd" @@ -72,8 +74,8 @@ func newConcentrator(c *config, bucketSize int64) *concentrator { Hostname: c.hostname, Env: env, Version: c.version, - ContainerID: "", //todo: verify these should be empty - GitCommitSha: "", + ContainerID: "", // This intentionally left empty as the Agent will attach the container ID only in certain situations. + GitCommitSha: utils.GetCITags()[constants.GitCommitSHA], ImageTag: "", } spanConcentrator := stats.NewSpanConcentrator(sCfg, time.Now()) diff --git a/ddtrace/tracer/stats_test.go b/ddtrace/tracer/stats_test.go index 63acf92053..6ca000a600 100644 --- a/ddtrace/tracer/stats_test.go +++ b/ddtrace/tracer/stats_test.go @@ -11,6 +11,9 @@ import ( "time" "github.com/stretchr/testify/assert" + + "gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/constants" + "gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/utils" ) func TestAlignTs(t *testing.T) { @@ -95,6 +98,20 @@ func TestConcentrator(t *testing.T) { assert.NotNil(t, names["potato"]) }) + t.Run("ciGitSha", func(t *testing.T) { + utils.AddCITags(constants.GitCommitSHA, "DEADBEEF") + transport := newDummyTransport() + c := newConcentrator(&config{transport: transport, env: "someEnv"}, (10 * time.Second).Nanoseconds()) + assert.Len(t, transport.Stats(), 0) + ss1, ok := c.newTracerStatSpan(&s1, nil) + assert.True(t, ok) + c.Start() + c.In <- ss1 + c.Stop() + actualStats := transport.Stats() + assert.Equal(t, "DEADBEEF", actualStats[0].GitCommitSha) + }) + // stats should be sent if the concentrator is stopped t.Run("stop", func(t *testing.T) { transport := newDummyTransport()