Skip to content

Commit

Permalink
propagate the tagger component when building the OTLP pipeline for se…
Browse files Browse the repository at this point in the history
…rverless-init
  • Loading branch information
GustavoCaso committed Nov 28, 2024
1 parent 7bf22e7 commit 832aac9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cmd/serverless-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func setup(_ mode.Conf, tagger tagger.Component) (cloudservice.CloudService, *se
metricAgent := setupMetricAgent(tags, tagger)
metric.AddColdStartMetric(prefix, metricAgent.GetExtraTags(), time.Now(), metricAgent.Demux)

setupOtlpAgent(metricAgent)
setupOtlpAgent(metricAgent, tagger)

go flushMetricsAgent(metricAgent)
return cloudService, agentLogConfig, traceAgent, metricAgent, logsAgent
Expand Down Expand Up @@ -200,12 +200,12 @@ func setupMetricAgent(tags map[string]string, tagger tagger.Component) *metrics.
return metricAgent
}

func setupOtlpAgent(metricAgent *metrics.ServerlessMetricAgent) {
func setupOtlpAgent(metricAgent *metrics.ServerlessMetricAgent, tagger tagger.Component) {
if !otlp.IsEnabled() {
log.Debugf("otlp endpoint disabled")
return
}
otlpAgent := otlp.NewServerlessOTLPAgent(metricAgent.Demux.Serializer())
otlpAgent := otlp.NewServerlessOTLPAgent(metricAgent.Demux.Serializer(), tagger)
otlpAgent.Start()
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func runAgent(tagger tagger.Component) {
wg.Add(3)

go startTraceAgent(&wg, lambdaSpanChan, coldStartSpanId, serverlessDaemon, tagger, rcService)
go startOtlpAgent(&wg, metricAgent, serverlessDaemon)
go startOtlpAgent(&wg, metricAgent, serverlessDaemon, tagger)
go startTelemetryCollection(&wg, serverlessID, logChannel, serverlessDaemon, tagger)

// start appsec
Expand Down Expand Up @@ -330,13 +330,13 @@ func startTelemetryCollection(wg *sync.WaitGroup, serverlessID registration.ID,
}
}

func startOtlpAgent(wg *sync.WaitGroup, metricAgent *metrics.ServerlessMetricAgent, serverlessDaemon *daemon.Daemon) {
func startOtlpAgent(wg *sync.WaitGroup, metricAgent *metrics.ServerlessMetricAgent, serverlessDaemon *daemon.Daemon, tagger tagger.Component) {
defer wg.Done()
if !otlp.IsEnabled() {
log.Debug("otlp endpoint disabled")
return
}
otlpAgent := otlp.NewServerlessOTLPAgent(metricAgent.Demux.Serializer())
otlpAgent := otlp.NewServerlessOTLPAgent(metricAgent.Demux.Serializer(), tagger)
otlpAgent.Start()
serverlessDaemon.SetOTLPAgent(otlpAgent)

Expand Down
5 changes: 3 additions & 2 deletions pkg/serverless/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"go.opentelemetry.io/collector/otelcol"

tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def"
coreOtlp "github.com/DataDog/datadog-agent/comp/otelcol/otlp"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/serializer"
Expand All @@ -28,8 +29,8 @@ type ServerlessOTLPAgent struct {

// NewServerlessOTLPAgent creates a new ServerlessOTLPAgent with the correct
// otel pipeline.
func NewServerlessOTLPAgent(serializer serializer.MetricSerializer) *ServerlessOTLPAgent {
pipeline, err := coreOtlp.NewPipelineFromAgentConfig(pkgconfigsetup.Datadog(), serializer, nil, nil)
func NewServerlessOTLPAgent(serializer serializer.MetricSerializer, tagger tagger.Component) *ServerlessOTLPAgent {
pipeline, err := coreOtlp.NewPipelineFromAgentConfig(pkgconfigsetup.Datadog(), serializer, nil, tagger)
if err != nil {
log.Error("Error creating new otlp pipeline:", err)
return nil
Expand Down
7 changes: 5 additions & 2 deletions pkg/serverless/otlp/otlp_no_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
//nolint:revive // TODO(SERV) Fix revive linter
package otlp

import "github.com/DataDog/datadog-agent/pkg/serializer"
import (
tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def"
"github.com/DataDog/datadog-agent/pkg/serializer"
)

//nolint:revive // TODO(SERV) Fix revive linter
type ServerlessOTLPAgent struct{}

//nolint:revive // TODO(SERV) Fix revive linter
func NewServerlessOTLPAgent(serializer.MetricSerializer) *ServerlessOTLPAgent {
func NewServerlessOTLPAgent(serializer.MetricSerializer, tagger.Component) *ServerlessOTLPAgent {
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/serverless/otlp/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
sdktrace "go.opentelemetry.io/otel/sdk/trace"

"github.com/stretchr/testify/assert"

taggernoop "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
"github.com/DataDog/datadog-agent/pkg/serverless/metrics"
"github.com/DataDog/datadog-agent/pkg/serverless/trace"
"github.com/DataDog/datadog-agent/pkg/trace/testutil"
"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -84,7 +86,7 @@ func TestServerlessOTLPAgentReceivesTraces(t *testing.T) {
assert.True(metricAgent.IsReady())

// setup otlp agent
otlpAgent := NewServerlessOTLPAgent(metricAgent.Demux.Serializer())
otlpAgent := NewServerlessOTLPAgent(metricAgent.Demux.Serializer(), taggernoop.NewComponent())
otlpAgent.Start()
defer otlpAgent.Stop()
assert.NotNil(otlpAgent.pipeline)
Expand Down

0 comments on commit 832aac9

Please sign in to comment.