Skip to content

Commit

Permalink
Add AzureContainerAppTags to trace agent config struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
purple4reina committed Nov 4, 2024
1 parent e39c815 commit 43e6f8b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
28 changes: 24 additions & 4 deletions cmd/serverless-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ package main
import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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()
Expand Down
11 changes: 7 additions & 4 deletions pkg/serverless/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ func (l *LoadConfig) Load() (*config.AgentConfig, error) {
return comptracecfg.LoadConfigFile(l.Path, c, l.Tagger)
}

// StartServerlessTraceAgentArgs are the arguments for the StartServerlessTraceAgent method
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
Expand All @@ -115,6 +117,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,
Expand Down
18 changes: 2 additions & 16 deletions pkg/trace/api/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/trace/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 43e6f8b

Please sign in to comment.