@@ -50,20 +50,22 @@ public void BeginRequest(HttpContext httpContext, HostingApplication.Context con
5050 }
5151
5252 var diagnosticListenerEnabled = _diagnosticListener . IsEnabled ( ) ;
53+ var diagnosticListenerActivityCreationEnabled = ( diagnosticListenerEnabled && _diagnosticListener . IsEnabled ( ActivityName , httpContext ) ) ;
5354 var loggingEnabled = _logger . IsEnabled ( LogLevel . Critical ) ;
5455
5556 // TODO: If loggingEnabled check to change to if ActivityPropogation options are enabled
56- if ( loggingEnabled || ( diagnosticListenerEnabled && _diagnosticListener . IsEnabled ( ActivityName , httpContext ) ) )
57+ if ( loggingEnabled || diagnosticListenerActivityCreationEnabled )
5758 {
5859 _dummyListener = new ActivityListener ( )
5960 {
60- ShouldListenTo = activitySource => activitySource . Name . Equals ( ActivitySourceName ) ,
61- Sample = ( ref ActivityCreationOptions < ActivityContext > _ ) => ActivitySamplingResult . PropagationData
61+ ShouldListenTo = activitySource => ReferenceEquals ( activitySource , _activitySource ) ,
62+ Sample = ( ref ActivityCreationOptions < ActivityContext > options ) => ActivitySamplingResult . PropagationData ,
63+ SampleUsingParentId = ( ref ActivityCreationOptions < string > options ) => ActivitySamplingResult . PropagationData
6264 } ;
6365 ActivitySource . AddActivityListener ( _dummyListener ) ;
6466 }
6567
66- context . Activity = StartActivity ( httpContext , out var hasDiagnosticListener ) ;
68+ context . Activity = StartActivity ( httpContext , diagnosticListenerActivityCreationEnabled , out var hasDiagnosticListener ) ;
6769 context . HasDiagnosticListener = hasDiagnosticListener ;
6870
6971 if ( diagnosticListenerEnabled )
@@ -261,12 +263,15 @@ private static void RecordRequestStartEventLog(HttpContext httpContext)
261263 }
262264
263265 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
264- private Activity ? StartActivity ( HttpContext httpContext , out bool hasDiagnosticListener )
266+ private Activity ? StartActivity ( HttpContext httpContext , bool diagnosticListenerActivityCreationEnabled , out bool hasDiagnosticListener )
265267 {
266268 hasDiagnosticListener = false ;
267- if ( _diagnosticListener . IsEnabled ( ActivityStartKey ) )
269+ if ( diagnosticListenerActivityCreationEnabled )
268270 {
269- hasDiagnosticListener = true ;
271+ if ( _diagnosticListener . IsEnabled ( ActivityStartKey ) )
272+ {
273+ hasDiagnosticListener = true ;
274+ }
270275 }
271276
272277 // Short-circuit to avoid doing an expensive header lookup
@@ -310,13 +315,16 @@ private static void RecordRequestStartEventLog(HttpContext httpContext)
310315 }
311316 }
312317
313- // Review: Breaking change: We will no longer fire OnActivityImport before Activity.Start()
314- _diagnosticListener . OnActivityImport ( activity , httpContext ) ;
315-
316- if ( hasDiagnosticListener )
318+ if ( diagnosticListenerActivityCreationEnabled )
317319 {
318- //Review: Do we need to explicity call this?
319- _diagnosticListener . Write ( ActivityStartKey , httpContext ) ;
320+ // Review: Breaking change: We will no longer fire OnActivityImport before Activity.Start()
321+ _diagnosticListener . OnActivityImport ( activity , httpContext ) ;
322+
323+ if ( hasDiagnosticListener )
324+ {
325+ //Review: Do we need to explicity call this?
326+ _diagnosticListener . Write ( ActivityStartKey , httpContext ) ;
327+ }
320328 }
321329 }
322330 return activity ;
0 commit comments