|
11 | 11 | using Microsoft.AspNetCore.Http;
|
12 | 12 | using Microsoft.AspNetCore.Http.Features;
|
13 | 13 | using Microsoft.Extensions.Logging;
|
14 |
| -using Microsoft.Extensions.ObjectPool; |
15 |
| -using Microsoft.Extensions.Options; |
16 | 14 | using Moq;
|
17 | 15 | using Xunit;
|
18 | 16 |
|
@@ -304,6 +302,34 @@ public void ActivityTraceParentAndTraceStateFromHeaders()
|
304 | 302 | Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key2" && pair.Value == "value2");
|
305 | 303 | }
|
306 | 304 |
|
| 305 | + [Fact] |
| 306 | + public void ActivityOnExportHookIsCalled() |
| 307 | + { |
| 308 | + var diagnosticSource = new DiagnosticListener("DummySource"); |
| 309 | + var hostingApplication = CreateApplication(out var features, diagnosticSource: diagnosticSource); |
| 310 | + |
| 311 | + bool onActivityImportCalled = false; |
| 312 | + diagnosticSource.Subscribe( |
| 313 | + observer: new CallbackDiagnosticListener(pair => { }), |
| 314 | + isEnabled: (s, o, _) => true, |
| 315 | + onActivityImport: (activity, context) => |
| 316 | + { |
| 317 | + onActivityImportCalled = true; |
| 318 | + Assert.Null(Activity.Current); |
| 319 | + Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", activity.OperationName); |
| 320 | + Assert.NotNull(context); |
| 321 | + Assert.IsAssignableFrom<HttpContext>(context); |
| 322 | + |
| 323 | + activity.ActivityTraceFlags = ActivityTraceFlags.Recorded; |
| 324 | + }); |
| 325 | + |
| 326 | + hostingApplication.CreateContext(features); |
| 327 | + |
| 328 | + Assert.True(onActivityImportCalled); |
| 329 | + Assert.NotNull(Activity.Current); |
| 330 | + Assert.True(Activity.Current.Recorded); |
| 331 | + } |
| 332 | + |
307 | 333 |
|
308 | 334 | private static void AssertProperty<T>(object o, string name)
|
309 | 335 | {
|
|
0 commit comments