@@ -88,7 +88,7 @@ private void CallEnrichment(KustoUtils.TraceRecord record)
8888 var activity = this . GetContext ( record ) ? . Activity ;
8989 if ( activity is not null && activity . IsAllDataRequested )
9090 {
91- KustoInstrumentation . Options . Enrich ? . Invoke ( activity , record ) ;
91+ KustoInstrumentation . TraceOptions . Enrich ? . Invoke ( activity , record ) ;
9292 }
9393 }
9494 catch ( Exception ex )
@@ -110,7 +110,7 @@ private void HandleException(KustoUtils.TraceRecord record)
110110 if ( ! result . ErrorType . IsEmpty )
111111 {
112112 activity ? . SetTag ( SemanticConventions . AttributeErrorType , result . ErrorType . ToString ( ) ) ;
113- context . Value . Tags . Add ( SemanticConventions . AttributeErrorType , result . ErrorType . ToString ( ) ) ;
113+ context . Value . MeterTags . Add ( SemanticConventions . AttributeErrorType , result . ErrorType . ToString ( ) ) ;
114114 }
115115
116116 var description = result . ErrorMessage . IsEmpty ? null : result . ErrorMessage . ToString ( ) ;
@@ -125,52 +125,74 @@ private void HandleHttpRequestStart(KustoUtils.TraceRecord record)
125125 var operationName = record . Activity . ActivityType ;
126126
127127 var activity = KustoActivitySourceHelper . ActivitySource . StartActivity ( operationName , ActivityKind . Client ) ;
128- var tagList = default ( TagList ) ;
128+ var meterTags = default ( TagList ) ;
129129
130130 if ( ShouldComputeTags ( activity ) )
131131 {
132132 activity ? . DisplayName = operationName ;
133133 activity ? . AddTag ( KustoActivitySourceHelper . ClientRequestIdTagKey , record . Activity . ClientRequestId . ToString ( ) ) ;
134134
135- tagList . Add ( SemanticConventions . AttributeDbSystemName , KustoActivitySourceHelper . DbSystem ) ;
136- tagList . Add ( SemanticConventions . AttributeDbOperationName , operationName ) ;
135+ activity ? . AddTag ( SemanticConventions . AttributeDbSystemName , KustoActivitySourceHelper . DbSystem ) ;
136+ activity ? . AddTag ( SemanticConventions . AttributeDbOperationName , operationName ) ;
137+ meterTags . Add ( SemanticConventions . AttributeDbSystemName , KustoActivitySourceHelper . DbSystem ) ;
138+ meterTags . Add ( SemanticConventions . AttributeDbOperationName , operationName ) ;
137139
138140 var result = TraceRecordParser . ParseRequestStart ( record . Message . AsSpan ( ) ) ;
139141
140142 if ( ! string . IsNullOrEmpty ( result . ServerAddress ) )
141143 {
142- tagList . Add ( SemanticConventions . AttributeServerAddress , result . ServerAddress ) ;
144+ activity ? . AddTag ( SemanticConventions . AttributeServerAddress , result . ServerAddress ) ;
145+ meterTags . Add ( SemanticConventions . AttributeServerAddress , result . ServerAddress ) ;
143146 }
144147
145148 if ( result . ServerPort is not null )
146149 {
147- tagList . Add ( SemanticConventions . AttributeServerPort , result . ServerPort . Value ) ;
150+ activity ? . AddTag ( SemanticConventions . AttributeServerPort , result . ServerPort . Value ) ;
151+ meterTags . Add ( SemanticConventions . AttributeServerPort , result . ServerPort . Value ) ;
148152 }
149153
150154 if ( ! result . Database . IsEmpty )
151155 {
152- tagList . Add ( SemanticConventions . AttributeDbNamespace , result . Database . ToString ( ) ) ;
156+ activity ? . AddTag ( SemanticConventions . AttributeDbNamespace , result . Database . ToString ( ) ) ;
157+ meterTags . Add ( SemanticConventions . AttributeDbNamespace , result . Database . ToString ( ) ) ;
153158 }
154159
155160 if ( ! result . QueryText . IsEmpty )
156161 {
157- var info = KustoProcessor . Process ( shouldSummarize : KustoInstrumentation . Options . RecordQuerySummary , shouldSanitize : KustoInstrumentation . Options . RecordQueryText , result . QueryText . ToString ( ) ) ;
162+ var shouldSummarize = KustoInstrumentation . TraceOptions . RecordQuerySummary || KustoInstrumentation . MeterOptions . RecordQuerySummary ;
163+ var shouldSanitize = KustoInstrumentation . TraceOptions . RecordQueryText || KustoInstrumentation . MeterOptions . RecordQueryText ;
164+ var info = KustoProcessor . Process ( shouldSummarize , shouldSanitize , result . QueryText . ToString ( ) ) ;
158165
159- if ( KustoInstrumentation . Options . RecordQueryText )
166+ if ( ! string . IsNullOrEmpty ( info . Sanitized ) )
160167 {
161- tagList . Add ( SemanticConventions . AttributeDbQueryText , info . Sanitized ) ;
168+ if ( KustoInstrumentation . TraceOptions . RecordQueryText )
169+ {
170+ activity ? . AddTag ( SemanticConventions . AttributeDbQueryText , info . Sanitized ) ;
171+ }
172+
173+ if ( KustoInstrumentation . MeterOptions . RecordQueryText )
174+ {
175+ meterTags . Add ( SemanticConventions . AttributeDbQueryText , info . Sanitized ) ;
176+ }
162177 }
163178
164- // Set query summary and use it as display name per spec
165179 if ( ! string . IsNullOrEmpty ( info . Summarized ) )
166180 {
167- tagList . Add ( SemanticConventions . AttributeDbQuerySummary , info . Summarized ) ;
168- activity ? . DisplayName = info. Summarized ! ;
181+ if ( KustoInstrumentation . TraceOptions . RecordQuerySummary )
182+ {
183+ activity ? . AddTag ( SemanticConventions . AttributeDbQuerySummary , info . Summarized ) ;
184+ activity ? . DisplayName = info. Summarized ! ;
185+ }
186+
187+ if ( KustoInstrumentation . MeterOptions . RecordQuerySummary )
188+ {
189+ meterTags . Add ( SemanticConventions . AttributeDbQuerySummary , info . Summarized ) ;
190+ }
169191 }
170192 }
171193 }
172194
173- this . contexts [ record . Activity . ActivityId ] = new ContextData ( beginTimestamp , tagList , activity ! ) ;
195+ this . contexts [ record . Activity . ActivityId ] = new ContextData ( beginTimestamp , meterTags , activity ! ) ;
174196
175197 this . CallEnrichment ( record ) ;
176198 }
@@ -191,12 +213,11 @@ private void HandleActivityComplete(KustoUtils.TraceRecord record)
191213 activity ? . SetStatus ( ActivityStatusCode . Ok ) ;
192214 }
193215
194- activity ? . AddTags ( context . Value . Tags ) ;
195216 this . CallEnrichment ( record ) ;
196217 activity ? . Stop ( ) ;
197218
198219 var duration = activity ? . Duration . TotalSeconds ?? GetElapsedTime ( context . Value . BeginTimestamp ) ;
199- KustoActivitySourceHelper . OperationDurationHistogram . Record ( duration , context . Value . Tags ) ;
220+ KustoActivitySourceHelper . OperationDurationHistogram . Record ( duration , context . Value . MeterTags ) ;
200221
201222 this . contexts . TryRemove ( record . Activity . ActivityId , out _ ) ;
202223 }
@@ -217,10 +238,10 @@ private void HandleActivityComplete(KustoUtils.TraceRecord record)
217238 /// </summary>
218239 private readonly struct ContextData
219240 {
220- public ContextData ( long beginTimestamp , TagList tags , Activity activity )
241+ public ContextData ( long beginTimestamp , TagList meterTags , Activity activity )
221242 {
222243 this . BeginTimestamp = beginTimestamp ;
223- this . Tags = tags ;
244+ this . MeterTags = meterTags ;
224245 this . Activity = activity ;
225246 }
226247
@@ -231,9 +252,9 @@ public ContextData(long beginTimestamp, TagList tags, Activity activity)
231252 public long BeginTimestamp { get ; }
232253
233254 /// <summary>
234- /// Gets the collection of tags associated with the operation that should be shared between the span and metrics.
255+ /// Gets the collection of tags associated with the operation that should be applies to metrics.
235256 /// </summary>
236- public TagList Tags { get ; }
257+ public TagList MeterTags { get ; }
237258
238259 /// <summary>
239260 /// Gets the current activity associated with the instance, if any.
0 commit comments