@@ -59,43 +59,74 @@ public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
5959 options . CommitId = Environment . GetEnvironmentVariable ( options . CommitIdEnvVariable ) ?? "" ;
6060 }
6161
62- if ( string . IsNullOrWhiteSpace ( options . EnvironmentId ) )
62+ SetEnvironment ( options , builder ) ;
63+ SetEnvironmentType ( options , builder ) ;
64+ SetUserId ( builder , options ) ;
65+
66+ builder . AddAttributes ( new [ ]
6367 {
64- options . EnvironmentId = Environment . GetEnvironmentVariable ( options . DigmaEnvironmentIdVariable ) ?? "" ;
65- }
66-
67- if ( string . IsNullOrWhiteSpace ( options . Environment ) )
68+ new KeyValuePair < string , object > ( "paths.working_directory" , workingDirectory ) ,
69+ new KeyValuePair < string , object > ( "scm.commit.id" , options . CommitId ) ,
70+ new KeyValuePair < string , object > ( "code.namespace.root" , options . NamespaceRoot ) ,
71+ new KeyValuePair < string , object > ( "host.name" , hostName ) ,
72+ new KeyValuePair < string , object > ( "digma.span_mapping_pattern" , options . SpanMappingPattern ) ,
73+ new KeyValuePair < string , object > ( "digma.span_mapping_replacement" , options . SpanMappingReplacement ) ,
74+ } ) ;
75+ return builder ;
76+ }
77+
78+ private static void SetUserId ( ResourceBuilder builder , DigmaConfigurationOptions options )
79+ {
80+ if ( string . IsNullOrWhiteSpace ( options . UserId ) )
6881 {
69- options . Environment = Environment . GetEnvironmentVariable ( options . DigmaEnvironmentEnvVariable ) ?? "" ;
82+ options . UserId = Environment . GetEnvironmentVariable ( options . DigmaUserIdVariable ) ?? null ;
83+ if ( ! string . IsNullOrWhiteSpace ( options . UserId ) )
84+ builder . AddAttributes ( new [ ] { new KeyValuePair < string , object > ( "digma.user.id" , options . UserId ) } ) ;
7085 }
86+ }
7187
72- if ( string . IsNullOrWhiteSpace ( options . Environment ) )
88+ private static void SetEnvironmentType ( DigmaConfigurationOptions options , ResourceBuilder builder )
89+ {
90+ if ( options . EnvironmentType == null )
7391 {
74- options . Environment = Environment . GetEnvironmentVariable ( options . EnvironmentEnvVariable ) ?? "" ;
92+ string ? environmentTypeStr = Environment . GetEnvironmentVariable ( options . DigmaEnvironmentTypeVariable ) ;
93+ if ( ! string . IsNullOrWhiteSpace ( environmentTypeStr ) )
94+ {
95+ options . EnvironmentType = Enum . Parse < EnvironmentType > ( environmentTypeStr , true ) ;
96+ }
7597 }
76-
77- if ( string . IsNullOrWhiteSpace ( options . Environment ) )
98+ if ( options . EnvironmentType != null )
7899 {
79- options . Environment = hostName + "[local]" ;
100+ builder . AddAttributes ( new [ ] { new KeyValuePair < string , object > ( "digma.environment.type" , options . EnvironmentType ) } ) ;
101+ }
102+ }
103+
104+ private static void SetEnvironment ( DigmaConfigurationOptions options , ResourceBuilder builder )
105+ {
106+ if ( string . IsNullOrWhiteSpace ( options . EnvironmentId ) )
107+ {
108+ options . EnvironmentId = Environment . GetEnvironmentVariable ( options . DigmaEnvironmentIdVariable ) ?? null ;
109+ }
110+ if ( ! string . IsNullOrWhiteSpace ( options . EnvironmentId ) )
111+ {
112+ builder . AddAttributes ( new [ ]
113+ {
114+ new KeyValuePair < string , object > ( "digma.environment.id" , options . EnvironmentId ) ,
115+ } ) ;
116+ return ;
80117 }
81118
82- if ( string . IsNullOrWhiteSpace ( options . UserId ) )
119+
120+ if ( string . IsNullOrWhiteSpace ( options . Environment ) )
83121 {
84- options . UserId = Environment . GetEnvironmentVariable ( options . DigmaUserIdVariable ) ?? "" ;
122+ options . Environment = Environment . GetEnvironmentVariable ( options . DigmaEnvironmentEnvVariable ) ?? null ;
123+ if ( string . IsNullOrWhiteSpace ( options . Environment ) )
124+ options . Environment = Environment . GetEnvironmentVariable ( options . EnvironmentEnvVariable ) ?? null ;
85125 }
86-
87- builder . AddAttributes ( new [ ]
126+
127+ if ( ! string . IsNullOrWhiteSpace ( options . Environment ) )
88128 {
89- new KeyValuePair < string , object > ( "digma.user.id" , options . UserId ) ,
90- new KeyValuePair < string , object > ( "digma.environment.id" , options . EnvironmentId ) ,
91- new KeyValuePair < string , object > ( "digma.environment" , options . Environment ) ,
92- new KeyValuePair < string , object > ( "paths.working_directory" , workingDirectory ) ,
93- new KeyValuePair < string , object > ( "scm.commit.id" , options . CommitId ) ,
94- new KeyValuePair < string , object > ( "code.namespace.root" , options . NamespaceRoot ) ,
95- new KeyValuePair < string , object > ( "host.name" , hostName ) ,
96- new KeyValuePair < string , object > ( "digma.span_mapping_pattern" , options . SpanMappingPattern ) ,
97- new KeyValuePair < string , object > ( "digma.span_mapping_replacement" , options . SpanMappingReplacement ) ,
98- } ) ;
99- return builder ;
129+ builder . AddAttributes ( new [ ] { new KeyValuePair < string , object > ( "digma.environment" , options . Environment ) } ) ;
130+ }
100131 }
101132}
0 commit comments