diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props
index cdcba2f64b6..84759cd32a4 100644
--- a/build/Common.nonprod.props
+++ b/build/Common.nonprod.props
@@ -7,6 +7,10 @@
$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenTelemetry.sln'))\build\OpenTelemetry.test.ruleset
+
+ net7.0
+
+
true
diff --git a/build/test-aot-compatibility.ps1 b/build/test-aot-compatibility.ps1
index c80070de223..cde8dfc9839 100644
--- a/build/test-aot-compatibility.ps1
+++ b/build/test-aot-compatibility.ps1
@@ -10,6 +10,7 @@ foreach ($line in $($publishOutput -split "`r`n"))
if ($line -like "*analysis warning IL*")
{
Write-Host $line
+
$actualWarningCount += 1
}
}
@@ -28,7 +29,7 @@ if ($LastExitCode -ne 0)
popd
Write-Host "Actual warning count is:", $actualWarningCount
-$expectedWarningCount = 33
+$expectedWarningCount = 26
$testPassed = 0
if ($actualWarningCount -ne $expectedWarningCount)
diff --git a/examples/AspNetCore/Examples.AspNetCore.csproj b/examples/AspNetCore/Examples.AspNetCore.csproj
index fe6b61f8962..abeb406696e 100644
--- a/examples/AspNetCore/Examples.AspNetCore.csproj
+++ b/examples/AspNetCore/Examples.AspNetCore.csproj
@@ -1,7 +1,7 @@
- net6.0
+ $(DefaultTargetFrameworkForExampleApps)
diff --git a/examples/AspNetCore/Program.cs b/examples/AspNetCore/Program.cs
index 33e2a08abf0..2ee28a5dae4 100644
--- a/examples/AspNetCore/Program.cs
+++ b/examples/AspNetCore/Program.cs
@@ -26,20 +26,20 @@
var appBuilder = WebApplication.CreateBuilder(args);
// Note: Switch between Zipkin/Jaeger/OTLP/Console by setting UseTracingExporter in appsettings.json.
-var tracingExporter = appBuilder.Configuration.GetValue("UseTracingExporter").ToLowerInvariant();
+var tracingExporter = appBuilder.Configuration.GetValue("UseTracingExporter", defaultValue: "console")!.ToLowerInvariant();
// Note: Switch between Prometheus/OTLP/Console by setting UseMetricsExporter in appsettings.json.
-var metricsExporter = appBuilder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant();
+var metricsExporter = appBuilder.Configuration.GetValue("UseMetricsExporter", defaultValue: "console")!.ToLowerInvariant();
// Note: Switch between Console/OTLP by setting UseLogExporter in appsettings.json.
-var logExporter = appBuilder.Configuration.GetValue("UseLogExporter").ToLowerInvariant();
+var logExporter = appBuilder.Configuration.GetValue("UseLogExporter", defaultValue: "console")!.ToLowerInvariant();
// Note: Switch between Explicit/Exponential by setting HistogramAggregation in appsettings.json
-var histogramAggregation = appBuilder.Configuration.GetValue("HistogramAggregation").ToLowerInvariant();
+var histogramAggregation = appBuilder.Configuration.GetValue("HistogramAggregation", defaultValue: "explicit")!.ToLowerInvariant();
// Build a resource configuration action to set service information.
Action configureResource = r => r.AddService(
- serviceName: appBuilder.Configuration.GetValue("ServiceName"),
+ serviceName: appBuilder.Configuration.GetValue("ServiceName", defaultValue: "otel-test")!,
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown",
serviceInstanceId: Environment.MachineName);
@@ -94,7 +94,7 @@
builder.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
- otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint"));
+ otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
@@ -142,7 +142,7 @@
builder.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
- otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint"));
+ otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
default:
@@ -169,7 +169,7 @@
options.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
- otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint"));
+ otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
default:
diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj
index 2f4f047c070..9b03f7e08db 100644
--- a/examples/Console/Examples.Console.csproj
+++ b/examples/Console/Examples.Console.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ $(DefaultTargetFrameworkForExampleApps)
$(NoWarn),CS0618
diff --git a/examples/GrpcService/Examples.GrpcService.csproj b/examples/GrpcService/Examples.GrpcService.csproj
index 4d7aed6d3b2..0203f0d80c5 100644
--- a/examples/GrpcService/Examples.GrpcService.csproj
+++ b/examples/GrpcService/Examples.GrpcService.csproj
@@ -1,7 +1,7 @@
- net6.0
+ $(DefaultTargetFrameworkForExampleApps)
diff --git a/examples/GrpcService/Startup.cs b/examples/GrpcService/Startup.cs
index 85fbc5bb8fb..0d5ddeda954 100644
--- a/examples/GrpcService/Startup.cs
+++ b/examples/GrpcService/Startup.cs
@@ -36,24 +36,24 @@ public void ConfigureServices(IServiceCollection services)
.WithTracing(builder =>
{
builder
- .ConfigureResource(r => r.AddService(this.Configuration.GetValue("ServiceName")))
+ .ConfigureResource(r => r.AddService(this.Configuration.GetValue("ServiceName", defaultValue: "otel-test")!))
.AddAspNetCoreInstrumentation();
// Switch between Jaeger/Zipkin/Console by setting UseExporter in appsettings.json.
- var exporter = this.Configuration.GetValue("UseExporter").ToLowerInvariant();
+ var exporter = this.Configuration.GetValue("UseExporter", defaultValue: "console")!.ToLowerInvariant();
switch (exporter)
{
case "jaeger":
- builder.AddJaegerExporter(jaegerOptions =>
+ _ = builder.AddJaegerExporter(jaegerOptions =>
{
- jaegerOptions.AgentHost = this.Configuration.GetValue("Jaeger:Host");
- jaegerOptions.AgentPort = this.Configuration.GetValue("Jaeger:Port");
+ jaegerOptions.AgentHost = this.Configuration.GetValue("Jaeger:Host", defaultValue: "localhost");
+ jaegerOptions.AgentPort = this.Configuration.GetValue("Jaeger:Port", defaultValue: 6831);
});
break;
case "zipkin":
builder.AddZipkinExporter(zipkinOptions =>
{
- zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue("Zipkin:Endpoint"));
+ zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue("Zipkin:Endpoint", defaultValue: "http://localhost:9411/api/v2/spans")!);
});
break;
default:
diff --git a/examples/MicroserviceExample/WebApi/WebApi.csproj b/examples/MicroserviceExample/WebApi/WebApi.csproj
index 3697a904239..57bf07e763f 100644
--- a/examples/MicroserviceExample/WebApi/WebApi.csproj
+++ b/examples/MicroserviceExample/WebApi/WebApi.csproj
@@ -1,6 +1,6 @@
- net7.0
+ $(DefaultTargetFrameworkForExampleApps)
diff --git a/examples/MicroserviceExample/WorkerService/WorkerService.csproj b/examples/MicroserviceExample/WorkerService/WorkerService.csproj
index 78f61661324..b9b1a680772 100644
--- a/examples/MicroserviceExample/WorkerService/WorkerService.csproj
+++ b/examples/MicroserviceExample/WorkerService/WorkerService.csproj
@@ -1,6 +1,6 @@
- net7.0
+ $(DefaultTargetFrameworkForExampleApps)
diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
index 9a70f54689b..9221394b038 100644
--- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
+++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
@@ -17,9 +17,15 @@
using System.Data;
using System.Diagnostics;
using OpenTelemetry.Trace;
+#if NET6_0_OR_GREATER
+using System.Diagnostics.CodeAnalysis;
+#endif
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation;
+#if NET6_0_OR_GREATER
+[RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
+#endif
internal sealed class SqlClientDiagnosticListener : ListenerHandler
{
public const string SqlDataBeforeExecuteCommand = "System.Data.SqlClient.WriteCommandBefore";
diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs b/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs
index ea9bca53422..ba89db24fa2 100644
--- a/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs
+++ b/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs
@@ -14,6 +14,9 @@
// limitations under the License.
//
+#if NET6_0_OR_GREATER
+using System.Diagnostics.CodeAnalysis;
+#endif
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
namespace OpenTelemetry.Instrumentation.SqlClient;
@@ -24,7 +27,9 @@ namespace OpenTelemetry.Instrumentation.SqlClient;
internal sealed class SqlClientInstrumentation : IDisposable
{
internal const string SqlClientDiagnosticListenerName = "SqlClientDiagnosticListener";
-
+#if NET6_0_OR_GREATER
+ internal const string SqlClientTrimmingUnsupportedMessage = "Trimming is not yet supported with SqlClient instrumentation.";
+#endif
#if NETFRAMEWORK
private readonly SqlEventSourceListener sqlEventSourceListener;
#else
@@ -48,6 +53,9 @@ internal sealed class SqlClientInstrumentation : IDisposable
/// Initializes a new instance of the class.
///
/// Configuration options for sql instrumentation.
+#if NET6_0_OR_GREATER
+ [RequiresUnreferencedCode(SqlClientTrimmingUnsupportedMessage)]
+#endif
public SqlClientInstrumentation(
SqlClientInstrumentationOptions options = null)
{
diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs
index 0a9ba0cbe83..de5a6d832ae 100644
--- a/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs
+++ b/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs
@@ -14,6 +14,9 @@
// limitations under the License.
//
+#if NET6_0_OR_GREATER
+using System.Diagnostics.CodeAnalysis;
+#endif
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.SqlClient;
@@ -32,6 +35,9 @@ public static class TracerProviderBuilderExtensions
///
/// being configured.
/// The instance of to chain the calls.
+#if NET6_0_OR_GREATER
+ [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
+#endif
public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProviderBuilder builder)
=> AddSqlClientInstrumentation(builder, name: null, configureSqlClientInstrumentationOptions: null);
@@ -41,6 +47,9 @@ public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProvi
/// being configured.
/// Callback action for configuring .
/// The instance of to chain the calls.
+#if NET6_0_OR_GREATER
+ [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
+#endif
public static TracerProviderBuilder AddSqlClientInstrumentation(
this TracerProviderBuilder builder,
Action configureSqlClientInstrumentationOptions)
@@ -53,6 +62,10 @@ public static TracerProviderBuilder AddSqlClientInstrumentation(
/// Name which is used when retrieving options.
/// Callback action for configuring .
/// The instance of to chain the calls.
+#if NET6_0_OR_GREATER
+ [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
+#endif
+
public static TracerProviderBuilder AddSqlClientInstrumentation(
this TracerProviderBuilder builder,
string name,