Skip to content

Commit 79ec511

Browse files
committed
PR feedback
1 parent 3ab7789 commit 79ec511

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Hosting/Hosting/test/HostingApplicationDiagnosticsTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,20 @@ public void EventCountersEnabled()
159159
public void Metrics_RequestDuration_RecordedWithHttpActivity()
160160
{
161161
// Arrange
162+
Activity measurementActivity = null;
163+
var measureCount = 0;
164+
165+
// Listen to hosting activity source.
166+
var testSource = new ActivitySource(Path.GetRandomFileName());
162167
using var activityListener = new ActivityListener
163168
{
164-
ShouldListenTo = activitySource => activitySource.Name == "Microsoft.AspNetCore",
169+
ShouldListenTo = activitySource => ReferenceEquals(activitySource, testSource),
165170
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData
166171
};
167172
ActivitySource.AddActivityListener(activityListener);
168173

174+
// Listen to http.server.request.duration.
169175
var testMeterFactory = new TestMeterFactory();
170-
171176
var meterListener = new MeterListener();
172177
meterListener.InstrumentPublished = (i, l) =>
173178
{
@@ -176,9 +181,6 @@ public void Metrics_RequestDuration_RecordedWithHttpActivity()
176181
l.EnableMeasurementEvents(i);
177182
}
178183
};
179-
180-
Activity measurementActivity = null;
181-
var measureCount = 0;
182184
meterListener.SetMeasurementEventCallback<double>((i, m, t, s) =>
183185
{
184186
if (Interlocked.Increment(ref measureCount) > 1)
@@ -191,7 +193,7 @@ public void Metrics_RequestDuration_RecordedWithHttpActivity()
191193
meterListener.Start();
192194

193195
// Act
194-
var hostingApplication = CreateApplication(out var features, meterFactory: testMeterFactory);
196+
var hostingApplication = CreateApplication(out var features, activitySource: testSource, meterFactory: testMeterFactory);
195197
var context = hostingApplication.CreateContext(features);
196198
hostingApplication.DisposeContext(context, null);
197199

0 commit comments

Comments
 (0)