From 3af5a3b0b44f16415badb52d38d96f14ef9644a5 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 11 Mar 2022 18:04:34 -0800 Subject: [PATCH] Fix analyzer issues in docs (#3026) --- docs/logs/extending-the-sdk/Program.cs | 6 ++++-- docs/logs/getting-started/Program.cs | 2 ++ docs/logs/source-generation/FoodSupplyLogs.cs | 2 ++ docs/logs/source-generation/Program.cs | 2 ++ docs/metrics/customizing-the-sdk/Program.cs | 4 +++- docs/metrics/extending-the-sdk/Program.cs | 4 +++- .../getting-started-prometheus-grafana/Program.cs | 4 +++- docs/metrics/getting-started/Program.cs | 4 +++- docs/metrics/learning-more-instruments/Program.cs | 4 +++- docs/trace/customizing-the-sdk/Program.cs | 2 ++ .../extending-the-sdk/MyFilteringProcessor.cs | 14 ++------------ docs/trace/extending-the-sdk/Program.cs | 2 ++ docs/trace/extending-the-sdk/README.md | 2 +- docs/trace/getting-started/Program.cs | 2 ++ docs/trace/reporting-exceptions/Program.cs | 2 ++ docs/trace/reporting-exceptions/README.md | 2 +- 16 files changed, 37 insertions(+), 21 deletions(-) diff --git a/docs/logs/extending-the-sdk/Program.cs b/docs/logs/extending-the-sdk/Program.cs index b5560fa31a0..02bdf14bc4c 100644 --- a/docs/logs/extending-the-sdk/Program.cs +++ b/docs/logs/extending-the-sdk/Program.cs @@ -18,6 +18,8 @@ using Microsoft.Extensions.Logging; using OpenTelemetry; +namespace ExtendingTheSdk; + public class Program { public static void Main() @@ -37,8 +39,8 @@ public static void Main() // unstructured log logger.LogInformation("Hello, World!"); - // unstructured log with string interpolation - logger.LogInformation($"Hello from potato {0.99}."); + // String interpolation, as in the below line, results in unstructured logging, and is not recommended + // logger.LogInformation($"Hello from potato {0.99}."); // structured log with template logger.LogInformation("Hello from {name} {price}.", "tomato", 2.99); diff --git a/docs/logs/getting-started/Program.cs b/docs/logs/getting-started/Program.cs index e0eb8d41781..3cac963fd6f 100644 --- a/docs/logs/getting-started/Program.cs +++ b/docs/logs/getting-started/Program.cs @@ -17,6 +17,8 @@ using Microsoft.Extensions.Logging; using OpenTelemetry.Logs; +namespace GettingStarted; + public class Program { public static void Main() diff --git a/docs/logs/source-generation/FoodSupplyLogs.cs b/docs/logs/source-generation/FoodSupplyLogs.cs index 62485fd00f7..c7c54610bfb 100644 --- a/docs/logs/source-generation/FoodSupplyLogs.cs +++ b/docs/logs/source-generation/FoodSupplyLogs.cs @@ -16,6 +16,8 @@ using Microsoft.Extensions.Logging; +namespace SourceGeneration; + public static partial class FoodSupplyLogs { [LoggerMessage( diff --git a/docs/logs/source-generation/Program.cs b/docs/logs/source-generation/Program.cs index de5ac143e12..42c0e41ec3a 100644 --- a/docs/logs/source-generation/Program.cs +++ b/docs/logs/source-generation/Program.cs @@ -17,6 +17,8 @@ using Microsoft.Extensions.Logging; using OpenTelemetry.Logs; +namespace SourceGeneration; + public class Program { public static void Main() diff --git a/docs/metrics/customizing-the-sdk/Program.cs b/docs/metrics/customizing-the-sdk/Program.cs index 5770fabaf15..4172602fc2b 100644 --- a/docs/metrics/customizing-the-sdk/Program.cs +++ b/docs/metrics/customizing-the-sdk/Program.cs @@ -19,12 +19,14 @@ using OpenTelemetry; using OpenTelemetry.Metrics; +namespace CustomizingTheSdk; + public class Program { private static readonly Meter Meter1 = new("CompanyA.ProductA.Library1", "1.0"); private static readonly Meter Meter2 = new("CompanyA.ProductB.Library2", "1.0"); - public static void Main(string[] args) + public static void Main() { using var meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter(Meter1.Name) diff --git a/docs/metrics/extending-the-sdk/Program.cs b/docs/metrics/extending-the-sdk/Program.cs index 8f8b73fe5af..424985def10 100644 --- a/docs/metrics/extending-the-sdk/Program.cs +++ b/docs/metrics/extending-the-sdk/Program.cs @@ -21,6 +21,8 @@ using OpenTelemetry; using OpenTelemetry.Metrics; +namespace ExtendingTheSdk; + public class Program { private static readonly Meter MyMeter = new("MyCompany.MyProduct.MyLibrary", "1.0"); @@ -38,7 +40,7 @@ static Program() }); } - public static void Main(string[] args) + public static void Main() { using var meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter("MyCompany.MyProduct.MyLibrary") diff --git a/docs/metrics/getting-started-prometheus-grafana/Program.cs b/docs/metrics/getting-started-prometheus-grafana/Program.cs index a5758dcc16f..2e176c39f79 100644 --- a/docs/metrics/getting-started-prometheus-grafana/Program.cs +++ b/docs/metrics/getting-started-prometheus-grafana/Program.cs @@ -20,12 +20,14 @@ using OpenTelemetry; using OpenTelemetry.Metrics; +namespace GettingStartedPrometheusGrafana; + public class Program { private static readonly Meter MyMeter = new("MyCompany.MyProduct.MyLibrary", "1.0"); private static readonly Counter MyFruitCounter = MyMeter.CreateCounter("MyFruitCounter"); - public static void Main(string[] args) + public static void Main() { using var meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter("MyCompany.MyProduct.MyLibrary") diff --git a/docs/metrics/getting-started/Program.cs b/docs/metrics/getting-started/Program.cs index e681a6a6171..4911d3ce73c 100644 --- a/docs/metrics/getting-started/Program.cs +++ b/docs/metrics/getting-started/Program.cs @@ -18,12 +18,14 @@ using OpenTelemetry; using OpenTelemetry.Metrics; +namespace GettingStarted; + public class Program { private static readonly Meter MyMeter = new("MyCompany.MyProduct.MyLibrary", "1.0"); private static readonly Counter MyFruitCounter = MyMeter.CreateCounter("MyFruitCounter"); - public static void Main(string[] args) + public static void Main() { using var meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter("MyCompany.MyProduct.MyLibrary") diff --git a/docs/metrics/learning-more-instruments/Program.cs b/docs/metrics/learning-more-instruments/Program.cs index c9582a1bfe6..0db875f4e68 100644 --- a/docs/metrics/learning-more-instruments/Program.cs +++ b/docs/metrics/learning-more-instruments/Program.cs @@ -21,6 +21,8 @@ using OpenTelemetry; using OpenTelemetry.Metrics; +namespace LearningMoreInstruments; + public class Program { private static readonly Meter MyMeter = new("MyCompany.MyProduct.MyLibrary", "1.0"); @@ -35,7 +37,7 @@ static Program() MyMeter.CreateObservableGauge("Thread.State", () => GetThreadState(process)); } - public static void Main(string[] args) + public static void Main() { using var meterProvider = Sdk.CreateMeterProviderBuilder() .AddMeter("MyCompany.MyProduct.MyLibrary") diff --git a/docs/trace/customizing-the-sdk/Program.cs b/docs/trace/customizing-the-sdk/Program.cs index ae1f5cbbd54..8b07ac2470b 100644 --- a/docs/trace/customizing-the-sdk/Program.cs +++ b/docs/trace/customizing-the-sdk/Program.cs @@ -18,6 +18,8 @@ using OpenTelemetry; using OpenTelemetry.Trace; +namespace CustomizingTheSdk; + public class Program { private static readonly ActivitySource MyLibraryActivitySource = new( diff --git a/docs/trace/extending-the-sdk/MyFilteringProcessor.cs b/docs/trace/extending-the-sdk/MyFilteringProcessor.cs index 4734800faff..22cf898f3b5 100644 --- a/docs/trace/extending-the-sdk/MyFilteringProcessor.cs +++ b/docs/trace/extending-the-sdk/MyFilteringProcessor.cs @@ -25,18 +25,8 @@ internal class MyFilteringProcessor : BaseProcessor public MyFilteringProcessor(BaseProcessor processor, Func filter) { - if (filter == null) - { - throw new ArgumentNullException(nameof(filter)); - } - - if (processor == null) - { - throw new ArgumentNullException(nameof(processor)); - } - - this.filter = filter; - this.processor = processor; + this.filter = filter ?? throw new ArgumentNullException(nameof(filter)); + this.processor = processor ?? throw new ArgumentNullException(nameof(processor)); } public override void OnEnd(Activity activity) diff --git a/docs/trace/extending-the-sdk/Program.cs b/docs/trace/extending-the-sdk/Program.cs index 8db887dbab5..1fec8d87dc8 100644 --- a/docs/trace/extending-the-sdk/Program.cs +++ b/docs/trace/extending-the-sdk/Program.cs @@ -19,6 +19,8 @@ using OpenTelemetry.Resources; using OpenTelemetry.Trace; +namespace ExtendingTheSdk; + public class Program { private static readonly ActivitySource DemoSource = new("OTel.Demo"); diff --git a/docs/trace/extending-the-sdk/README.md b/docs/trace/extending-the-sdk/README.md index a9b427ec1d0..374c730e659 100644 --- a/docs/trace/extending-the-sdk/README.md +++ b/docs/trace/extending-the-sdk/README.md @@ -197,7 +197,7 @@ client .NET Core](../../../src/OpenTelemetry.Instrumentation.Http/README.md) . Instrumentation libraries for these are already provided in this repo. The [OpenTelemetry .NET Contrib](https://github.com/open-telemetry/opentelemetry-dotnet-contrib) -repostory also has instrumentations for libraries like +repository also has instrumentations for libraries like [ElasticSearchClient](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Contrib.Instrumentation.ElasticsearchClient) etc. which fall in this category. diff --git a/docs/trace/getting-started/Program.cs b/docs/trace/getting-started/Program.cs index af522b17d47..f88f1ca54c9 100644 --- a/docs/trace/getting-started/Program.cs +++ b/docs/trace/getting-started/Program.cs @@ -18,6 +18,8 @@ using OpenTelemetry; using OpenTelemetry.Trace; +namespace GettingStarted; + public class Program { private static readonly ActivitySource MyActivitySource = new( diff --git a/docs/trace/reporting-exceptions/Program.cs b/docs/trace/reporting-exceptions/Program.cs index f69db4c16bf..7ad5f70407c 100644 --- a/docs/trace/reporting-exceptions/Program.cs +++ b/docs/trace/reporting-exceptions/Program.cs @@ -19,6 +19,8 @@ using OpenTelemetry; using OpenTelemetry.Trace; +namespace ReportingExceptions; + public class Program { private static readonly ActivitySource MyActivitySource = new( diff --git a/docs/trace/reporting-exceptions/README.md b/docs/trace/reporting-exceptions/README.md index 74d2d4e1c3f..38bbc969998 100644 --- a/docs/trace/reporting-exceptions/README.md +++ b/docs/trace/reporting-exceptions/README.md @@ -136,7 +136,7 @@ will depend on the presence of a debugger: * If a debugger is attached, the debugger will be notified that an unhandled exception happened. * In case a postmortem debugger is configured, the postmortem debugger will be - activited and normally it will collect a crash dump. + activated and normally it will collect a crash dump. It might be useful to automatically capture the unhandled exceptions, travel through the unfinished activities and export them for troubleshooting. Here goes