Skip to content

Commit

Permalink
[sdk] Improve readability of TracerProviderSdk initialization code (#…
Browse files Browse the repository at this point in the history
…5810)

Co-authored-by: Mikel Blanchard <[email protected]>
  • Loading branch information
Kielek and CodeBlanch authored Sep 4, 2024
1 parent 104c9f0 commit 1479686
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal TracerProviderSdk(
OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent($"Instrumentations added = \"{instrumentationFactoriesAdded}\".");
}

var listener = new ActivityListener();
var activityListener = new ActivityListener();

if (this.supportLegacyActivity)
{
Expand All @@ -125,7 +125,7 @@ internal TracerProviderSdk(
legacyActivityPredicate = activity => state.LegacyActivityOperationNames.Contains(activity.OperationName);
}

listener.ActivityStarted = activity =>
activityListener.ActivityStarted = activity =>
{
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity);
Expand Down Expand Up @@ -163,7 +163,7 @@ internal TracerProviderSdk(
}
};

listener.ActivityStopped = activity =>
activityListener.ActivityStopped = activity =>
{
OpenTelemetrySdkEventSource.Log.ActivityStopped(activity);
Expand Down Expand Up @@ -194,7 +194,7 @@ internal TracerProviderSdk(
}
else
{
listener.ActivityStarted = activity =>
activityListener.ActivityStarted = activity =>
{
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity);
Expand All @@ -204,7 +204,7 @@ internal TracerProviderSdk(
}
};

listener.ActivityStopped = activity =>
activityListener.ActivityStopped = activity =>
{
OpenTelemetrySdkEventSource.Log.ActivityStopped(activity);
Expand All @@ -230,20 +230,20 @@ internal TracerProviderSdk(

if (this.sampler is AlwaysOnSampler)
{
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
activityListener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
!Sdk.SuppressInstrumentation ? ActivitySamplingResult.AllDataAndRecorded : ActivitySamplingResult.None;
this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOnSampler;
}
else if (this.sampler is AlwaysOffSampler)
{
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
activityListener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent) : ActivitySamplingResult.None;
this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOffSampler;
}
else
{
// This delegate informs ActivitySource about sampling decision when the parent context is an ActivityContext.
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
activityListener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
!Sdk.SuppressInstrumentation ? ComputeActivitySamplingResult(ref options, this.sampler) : ActivitySamplingResult.None;
this.getRequestedDataAction = this.RunGetRequestedDataOtherSampler;
}
Expand All @@ -260,7 +260,7 @@ internal TracerProviderSdk(

// Function which takes ActivitySource and returns true/false to indicate if it should be subscribed to
// or not.
listener.ShouldListenTo = (activitySource) =>
activityListener.ShouldListenTo = activitySource =>
this.supportLegacyActivity ?
string.IsNullOrEmpty(activitySource.Name) || regex.IsMatch(activitySource.Name) :
regex.IsMatch(activitySource.Name);
Expand All @@ -276,19 +276,19 @@ internal TracerProviderSdk(

// Function which takes ActivitySource and returns true/false to indicate if it should be subscribed to
// or not.
listener.ShouldListenTo = (activitySource) => activitySources.Contains(activitySource.Name);
activityListener.ShouldListenTo = activitySource => activitySources.Contains(activitySource.Name);
}
}
else
{
if (this.supportLegacyActivity)
{
listener.ShouldListenTo = (activitySource) => string.IsNullOrEmpty(activitySource.Name);
activityListener.ShouldListenTo = activitySource => string.IsNullOrEmpty(activitySource.Name);
}
}

ActivitySource.AddActivityListener(listener);
this.listener = listener;
ActivitySource.AddActivityListener(activityListener);
this.listener = activityListener;
OpenTelemetrySdkEventSource.Log.TracerProviderSdkEvent("TracerProvider built successfully.");
}

Expand Down

0 comments on commit 1479686

Please sign in to comment.