Removed usage of Mock<BaseProcessor> (#5095)
This commit is contained in:
parent
6a829dd363
commit
79aa39fb7e
|
|
@ -120,14 +120,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
[InlineData(false)]
|
[InlineData(false)]
|
||||||
public async Task InjectsHeadersAsync(bool shouldEnrich)
|
public async Task InjectsHeadersAsync(bool shouldEnrich)
|
||||||
{
|
{
|
||||||
var processor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
processor.Setup(x => x.OnStart(It.IsAny<Activity>())).Callback<Activity>(c =>
|
|
||||||
{
|
|
||||||
c.SetTag("enrichedWithHttpWebRequest", "no");
|
|
||||||
c.SetTag("enrichedWithHttpWebResponse", "no");
|
|
||||||
c.SetTag("enrichedWithHttpRequestMessage", "no");
|
|
||||||
c.SetTag("enrichedWithHttpResponseMessage", "no");
|
|
||||||
});
|
|
||||||
|
|
||||||
using var request = new HttpRequestMessage
|
using var request = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
|
|
@ -167,15 +160,15 @@ public partial class HttpClientTests : IDisposable
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.AddProcessor(processor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
using var c = new HttpClient();
|
using var c = new HttpClient();
|
||||||
await c.SendAsync(request);
|
await c.SendAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called.
|
Assert.Single(exportedItems);
|
||||||
var activity = (Activity)processor.Invocations[2].Arguments[0];
|
var activity = exportedItems[0];
|
||||||
|
|
||||||
Assert.Equal(ActivityKind.Client, activity.Kind);
|
Assert.Equal(ActivityKind.Client, activity.Kind);
|
||||||
Assert.Equal(parent.TraceId, activity.Context.TraceId);
|
Assert.Equal(parent.TraceId, activity.Context.TraceId);
|
||||||
|
|
@ -198,17 +191,33 @@ public partial class HttpClientTests : IDisposable
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebRequest").FirstOrDefault().Value);
|
if (shouldEnrich)
|
||||||
Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebResponse").FirstOrDefault().Value);
|
{
|
||||||
|
Assert.Equal("yes", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebRequest").FirstOrDefault().Value);
|
||||||
|
Assert.Equal("yes", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebResponse").FirstOrDefault().Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpWebRequest");
|
||||||
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpWebResponse");
|
||||||
|
}
|
||||||
|
|
||||||
Assert.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpRequestMessage").FirstOrDefault().Value);
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpRequestMessage");
|
||||||
Assert.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpResponseMessage").FirstOrDefault().Value);
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpResponseMessage");
|
||||||
#else
|
#else
|
||||||
Assert.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebRequest").FirstOrDefault().Value);
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpWebRequest");
|
||||||
Assert.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebResponse").FirstOrDefault().Value);
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpWebResponse");
|
||||||
|
|
||||||
Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpRequestMessage").FirstOrDefault().Value);
|
if (shouldEnrich)
|
||||||
Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpResponseMessage").FirstOrDefault().Value);
|
{
|
||||||
|
Assert.Equal("yes", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpRequestMessage").FirstOrDefault().Value);
|
||||||
|
Assert.Equal("yes", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpResponseMessage").FirstOrDefault().Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpRequestMessage");
|
||||||
|
Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpResponseMessage");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,7 +232,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
action(message, "custom_tracestate", Activity.Current.TraceStateString);
|
action(message, "custom_tracestate", Activity.Current.TraceStateString);
|
||||||
});
|
});
|
||||||
|
|
||||||
var processor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
|
|
||||||
using var request = new HttpRequestMessage
|
using var request = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
|
|
@ -241,15 +250,15 @@ public partial class HttpClientTests : IDisposable
|
||||||
|
|
||||||
using (Sdk.CreateTracerProviderBuilder()
|
using (Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddProcessor(processor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
using var c = new HttpClient();
|
using var c = new HttpClient();
|
||||||
await c.SendAsync(request);
|
await c.SendAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called.
|
Assert.Single(exportedItems);
|
||||||
var activity = (Activity)processor.Invocations[2].Arguments[0];
|
var activity = exportedItems[0];
|
||||||
|
|
||||||
Assert.Equal(ActivityKind.Client, activity.Kind);
|
Assert.Equal(ActivityKind.Client, activity.Kind);
|
||||||
Assert.Equal(parent.TraceId, activity.Context.TraceId);
|
Assert.Equal(parent.TraceId, activity.Context.TraceId);
|
||||||
|
|
@ -291,7 +300,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
action(message, "custom_tracestate", Activity.Current.TraceStateString);
|
action(message, "custom_tracestate", Activity.Current.TraceStateString);
|
||||||
});
|
});
|
||||||
|
|
||||||
var processor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
|
|
||||||
using var request = new HttpRequestMessage
|
using var request = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
|
|
@ -309,7 +318,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
|
|
||||||
using (Sdk.CreateTracerProviderBuilder()
|
using (Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddProcessor(processor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
using var c = new HttpClient();
|
using var c = new HttpClient();
|
||||||
|
|
@ -321,7 +330,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
|
|
||||||
// If suppressed, activity is not emitted and
|
// If suppressed, activity is not emitted and
|
||||||
// propagation is also not performed.
|
// propagation is also not performed.
|
||||||
Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose called.
|
Assert.Empty(exportedItems);
|
||||||
Assert.False(request.Headers.Contains("custom_traceparent"));
|
Assert.False(request.Headers.Contains("custom_traceparent"));
|
||||||
Assert.False(request.Headers.Contains("custom_tracestate"));
|
Assert.False(request.Headers.Contains("custom_tracestate"));
|
||||||
}
|
}
|
||||||
|
|
@ -345,7 +354,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
Method = new HttpMethod("GET"),
|
Method = new HttpMethod("GET"),
|
||||||
};
|
};
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -357,7 +366,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
await httpClient.SendAsync(request);
|
await httpClient.SendAsync(request);
|
||||||
|
|
||||||
// number of exported spans should be 3(maxRetries)
|
// number of exported spans should be 3(maxRetries)
|
||||||
Assert.Equal(maxRetries, exportedItems.Count());
|
Assert.Equal(maxRetries, exportedItems.Count);
|
||||||
|
|
||||||
var spanid1 = exportedItems[0].SpanId;
|
var spanid1 = exportedItems[0].SpanId;
|
||||||
var spanid2 = exportedItems[1].SpanId;
|
var spanid2 = exportedItems[1].SpanId;
|
||||||
|
|
@ -390,7 +399,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
Method = new HttpMethod(originalMethod),
|
Method = new HttpMethod(originalMethod),
|
||||||
};
|
};
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -447,7 +456,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
Method = new HttpMethod(originalMethod),
|
Method = new HttpMethod(originalMethod),
|
||||||
};
|
};
|
||||||
|
|
||||||
using var meterprovider = Sdk.CreateMeterProviderBuilder()
|
using var meterProvider = Sdk.CreateMeterProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddInMemoryExporter(metricItems)
|
.AddInMemoryExporter(metricItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -463,7 +472,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
// ignore error.
|
// ignore error.
|
||||||
}
|
}
|
||||||
|
|
||||||
meterprovider.Dispose();
|
meterProvider.Dispose();
|
||||||
|
|
||||||
var metric = metricItems.FirstOrDefault(m => m.Name == "http.client.request.duration");
|
var metric = metricItems.FirstOrDefault(m => m.Name == "http.client.request.duration");
|
||||||
|
|
||||||
|
|
@ -493,10 +502,10 @@ public partial class HttpClientTests : IDisposable
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RedirectTest()
|
public async Task RedirectTest()
|
||||||
{
|
{
|
||||||
var processor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
using (Sdk.CreateTracerProviderBuilder()
|
using (Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddProcessor(processor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
using var c = new HttpClient();
|
using var c = new HttpClient();
|
||||||
|
|
@ -509,18 +518,12 @@ public partial class HttpClientTests : IDisposable
|
||||||
// good way to produce two spans when redirecting that we have
|
// good way to produce two spans when redirecting that we have
|
||||||
// found. For now, this is not supported.
|
// found. For now, this is not supported.
|
||||||
|
|
||||||
Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called.
|
Assert.Single(exportedItems);
|
||||||
|
Assert.Contains(exportedItems[0].TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 200);
|
||||||
var firstActivity = (Activity)processor.Invocations[2].Arguments[0]; // First OnEnd
|
|
||||||
Assert.Contains(firstActivity.TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 200);
|
|
||||||
#else
|
#else
|
||||||
Assert.Equal(7, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnStart/OnEnd/OnShutdown/Dispose called.
|
Assert.Equal(2, exportedItems.Count);
|
||||||
|
Assert.Contains(exportedItems[0].TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 302);
|
||||||
var firstActivity = (Activity)processor.Invocations[2].Arguments[0]; // First OnEnd
|
Assert.Contains(exportedItems[1].TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 200);
|
||||||
Assert.Contains(firstActivity.TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 302);
|
|
||||||
|
|
||||||
var secondActivity = (Activity)processor.Invocations[4].Arguments[0]; // Second OnEnd
|
|
||||||
Assert.Contains(secondActivity.TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 200);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -595,7 +598,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
var exportedItems = new List<Activity>();
|
var exportedItems = new List<Activity>();
|
||||||
bool exceptionThrown = false;
|
bool exceptionThrown = false;
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -621,7 +624,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
var exportedItems = new List<Activity>();
|
var exportedItems = new List<Activity>();
|
||||||
bool exceptionThrown = false;
|
bool exceptionThrown = false;
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -652,7 +655,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
Method = new HttpMethod("GET"),
|
Method = new HttpMethod("GET"),
|
||||||
};
|
};
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -706,7 +709,7 @@ public partial class HttpClientTests : IDisposable
|
||||||
|
|
||||||
var exportedItems = new List<Activity>();
|
var exportedItems = new List<Activity>();
|
||||||
|
|
||||||
using (var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using (var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.SetSampler(sample ? new ParentBasedSampler(new AlwaysOnSampler()) : new AlwaysOffSampler())
|
.SetSampler(sample ? new ParentBasedSampler(new AlwaysOnSampler()) : new AlwaysOffSampler())
|
||||||
|
|
|
||||||
|
|
@ -75,9 +75,9 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BacksOffIfAlreadyInstrumented()
|
public async Task BacksOffIfAlreadyInstrumented()
|
||||||
{
|
{
|
||||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddProcessor(activityProcessor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -90,12 +90,9 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
using var response = await request.GetResponseAsync();
|
using var response = await request.GetResponseAsync();
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
// Note: Back-off is part of the .NET Framework reflection only and
|
Assert.Empty(exportedItems);
|
||||||
// is needed to prevent issues when the same request is re-used for
|
|
||||||
// things like redirects or SSL negotiation.
|
|
||||||
Assert.Single(activityProcessor.Invocations); // SetParentProvider called
|
|
||||||
#else
|
#else
|
||||||
Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called
|
Assert.Single(exportedItems);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,7 +102,7 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
bool httpWebRequestFilterApplied = false;
|
bool httpWebRequestFilterApplied = false;
|
||||||
bool httpRequestMessageFilterApplied = false;
|
bool httpRequestMessageFilterApplied = false;
|
||||||
|
|
||||||
List<Activity> exportedItems = new();
|
var exportedItems = new List<Activity>();
|
||||||
|
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
|
|
@ -145,7 +142,7 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException()
|
public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException()
|
||||||
{
|
{
|
||||||
List<Activity> exportedItems = new();
|
var exportedItems = new List<Activity>();
|
||||||
|
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
|
|
@ -174,9 +171,9 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InjectsHeadersAsync()
|
public async Task InjectsHeadersAsync()
|
||||||
{
|
{
|
||||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddProcessor(activityProcessor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
@ -192,8 +189,8 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
|
|
||||||
using var response = await request.GetResponseAsync();
|
using var response = await request.GetResponseAsync();
|
||||||
|
|
||||||
Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called
|
Assert.Single(exportedItems);
|
||||||
var activity = (Activity)activityProcessor.Invocations[2].Arguments[0];
|
var activity = exportedItems[0];
|
||||||
|
|
||||||
Assert.Equal(parent.TraceId, activity.Context.TraceId);
|
Assert.Equal(parent.TraceId, activity.Context.TraceId);
|
||||||
Assert.Equal(parent.SpanId, activity.ParentSpanId);
|
Assert.Equal(parent.SpanId, activity.ParentSpanId);
|
||||||
|
|
@ -312,13 +309,11 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
|
|
||||||
int configurationDelegateInvocations = 0;
|
int configurationDelegateInvocations = 0;
|
||||||
|
|
||||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.ConfigureServices(services =>
|
.ConfigureServices(services =>
|
||||||
{
|
{
|
||||||
services.Configure<HttpClientInstrumentationOptions>(name, o => configurationDelegateInvocations++);
|
services.Configure<HttpClientInstrumentationOptions>(name, o => configurationDelegateInvocations++);
|
||||||
})
|
})
|
||||||
.AddProcessor(activityProcessor.Object)
|
|
||||||
.AddHttpClientInstrumentation(name, options =>
|
.AddHttpClientInstrumentation(name, options =>
|
||||||
{
|
{
|
||||||
Assert.IsType<HttpClientInstrumentationOptions>(options);
|
Assert.IsType<HttpClientInstrumentationOptions>(options);
|
||||||
|
|
@ -334,7 +329,7 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
var exportedItems = new List<Activity>();
|
var exportedItems = new List<Activity>();
|
||||||
bool exceptionThrown = false;
|
bool exceptionThrown = false;
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
@ -363,7 +358,7 @@ public partial class HttpWebRequestTests : IDisposable
|
||||||
var exportedItems = new List<Activity>();
|
var exportedItems = new List<Activity>();
|
||||||
bool exceptionThrown = false;
|
bool exceptionThrown = false;
|
||||||
|
|
||||||
using var traceprovider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
.AddHttpClientInstrumentation(o => o.RecordException = true)
|
||||||
.AddInMemoryExporter(exportedItems)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Moq;
|
|
||||||
using OpenTelemetry.Tests;
|
using OpenTelemetry.Tests;
|
||||||
using OpenTelemetry.Trace;
|
using OpenTelemetry.Trace;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -49,9 +48,9 @@ public partial class HttpWebRequestTests
|
||||||
bool enrichWithHttpResponseMessageCalled = false;
|
bool enrichWithHttpResponseMessageCalled = false;
|
||||||
bool enrichWithExceptionCalled = false;
|
bool enrichWithExceptionCalled = false;
|
||||||
|
|
||||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
var exportedItems = new List<Activity>();
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddProcessor(activityProcessor.Object)
|
.AddInMemoryExporter(exportedItems)
|
||||||
.AddHttpClientInstrumentation(options =>
|
.AddHttpClientInstrumentation(options =>
|
||||||
{
|
{
|
||||||
options.EnrichWithHttpWebRequest = (activity, httpWebRequest) => { enrichWithHttpWebRequestCalled = true; };
|
options.EnrichWithHttpWebRequest = (activity, httpWebRequest) => { enrichWithHttpWebRequestCalled = true; };
|
||||||
|
|
@ -92,8 +91,8 @@ public partial class HttpWebRequestTests
|
||||||
tc.ResponseExpected = false;
|
tc.ResponseExpected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called
|
Assert.Single(exportedItems);
|
||||||
var activity = (Activity)activityProcessor.Invocations[2].Arguments[0];
|
var activity = exportedItems[0];
|
||||||
ValidateHttpWebRequestActivity(activity);
|
ValidateHttpWebRequestActivity(activity);
|
||||||
Assert.Equal(tc.SpanName, activity.DisplayName);
|
Assert.Equal(tc.SpanName, activity.DisplayName);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue