diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index cdcba2f64..84759cd32 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/examples/AspNetCore/Examples.AspNetCore.csproj b/examples/AspNetCore/Examples.AspNetCore.csproj index fe6b61f89..abeb40669 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 33e2a08ab..2ee28a5da 100644 --- a/examples/AspNetCore/Program.cs +++ b/examples/AspNetCore/Program.cs @@ -26,20 +26,20 @@ using OpenTelemetry.Trace; 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 @@ appBuilder.Services.AddOpenTelemetry() 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 @@ appBuilder.Services.AddOpenTelemetry() 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 @@ appBuilder.Logging.AddOpenTelemetry(options => 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 2f4f047c0..9b03f7e08 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 4d7aed6d3..0203f0d80 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 85fbc5bb8..0d5ddeda9 100644 --- a/examples/GrpcService/Startup.cs +++ b/examples/GrpcService/Startup.cs @@ -36,24 +36,24 @@ public class Startup .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 3697a9042..57bf07e76 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 78f616613..b9b1a6807 100644 --- a/examples/MicroserviceExample/WorkerService/WorkerService.csproj +++ b/examples/MicroserviceExample/WorkerService/WorkerService.csproj @@ -1,6 +1,6 @@ - net7.0 + $(DefaultTargetFrameworkForExampleApps)