Skip to content

Commit

Permalink
Add CI Visibility data to client stats (APMSP-1241) (#2969)
Browse files Browse the repository at this point in the history
Co-authored-by: Dario Castañé <[email protected]>
  • Loading branch information
ajgajg1134 and darccio authored Nov 8, 2024
1 parent 2320b43 commit 2991277
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ddtrace/tracer/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 4 additions & 2 deletions ddtrace/tracer/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
17 changes: 17 additions & 0 deletions ddtrace/tracer/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2991277

Please sign in to comment.