diff --git a/build/Common.props b/build/Common.props
index 8feec5f986e..8a0a062ca07 100644
--- a/build/Common.props
+++ b/build/Common.props
@@ -21,7 +21,7 @@
net8.0;net6.0;netstandard2.0;$(NetFrameworkMinimumSupportedVersion)
net8.0;net6.0;netstandard2.1;netstandard2.0;$(NetFrameworkMinimumSupportedVersion)
- net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0
+ net8.0;net7.0;net6.0;netstandard2.0
net8.0;net6.0;netstandard2.1;netstandard2.0
net8.0;net6.0
diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs
index b8fd7c5ba27..49a07167bab 100644
--- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs
@@ -77,7 +77,7 @@ public class AspNetCoreInstrumentationOptions
///
public bool RecordException { get; set; }
-#if NETSTANDARD2_1 || NET6_0_OR_GREATER
+#if NET6_0_OR_GREATER
///
/// Gets or sets a value indicating whether RPC attributes are added to an Activity when using Grpc.AspNetCore. Default is true.
///
diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
index 67fa080bf8c..d346ac69e55 100644
--- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
+++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
@@ -8,6 +8,9 @@
semantic conventions.
([#5066](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5066))
+* Removed `netstandard2.1` target.
+ ([#5094](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5094))
+
## 1.6.0-beta.3
Released 2023-Nov-17
diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
index d2ea0e7f663..fcdf2e78cf6 100644
--- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
@@ -344,51 +344,6 @@ static bool TryFetchException(object payload, out Exception exc)
=> ExceptionPropertyFetcher.TryFetch(payload, out exc) && exc != null;
}
- private static string GetUri(HttpRequest request)
- {
- // this follows the suggestions from https://github.com/dotnet/aspnetcore/issues/28906
- var scheme = request.Scheme ?? string.Empty;
-
- // HTTP 1.0 request with NO host header would result in empty Host.
- // Use placeholder to avoid incorrect URL like "http:///"
- var host = request.Host.Value ?? UnknownHostName;
- var pathBase = request.PathBase.Value ?? string.Empty;
- var path = request.Path.Value ?? string.Empty;
- var queryString = request.QueryString.Value ?? string.Empty;
- var length = scheme.Length + Uri.SchemeDelimiter.Length + host.Length + pathBase.Length
- + path.Length + queryString.Length;
-
-#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
- return string.Create(length, (scheme, host, pathBase, path, queryString), (span, parts) =>
- {
- CopyTo(ref span, parts.scheme);
- CopyTo(ref span, Uri.SchemeDelimiter);
- CopyTo(ref span, parts.host);
- CopyTo(ref span, parts.pathBase);
- CopyTo(ref span, parts.path);
- CopyTo(ref span, parts.queryString);
-
- static void CopyTo(ref Span buffer, ReadOnlySpan text)
- {
- if (!text.IsEmpty)
- {
- text.CopyTo(buffer);
- buffer = buffer.Slice(text.Length);
- }
- }
- });
-#else
- return new System.Text.StringBuilder(length)
- .Append(scheme)
- .Append(Uri.SchemeDelimiter)
- .Append(host)
- .Append(pathBase)
- .Append(path)
- .Append(queryString)
- .ToString();
-#endif
- }
-
#if !NETSTANDARD2_0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryGetGrpcMethod(Activity activity, out string grpcMethod)
diff --git a/src/OpenTelemetry.Instrumentation.GrpcNetClient/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.GrpcNetClient/CHANGELOG.md
index 2299a1573a9..51ae981b732 100644
--- a/src/OpenTelemetry.Instrumentation.GrpcNetClient/CHANGELOG.md
+++ b/src/OpenTelemetry.Instrumentation.GrpcNetClient/CHANGELOG.md
@@ -2,6 +2,14 @@
## Unreleased
+* **Breaking Change** :
+ [SuppressDownstreamInstrumentation](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.GrpcNetClient#suppressdownstreaminstrumentation)
+ option will no longer be supported when used with certain versions of
+ `OpenTelemetry.Instrumentation.Http` package. Check out this
+ [issue](https://github.com/open-telemetry/opentelemetry-dotnet/issues/5092)
+ for details and workaround.
+ ([#5077](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5077))
+
## 1.6.0-beta.3
Released 2023-Nov-17
diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
index 2d5b686bfcc..5ef8ca9eb84 100644
--- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
+++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
@@ -11,6 +11,14 @@
* Update activity DisplayName as per the specification.
([#5078](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5078))
+* Removed reference to `OpenTelemetry` package. This is a **breaking change**
+ for users relying on
+ [SuppressDownstreamInstrumentation](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.GrpcNetClient#suppressdownstreaminstrumentation)
+ option in `OpenTelemetry.Instrumentation.GrpcNetClient`. For details, check
+ out this
+ [issue](https://github.com/open-telemetry/opentelemetry-dotnet/issues/5092).
+ ([#5077](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5077))
+
## 1.6.0-beta.3
Released 2023-Nov-17
diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs
index 30c2b41641d..f0cd19691e2 100644
--- a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs
@@ -20,9 +20,7 @@
using System.Net.Http;
#endif
using System.Runtime.CompilerServices;
-using Microsoft.Extensions.Configuration;
using OpenTelemetry.Instrumentation.Http.Implementation;
-using static OpenTelemetry.Internal.HttpSemanticConventionHelper;
namespace OpenTelemetry.Instrumentation.Http;
@@ -31,23 +29,6 @@ namespace OpenTelemetry.Instrumentation.Http;
///
public class HttpClientInstrumentationOptions
{
- internal readonly HttpSemanticConvention HttpSemanticConvention;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public HttpClientInstrumentationOptions()
- : this(new ConfigurationBuilder().AddEnvironmentVariables().Build())
- {
- }
-
- internal HttpClientInstrumentationOptions(IConfiguration configuration)
- {
- Debug.Assert(configuration != null, "configuration was null");
-
- this.HttpSemanticConvention = GetSemanticConventionOptIn(configuration);
- }
-
///
/// Gets or sets a filter function that determines whether or not to
/// collect telemetry on a per request basis.
diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs
index fb14e16c87f..f71707b37a5 100644
--- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs
@@ -104,11 +104,6 @@ public void OnStartActivity(Activity activity, object payload)
// By this time, samplers have already run and
// activity.IsAllDataRequested populated accordingly.
- if (Sdk.SuppressInstrumentation)
- {
- return;
- }
-
if (!TryFetchRequest(payload, out HttpRequestMessage request))
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs
index b3d45af15e8..15f6b6c1023 100644
--- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs
@@ -66,11 +66,6 @@ public override void OnEventWritten(string name, object payload)
public void OnStopEventWritten(Activity activity, object payload)
{
- if (Sdk.SuppressInstrumentation)
- {
- return;
- }
-
if (TryFetchRequest(payload, out HttpRequestMessage request))
{
// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-metrics.md
diff --git a/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj b/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj
index b9295759edf..32f80e31c21 100644
--- a/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj
+++ b/src/OpenTelemetry.Instrumentation.Http/OpenTelemetry.Instrumentation.Http.csproj
@@ -12,24 +12,22 @@
-
-
-
-
+
-
+
+
diff --git a/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs
index f8bb13a615c..cf0863091f0 100644
--- a/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs
+++ b/src/OpenTelemetry.Instrumentation.Http/TracerProviderBuilderExtensions.cs
@@ -72,8 +72,6 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(
{
services.Configure(name, configureHttpClientInstrumentationOptions);
}
-
- services.RegisterOptionsFactory(configuration => new HttpClientInstrumentationOptions(configuration));
});
#if NETFRAMEWORK
diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs
index e94ae3ef9e9..53328008bfb 100644
--- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs
+++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs
@@ -390,7 +390,7 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich)
Assert.Equal(shouldEnrich ? "yes" : "no", grpcSpan.Tags.Where(tag => tag.Key == "enrichedWithHttpResponseMessage").FirstOrDefault().Value);
}
- [Fact]
+ [Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/5092")]
public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation()
{
var uri = new Uri($"http://localhost:{this.server.Port}");
@@ -443,7 +443,7 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation()
Assert.Equal(0, grpcSpan4.GetTagValue(SemanticConventions.AttributeRpcGrpcStatusCode));
}
- [Fact]
+ [Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/5092")]
public void GrpcPropagatesContextWithSuppressInstrumentationOptionSetToTrue()
{
try
@@ -586,7 +586,7 @@ public void GrpcDoesNotPropagateContextWithSuppressInstrumentationOptionSetToFal
}
}
- [Fact]
+ [Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/5092")]
public void GrpcClientInstrumentationRespectsSdkSuppressInstrumentation()
{
try
diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs
index 0f0b487d5c9..1fe6ccee839 100644
--- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs
+++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs
@@ -120,14 +120,7 @@ public void AddHttpClientInstrumentation_BadArgs()
[InlineData(false)]
public async Task InjectsHeadersAsync(bool shouldEnrich)
{
- var processor = new Mock>();
- processor.Setup(x => x.OnStart(It.IsAny())).Callback(c =>
- {
- c.SetTag("enrichedWithHttpWebRequest", "no");
- c.SetTag("enrichedWithHttpWebResponse", "no");
- c.SetTag("enrichedWithHttpRequestMessage", "no");
- c.SetTag("enrichedWithHttpResponseMessage", "no");
- });
+ var exportedItems = new List();
using var request = new HttpRequestMessage
{
@@ -167,15 +160,15 @@ public async Task InjectsHeadersAsync(bool shouldEnrich)
};
}
})
- .AddProcessor(processor.Object)
+ .AddInMemoryExporter(exportedItems)
.Build())
{
using var c = new HttpClient();
await c.SendAsync(request);
}
- Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called.
- var activity = (Activity)processor.Invocations[2].Arguments[0];
+ Assert.Single(exportedItems);
+ var activity = exportedItems[0];
Assert.Equal(ActivityKind.Client, activity.Kind);
Assert.Equal(parent.TraceId, activity.Context.TraceId);
@@ -198,17 +191,33 @@ public async Task InjectsHeadersAsync(bool shouldEnrich)
#endif
#if NETFRAMEWORK
- Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebRequest").FirstOrDefault().Value);
- Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebResponse").FirstOrDefault().Value);
+ if (shouldEnrich)
+ {
+ 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.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpResponseMessage").FirstOrDefault().Value);
+ Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpRequestMessage");
+ Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpResponseMessage");
#else
- Assert.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebRequest").FirstOrDefault().Value);
- Assert.Equal("no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpWebResponse").FirstOrDefault().Value);
+ Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpWebRequest");
+ Assert.DoesNotContain(activity.Tags, tag => tag.Key == "enrichedWithHttpWebResponse");
- Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpRequestMessage").FirstOrDefault().Value);
- Assert.Equal(shouldEnrich ? "yes" : "no", activity.Tags.Where(tag => tag.Key == "enrichedWithHttpResponseMessage").FirstOrDefault().Value);
+ if (shouldEnrich)
+ {
+ 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
}
@@ -223,7 +232,7 @@ public async Task InjectsHeadersAsync_CustomFormat()
action(message, "custom_tracestate", Activity.Current.TraceStateString);
});
- var processor = new Mock>();
+ var exportedItems = new List();
using var request = new HttpRequestMessage
{
@@ -241,15 +250,15 @@ public async Task InjectsHeadersAsync_CustomFormat()
using (Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
- .AddProcessor(processor.Object)
+ .AddInMemoryExporter(exportedItems)
.Build())
{
using var c = new HttpClient();
await c.SendAsync(request);
}
- Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called.
- var activity = (Activity)processor.Invocations[2].Arguments[0];
+ Assert.Single(exportedItems);
+ var activity = exportedItems[0];
Assert.Equal(ActivityKind.Client, activity.Kind);
Assert.Equal(parent.TraceId, activity.Context.TraceId);
@@ -278,7 +287,7 @@ public async Task InjectsHeadersAsync_CustomFormat()
}));
}
- [Fact]
+ [Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/5092")]
public async Task RespectsSuppress()
{
try
@@ -291,7 +300,7 @@ public async Task RespectsSuppress()
action(message, "custom_tracestate", Activity.Current.TraceStateString);
});
- var processor = new Mock>();
+ var exportedItems = new List();
using var request = new HttpRequestMessage
{
@@ -309,7 +318,7 @@ public async Task RespectsSuppress()
using (Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
- .AddProcessor(processor.Object)
+ .AddInMemoryExporter(exportedItems)
.Build())
{
using var c = new HttpClient();
@@ -321,7 +330,7 @@ public async Task RespectsSuppress()
// If suppressed, activity is not emitted and
// 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_tracestate"));
}
@@ -345,7 +354,7 @@ public async Task ExportsSpansCreatedForRetries()
Method = new HttpMethod("GET"),
};
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
.AddInMemoryExporter(exportedItems)
.Build();
@@ -357,7 +366,7 @@ public async Task ExportsSpansCreatedForRetries()
await httpClient.SendAsync(request);
// number of exported spans should be 3(maxRetries)
- Assert.Equal(maxRetries, exportedItems.Count());
+ Assert.Equal(maxRetries, exportedItems.Count);
var spanid1 = exportedItems[0].SpanId;
var spanid2 = exportedItems[1].SpanId;
@@ -390,7 +399,7 @@ public async Task HttpRequestMethodIsSetOnActivityAsPerSpec(string originalMetho
Method = new HttpMethod(originalMethod),
};
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
.AddInMemoryExporter(exportedItems)
.Build();
@@ -447,7 +456,7 @@ public async Task HttpRequestMethodIsSetonRequestDurationMetricAsPerSpec(string
Method = new HttpMethod(originalMethod),
};
- using var meterprovider = Sdk.CreateMeterProviderBuilder()
+ using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddHttpClientInstrumentation()
.AddInMemoryExporter(metricItems)
.Build();
@@ -463,7 +472,7 @@ public async Task HttpRequestMethodIsSetonRequestDurationMetricAsPerSpec(string
// ignore error.
}
- meterprovider.Dispose();
+ meterProvider.Dispose();
var metric = metricItems.FirstOrDefault(m => m.Name == "http.client.request.duration");
@@ -493,10 +502,10 @@ public async Task HttpRequestMethodIsSetonRequestDurationMetricAsPerSpec(string
[Fact]
public async Task RedirectTest()
{
- var processor = new Mock>();
+ var exportedItems = new List();
using (Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
- .AddProcessor(processor.Object)
+ .AddInMemoryExporter(exportedItems)
.Build())
{
using var c = new HttpClient();
@@ -509,18 +518,12 @@ public async Task RedirectTest()
// good way to produce two spans when redirecting that we have
// found. For now, this is not supported.
- Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called.
-
- 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);
+ Assert.Single(exportedItems);
+ Assert.Contains(exportedItems[0].TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 200);
#else
- Assert.Equal(7, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnStart/OnEnd/OnShutdown/Dispose called.
-
- var firstActivity = (Activity)processor.Invocations[2].Arguments[0]; // First OnEnd
- 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);
+ Assert.Equal(2, exportedItems.Count);
+ Assert.Contains(exportedItems[0].TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 302);
+ Assert.Contains(exportedItems[1].TagObjects, t => t.Key == "http.response.status_code" && (int)t.Value == 200);
#endif
}
@@ -595,7 +598,7 @@ public async Task ReportsExceptionEventForNetworkFailuresWithGetAsync()
var exportedItems = new List();
bool exceptionThrown = false;
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation(o => o.RecordException = true)
.AddInMemoryExporter(exportedItems)
.Build();
@@ -621,7 +624,7 @@ public async Task DoesNotReportExceptionEventOnErrorResponseWithGetAsync()
var exportedItems = new List();
bool exceptionThrown = false;
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation(o => o.RecordException = true)
.AddInMemoryExporter(exportedItems)
.Build();
@@ -652,7 +655,7 @@ public async Task DoesNotReportExceptionEventOnErrorResponseWithGetStringAsync()
Method = new HttpMethod("GET"),
};
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation(o => o.RecordException = true)
.AddInMemoryExporter(exportedItems)
.Build();
@@ -706,7 +709,7 @@ public async Task CustomPropagatorCalled(bool sample, bool createParentActivity)
var exportedItems = new List();
- using (var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using (var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
.AddInMemoryExporter(exportedItems)
.SetSampler(sample ? new ParentBasedSampler(new AlwaysOnSampler()) : new AlwaysOffSampler())
diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.cs
index 40f0cf9a873..be35cedaee4 100644
--- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.cs
+++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.cs
@@ -75,9 +75,9 @@ public void Dispose()
[Fact]
public async Task BacksOffIfAlreadyInstrumented()
{
- var activityProcessor = new Mock>();
+ var exportedItems = new List();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
- .AddProcessor(activityProcessor.Object)
+ .AddInMemoryExporter(exportedItems)
.AddHttpClientInstrumentation()
.Build();
@@ -90,12 +90,9 @@ public async Task BacksOffIfAlreadyInstrumented()
using var response = await request.GetResponseAsync();
#if NETFRAMEWORK
- // Note: Back-off is part of the .NET Framework reflection only and
- // 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
+ Assert.Empty(exportedItems);
#else
- Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called
+ Assert.Single(exportedItems);
#endif
}
@@ -105,7 +102,7 @@ public async Task RequestNotCollectedWhenInstrumentationFilterApplied()
bool httpWebRequestFilterApplied = false;
bool httpRequestMessageFilterApplied = false;
- List exportedItems = new();
+ var exportedItems = new List();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddInMemoryExporter(exportedItems)
@@ -145,7 +142,7 @@ public async Task RequestNotCollectedWhenInstrumentationFilterApplied()
[Fact]
public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException()
{
- List exportedItems = new();
+ var exportedItems = new List();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddInMemoryExporter(exportedItems)
@@ -174,9 +171,9 @@ public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException()
[Fact]
public async Task InjectsHeadersAsync()
{
- var activityProcessor = new Mock>();
+ var exportedItems = new List();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
- .AddProcessor(activityProcessor.Object)
+ .AddInMemoryExporter(exportedItems)
.AddHttpClientInstrumentation()
.Build();
@@ -192,8 +189,8 @@ public async Task InjectsHeadersAsync()
using var response = await request.GetResponseAsync();
- Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called
- var activity = (Activity)activityProcessor.Invocations[2].Arguments[0];
+ Assert.Single(exportedItems);
+ var activity = exportedItems[0];
Assert.Equal(parent.TraceId, activity.Context.TraceId);
Assert.Equal(parent.SpanId, activity.ParentSpanId);
@@ -312,13 +309,11 @@ public void AddHttpClientInstrumentationUsesOptionsApi(string name)
int configurationDelegateInvocations = 0;
- var activityProcessor = new Mock>();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureServices(services =>
{
services.Configure(name, o => configurationDelegateInvocations++);
})
- .AddProcessor(activityProcessor.Object)
.AddHttpClientInstrumentation(name, options =>
{
Assert.IsType(options);
@@ -334,7 +329,7 @@ public async Task ReportsExceptionEventForNetworkFailures()
var exportedItems = new List();
bool exceptionThrown = false;
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation(o => o.RecordException = true)
.AddInMemoryExporter(exportedItems)
.Build();
@@ -363,7 +358,7 @@ public async Task ReportsExceptionEventOnErrorResponse()
var exportedItems = new List();
bool exceptionThrown = false;
- using var traceprovider = Sdk.CreateTracerProviderBuilder()
+ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation(o => o.RecordException = true)
.AddInMemoryExporter(exportedItems)
.Build();
diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.cs
index 1a95c0cdbf6..a9ed60c07e6 100644
--- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.cs
+++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.cs
@@ -17,7 +17,6 @@
using System.Diagnostics;
using System.Net;
using System.Text.Json;
-using Moq;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
using Xunit;
@@ -49,9 +48,9 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc
bool enrichWithHttpResponseMessageCalled = false;
bool enrichWithExceptionCalled = false;
- var activityProcessor = new Mock>();
+ var exportedItems = new List();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
- .AddProcessor(activityProcessor.Object)
+ .AddInMemoryExporter(exportedItems)
.AddHttpClientInstrumentation(options =>
{
options.EnrichWithHttpWebRequest = (activity, httpWebRequest) => { enrichWithHttpWebRequestCalled = true; };
@@ -92,8 +91,8 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc
tc.ResponseExpected = false;
}
- Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called
- var activity = (Activity)activityProcessor.Invocations[2].Arguments[0];
+ Assert.Single(exportedItems);
+ var activity = exportedItems[0];
ValidateHttpWebRequestActivity(activity);
Assert.Equal(tc.SpanName, activity.DisplayName);