diff --git a/cmd/serverless-init/main.go b/cmd/serverless-init/main.go index 501efd2f6a0732..8cb5d86665e5e2 100644 --- a/cmd/serverless-init/main.go +++ b/cmd/serverless-init/main.go @@ -10,8 +10,10 @@ package main import ( "context" "errors" + "fmt" "os" "os/exec" + "strings" "sync" "time" @@ -150,13 +152,31 @@ func setup(_ mode.Conf, tagger tagger.Component) (cloudservice.CloudService, *se go flushMetricsAgent(metricAgent) return cloudService, agentLogConfig, traceAgent, metricAgent, logsAgent } + +var azureContainerAppTags = []string{ + "subscription_id", + "resource_group", + "resource_id", + "replicate_name", + "aca.subscription.id", + "aca.resource.group", + "aca.resource.id", + "aca.replica.name", +} + func setupTraceAgent(tags map[string]string, tagger tagger.Component) trace.ServerlessTraceAgent { + var azureTags strings.Builder + for _, azureContainerAppTag := range azureContainerAppTags { + if value, ok := tags[azureContainerAppTag]; ok { + azureTags.WriteString(fmt.Sprintf(",%s:%s", azureContainerAppTag, value)) + } + } traceAgent := trace.StartServerlessTraceAgent(trace.StartServerlessTraceAgentArgs{ - Enabled: pkgconfigsetup.Datadog().GetBool("apm_config.enabled"), - LoadConfig: &trace.LoadConfig{Path: datadogConfigPath, Tagger: tagger}, - ColdStartSpanId: random.Random.Uint64(), + Enabled: pkgconfigsetup.Datadog().GetBool("apm_config.enabled"), + LoadConfig: &trace.LoadConfig{Path: datadogConfigPath, Tagger: tagger}, + ColdStartSpanId: random.Random.Uint64(), + AzureContainerAppTags: azureTags.String(), }) - traceAgent.SetTags(tags) go func() { for range time.Tick(3 * time.Second) { traceAgent.Flush() diff --git a/pkg/serverless/trace/trace.go b/pkg/serverless/trace/trace.go index ea0a5716751d23..e8a3a00137842e 100644 --- a/pkg/serverless/trace/trace.go +++ b/pkg/serverless/trace/trace.go @@ -92,10 +92,11 @@ func (l *LoadConfig) Load() (*config.AgentConfig, error) { } type StartServerlessTraceAgentArgs struct { - Enabled bool - LoadConfig Load - LambdaSpanChan chan<- *pb.Span - ColdStartSpanId uint64 + Enabled bool + LoadConfig Load + LambdaSpanChan chan<- *pb.Span + ColdStartSpanId uint64 + AzureContainerAppTags string } // Start starts the agent @@ -115,6 +116,7 @@ func StartServerlessTraceAgent(args StartServerlessTraceAgentArgs) ServerlessTra context, cancel := context.WithCancel(context.Background()) tc.Hostname = "" tc.SynchronousFlushing = true + tc.AzureContainerAppTags = args.AzureContainerAppTags ta := agent.NewAgent(context, tc, telemetry.NewNoopCollector(), &statsd.NoOpClient{}, zstd.NewComponent()) ta.SpanModifier = &spanModifier{ coldStartSpanId: args.ColdStartSpanId, diff --git a/pkg/trace/api/profiles.go b/pkg/trace/api/profiles.go index a3f2ecf87a0cc2..9b43efc94de747 100644 --- a/pkg/trace/api/profiles.go +++ b/pkg/trace/api/profiles.go @@ -30,17 +30,6 @@ const ( profilingV1EndpointSuffix = "v1/input" ) -var azureContainerAppTags = []string{ - "subscription_id", - "resource_group", - "resource_id", - "replicate_name", - "aca.subscription.id", - "aca.resource.group", - "aca.resource.id", - "aca.replica.name", -} - // profilingEndpoints returns the profiling intake urls and their corresponding // api keys based on agent configuration. The main endpoint is always returned as // the first element in the slice. @@ -97,11 +86,8 @@ func (r *HTTPReceiver) profileProxyHandler() http.Handler { tags.WriteString(fmt.Sprintf("functionname:%s", strings.ToLower(r.conf.LambdaFunctionName))) tags.WriteString("_dd.origin:lambda") } - - for _, azureContainerAppTag := range azureContainerAppTags { - if value, ok := r.conf.GlobalTags[azureContainerAppTag]; ok { - tags.WriteString(fmt.Sprintf(",%s:%s", azureContainerAppTag, value)) - } + if r.conf.AzureContainerAppTags != "" { + tags.WriteString(r.conf.AzureContainerAppTags) } return newProfileProxy(r.conf, targets, keys, tags.String(), r.statsd) diff --git a/pkg/trace/config/config.go b/pkg/trace/config/config.go index 0426863d60be71..60e2e456c0a6c3 100644 --- a/pkg/trace/config/config.go +++ b/pkg/trace/config/config.go @@ -450,6 +450,10 @@ type AgentConfig struct { // Lambda function name LambdaFunctionName string + + // Azure container apps tags, in the form of a comma-separated list of + // key-value pairs, starting with a comma + AzureContainerAppTags string } // RemoteClient client is used to APM Sampling Updates from a remote source.