diff --git a/cmd/serverless-init/cloudservice/containerapp.go b/cmd/serverless-init/cloudservice/containerapp.go index dba7e62282f6b..92e0433ce1698 100644 --- a/cmd/serverless-init/cloudservice/containerapp.go +++ b/cmd/serverless-init/cloudservice/containerapp.go @@ -48,24 +48,29 @@ func (c *ContainerApp) GetTags() map[string]string { replica := os.Getenv(ContainerAppReplicaName) tags := map[string]string{ - "app_name": appName, - "region": region, - "revision": revision, - "replica_name": replica, - "origin": c.GetOrigin(), - "_dd.origin": c.GetOrigin(), + "app_name": appName, + "region": region, + "revision": revision, + "replica_name": replica, + "aca.replica.name": replica, + "origin": c.GetOrigin(), + "_dd.origin": c.GetOrigin(), } if c.SubscriptionId != "" { tags["subscription_id"] = c.SubscriptionId + tags["aca.subscription.id"] = c.SubscriptionId } if c.ResourceGroup != "" { tags["resource_group"] = c.ResourceGroup + tags["aca.resource.group"] = c.ResourceGroup } if c.SubscriptionId != "" && c.ResourceGroup != "" { - tags["resource_id"] = fmt.Sprintf("/subscriptions/%v/resourcegroups/%v/providers/microsoft.app/containerapps/%v", c.SubscriptionId, c.ResourceGroup, strings.ToLower(appName)) + resourceID := fmt.Sprintf("/subscriptions/%v/resourcegroups/%v/providers/microsoft.app/containerapps/%v", c.SubscriptionId, c.ResourceGroup, strings.ToLower(appName)) + tags["resource_id"] = resourceID + tags["aca.resource.id"] = resourceID } return tags diff --git a/cmd/serverless-init/cloudservice/containerapp_test.go b/cmd/serverless-init/cloudservice/containerapp_test.go index 7da872f0c4faa..adb1341af57fb 100644 --- a/cmd/serverless-init/cloudservice/containerapp_test.go +++ b/cmd/serverless-init/cloudservice/containerapp_test.go @@ -27,12 +27,13 @@ func TestGetContainerAppTags(t *testing.T) { tags := service.GetTags() assert.Equal(t, map[string]string{ - "app_name": "test_app_name", - "origin": "containerapp", - "region": "eastus", - "revision": "test_revision", - "replica_name": "test--6nyz8z7-b845f7667-m7hlv", - "_dd.origin": "containerapp", + "app_name": "test_app_name", + "origin": "containerapp", + "region": "eastus", + "revision": "test_revision", + "replica_name": "test--6nyz8z7-b845f7667-m7hlv", + "aca.replica.name": "test--6nyz8z7-b845f7667-m7hlv", + "_dd.origin": "containerapp", }, tags) } @@ -53,15 +54,19 @@ func TestGetContainerAppTagsWithOptionalEnvVars(t *testing.T) { tags := service.GetTags() assert.Equal(t, map[string]string{ - "app_name": "test_app_name", - "origin": "containerapp", - "region": "eastus", - "revision": "test_revision", - "replica_name": "test--6nyz8z7-b845f7667-m7hlv", - "_dd.origin": "containerapp", - "subscription_id": "test_subscription_id", - "resource_id": "/subscriptions/test_subscription_id/resourcegroups/test_resource_group/providers/microsoft.app/containerapps/test_app_name", - "resource_group": "test_resource_group", + "app_name": "test_app_name", + "origin": "containerapp", + "region": "eastus", + "revision": "test_revision", + "replica_name": "test--6nyz8z7-b845f7667-m7hlv", + "aca.replica.name": "test--6nyz8z7-b845f7667-m7hlv", + "_dd.origin": "containerapp", + "subscription_id": "test_subscription_id", + "aca.subscription.id": "test_subscription_id", + "resource_id": "/subscriptions/test_subscription_id/resourcegroups/test_resource_group/providers/microsoft.app/containerapps/test_app_name", + "aca.resource.id": "/subscriptions/test_subscription_id/resourcegroups/test_resource_group/providers/microsoft.app/containerapps/test_app_name", + "resource_group": "test_resource_group", + "aca.resource.group": "test_resource_group", }, tags) assert.Nil(t, err) diff --git a/pkg/trace/api/profiles.go b/pkg/trace/api/profiles.go index dc1f2fe234ca8..a3f2ecf87a0cc 100644 --- a/pkg/trace/api/profiles.go +++ b/pkg/trace/api/profiles.go @@ -30,6 +30,17 @@ 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. @@ -87,15 +98,10 @@ func (r *HTTPReceiver) profileProxyHandler() http.Handler { tags.WriteString("_dd.origin:lambda") } - // Azure Container App metadata - if subscriptionID, ok := r.conf.GlobalTags["subscription_id"]; ok { - tags.WriteString(fmt.Sprintf(",subscription_id:%s", subscriptionID)) - } - if resourceGroup, ok := r.conf.GlobalTags["resource_group"]; ok { - tags.WriteString(fmt.Sprintf(",resource_group:%s", resourceGroup)) - } - if resourceID, ok := r.conf.GlobalTags["resource_id"]; ok { - tags.WriteString(fmt.Sprintf(",resource_id:%s", resourceID)) + for _, azureContainerAppTag := range azureContainerAppTags { + if value, ok := r.conf.GlobalTags[azureContainerAppTag]; ok { + tags.WriteString(fmt.Sprintf(",%s:%s", azureContainerAppTag, value)) + } } return newProfileProxy(r.conf, targets, keys, tags.String(), r.statsd) diff --git a/pkg/trace/api/profiles_test.go b/pkg/trace/api/profiles_test.go index a5f74b62ffd84..b11b162deaf9f 100644 --- a/pkg/trace/api/profiles_test.go +++ b/pkg/trace/api/profiles_test.go @@ -314,7 +314,7 @@ func TestProfileProxyHandler(t *testing.T) { kv := strings.Split(tag, ":") m[kv[0]] = kv[1] } - for _, tag := range []string{"subscription_id", "resource_group", "resource_id"} { + for _, tag := range []string{"subscription_id", "resource_group", "resource_id", "aca.subscription.id", "aca.resource.group", "aca.resource.id", "aca.replica.name"} { if _, ok := m[tag]; !ok { t.Fatalf("invalid X-Datadog-Additional-Tags header, should contain '%s': %q", tag, v) } @@ -324,9 +324,13 @@ func TestProfileProxyHandler(t *testing.T) { conf := newTestReceiverConfig() conf.ProfilingProxy = config.ProfilingProxyConfig{DDURL: srv.URL} conf.GlobalTags = map[string]string{ - "subscription_id": "123", - "resource_group": "test-rg", - "resource_id": "456", + "subscription_id": "123", + "resource_group": "test-rg", + "resource_id": "456", + "aca.subscription.id": "123", + "aca.resource.group": "test-rg", + "aca.resource.id": "456", + "aca.replica.name": "test-replica", } req, err := http.NewRequest("POST", "/some/path", nil) if err != nil {