Skip to content

Commit e591824

Browse files
authored
feat: add a new user agent: microsoft_foundry_skill (#9167)
1 parent 0b83ac1 commit e591824

5 files changed

Lines changed: 62 additions & 5 deletions

File tree

cli/azd/internal/tracing/fields/fields.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ const (
321321
// Environment modifiers. These are not environments themselves, but rather modifiers to the environment
322322
// that signal specific types of usages.
323323

324-
EnvModifierAzureSpace = "Azure App Spaces Portal"
324+
EnvModifierAzureSpace = "Azure App Spaces Portal"
325+
EnvModifierMicrosoftFoundrySkill = "Microsoft Foundry Skill"
325326
)
326327

327328
// All possible enumerations of AccountTypeKey

cli/azd/internal/tracing/resource/exec_environment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func execEnvModifiers() []string {
107107
if strings.Contains(userAgent, "azure_app_space_portal") {
108108
modifiers = append(modifiers, fields.EnvModifierAzureSpace)
109109
}
110+
if strings.Contains(userAgent, "microsoft_foundry_skill") {
111+
modifiers = append(modifiers, fields.EnvModifierMicrosoftFoundrySkill)
112+
}
110113

111114
return modifiers
112115
}

cli/azd/internal/tracing/resource/resource_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package resource
55

66
import (
77
"os"
8+
"slices"
89
"testing"
910

1011
"github.com/azure/azure-dev/cli/azd/internal/tracing/fields"
@@ -256,6 +257,48 @@ func TestExecEnvForHosts_no_host(t *testing.T) {
256257
}
257258
}
258259

260+
func TestExecEnvModifiers(t *testing.T) {
261+
tests := []struct {
262+
name string
263+
userAgent string
264+
want []string
265+
}{
266+
{
267+
name: "no modifiers",
268+
userAgent: "custom-user-agent",
269+
want: []string{},
270+
},
271+
{
272+
name: "Azure App Spaces portal",
273+
userAgent: "azure_app_space_portal:v1.0.0",
274+
want: []string{fields.EnvModifierAzureSpace},
275+
},
276+
{
277+
name: "Microsoft Foundry skill",
278+
userAgent: "microsoft_foundry_skill",
279+
want: []string{fields.EnvModifierMicrosoftFoundrySkill},
280+
},
281+
{
282+
name: "multiple modifiers",
283+
userAgent: "azure_app_space_portal microsoft_foundry_skill",
284+
want: []string{
285+
fields.EnvModifierAzureSpace,
286+
fields.EnvModifierMicrosoftFoundrySkill,
287+
},
288+
},
289+
}
290+
291+
for _, tt := range tests {
292+
t.Run(tt.name, func(t *testing.T) {
293+
t.Setenv("AZURE_DEV_USER_AGENT", tt.userAgent)
294+
295+
if got := execEnvModifiers(); !slices.Equal(got, tt.want) {
296+
t.Fatalf("execEnvModifiers() = %q, want %q", got, tt.want)
297+
}
298+
})
299+
}
300+
}
301+
259302
func TestNew_returns_non_nil_resource(t *testing.T) {
260303
clearCIEnvVars(t)
261304
t.Setenv("AZD_IN_CLOUDSHELL", "")

cli/azd/test/functional/telemetry_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ func Test_CLI_Telemetry_NestedCommands(t *testing.T) {
237237
// Always set telemetry opt-inn setting to avoid influence from user settings
238238
cli.Env = append(os.Environ(), "AZURE_DEV_COLLECT_TELEMETRY=yes")
239239

240-
// set environment modifier
241-
cli.Env = append(cli.Env, "AZURE_DEV_USER_AGENT=azure_app_space_portal:v1.0.0")
240+
// set environment modifiers
241+
cli.Env = append(
242+
cli.Env,
243+
"AZURE_DEV_USER_AGENT=azure_app_space_portal:v1.0.0 microsoft_foundry_skill",
244+
)
242245

243246
// set a fixed traceparent to verify trace ID propagation for commands and nested commands
244247
traceId := "246cfb7e1b1c5978f4b0fc2e41e98db6"
@@ -418,9 +421,16 @@ func verifyResource(
418421
}
419422

420423
for _, env := range cmdEnv {
421-
if strings.HasPrefix(env, "AZURE_DEV_USER_AGENT=") && strings.Contains(env, "azure_app_space_portal") {
424+
if !strings.HasPrefix(env, "AZURE_DEV_USER_AGENT=") {
425+
continue
426+
}
427+
428+
if strings.Contains(env, "azure_app_space_portal") {
422429
require.Contains(t, m[fields.ExecutionEnvironmentKey.Key], ";"+fields.EnvModifierAzureSpace)
423430
}
431+
if strings.Contains(env, "microsoft_foundry_skill") {
432+
require.Contains(t, m[fields.ExecutionEnvironmentKey.Key], ";"+fields.EnvModifierMicrosoftFoundrySkill)
433+
}
424434
}
425435

426436
require.Contains(t, m, fields.OSTypeKey.Key)

docs/reference/telemetry-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ The `execution.environment` field identifies where azd is running. Format: `<env
587587
| `GitHub Codespaces` | GitHub Codespaces |
588588
| Other CI systems | `AppVeyor`, `Bamboo`, `BitBucket Pipelines`, `Travis CI`, `Circle CI`, `GitLab CI`, `Jenkins`, `AWS CodeBuild`, `Google Cloud Build`, `TeamCity`, `JetBrains Space` |
589589

590-
**Modifier:** `Azure App Spaces Portal` may be appended as a modifier (`;` separated).
590+
**Modifiers:** `Azure App Spaces Portal` and `Microsoft Foundry Skill` may be appended as modifiers (`;` separated).
591591

592592
## Data Nuances & Gotchas
593593

0 commit comments

Comments
 (0)