@@ -20,6 +20,8 @@ import (
2020 "github.com/azure/azure-dev/cli/azd/cmd/actions"
2121 "github.com/azure/azure-dev/cli/azd/internal"
2222 "github.com/azure/azure-dev/cli/azd/internal/runcontext"
23+ "github.com/azure/azure-dev/cli/azd/internal/tracing"
24+ "github.com/azure/azure-dev/cli/azd/internal/tracing/fields"
2325 "github.com/azure/azure-dev/cli/azd/pkg/account"
2426 "github.com/azure/azure-dev/cli/azd/pkg/auth"
2527 "github.com/azure/azure-dev/cli/azd/pkg/contracts"
@@ -307,6 +309,7 @@ func (la *loginAction) Run(ctx context.Context) (*actions.ActionResult, error) {
307309 }
308310
309311 if la .flags .onlyCheckStatus {
312+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("check-status" ))
310313 // In check status mode, we always print the final status to stdout.
311314 // We print any non-setup related errors to stderr.
312315 // We always return a zero exit code.
@@ -452,6 +455,11 @@ func runningOnCodespacesBrowser(ctx context.Context, commandRunner exec.CommandR
452455}
453456
454457func (la * loginAction ) login (ctx context.Context ) error {
458+ // Track hashed tenant ID if provided (before resolving from env vars)
459+ if la .flags .tenantID != "" {
460+ tracing .SetUsageAttributes (fields .StringHashed (fields .TenantIdKey , la .flags .tenantID ))
461+ }
462+
455463 if la .flags .federatedTokenProvider == azurePipelinesProvider {
456464 if la .flags .clientID == "" {
457465 log .Printf ("setting client id from environment variable %s" , azurePipelinesClientIDEnvVarName )
@@ -465,6 +473,7 @@ func (la *loginAction) login(ctx context.Context) error {
465473 }
466474
467475 if la .flags .managedIdentity {
476+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("managed-identity" ))
468477 if _ , err := la .authManager .LoginWithManagedIdentity (
469478 ctx , la .flags .clientID ,
470479 ); err != nil {
@@ -494,6 +503,7 @@ func (la *loginAction) login(ctx context.Context) error {
494503
495504 switch {
496505 case la .flags .clientSecret .ptr != nil :
506+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("service-principal-secret" ))
497507 if * la .flags .clientSecret .ptr == "" {
498508 v , err := la .console .Prompt (ctx , input.ConsoleOptions {
499509 Message : "Enter your client secret" ,
@@ -510,6 +520,7 @@ func (la *loginAction) login(ctx context.Context) error {
510520 return fmt .Errorf ("logging in: %w" , err )
511521 }
512522 case la .flags .clientCertificate != "" :
523+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("service-principal-certificate" ))
513524 certFile , err := os .Open (la .flags .clientCertificate )
514525 if err != nil {
515526 return fmt .Errorf ("reading certificate: %w" , err )
@@ -527,12 +538,14 @@ func (la *loginAction) login(ctx context.Context) error {
527538 return fmt .Errorf ("logging in: %w" , err )
528539 }
529540 case la .flags .federatedTokenProvider == "github" :
541+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("federated-github" ))
530542 if _ , err := la .authManager .LoginWithGitHubFederatedTokenProvider (
531543 ctx , la .flags .tenantID , la .flags .clientID ,
532544 ); err != nil {
533545 return fmt .Errorf ("logging in: %w" , err )
534546 }
535547 case la .flags .federatedTokenProvider == azurePipelinesProvider :
548+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("federated-azure-pipelines" ))
536549 serviceConnectionID := os .Getenv (azurePipelinesServiceConnectionIDEnvVarName )
537550
538551 if serviceConnectionID == "" {
@@ -546,6 +559,7 @@ func (la *loginAction) login(ctx context.Context) error {
546559 return fmt .Errorf ("logging in: %w" , err )
547560 }
548561 case la .flags .federatedTokenProvider == "oidc" : // generic oidc provider
562+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("federated-oidc" ))
549563 if _ , err := la .authManager .LoginWithOidcFederatedTokenProvider (
550564 ctx , la .flags .tenantID , la .flags .clientID ,
551565 ); err != nil {
@@ -557,6 +571,7 @@ func (la *loginAction) login(ctx context.Context) error {
557571 }
558572
559573 if la .authManager .UseExternalAuth () {
574+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("external" ))
560575 // Request a token and assume the external auth system will prompt the user to log in.
561576 //
562577 // TODO(ellismg): We may want instead to call some explicit `/login` endpoint on the external auth system instead
@@ -581,6 +596,7 @@ func (la *loginAction) login(ctx context.Context) error {
581596 }
582597
583598 if useDevCode {
599+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("device-code" ))
584600 _ , err = la .authManager .LoginWithDeviceCode (ctx , la .flags .tenantID , la .flags .scopes , claims ,
585601 func (url string ) error {
586602 if ! la .flags .global .NoPrompt {
@@ -598,8 +614,10 @@ func (la *loginAction) login(ctx context.Context) error {
598614 }
599615
600616 if oneauth .Supported && ! la .flags .browser {
617+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("oneauth" ))
601618 err = la .authManager .LoginWithOneAuth (ctx , la .flags .tenantID , la .flags .scopes )
602619 } else {
620+ tracing .SetUsageAttributes (fields .AuthMethodKey .String ("browser" ))
603621 _ , err = la .authManager .LoginInteractive (ctx , la .flags .scopes , claims ,
604622 & auth.LoginInteractiveOptions {
605623 TenantID : la .flags .tenantID ,
0 commit comments