diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj index d2b74f2e648..86c6b1df037 100644 --- a/examples/Console/Examples.Console.csproj +++ b/examples/Console/Examples.Console.csproj @@ -4,9 +4,6 @@ Exe $(DefaultTargetFrameworkForExampleApps) $(NoWarn),CS0618 - - - disable diff --git a/examples/Console/InstrumentationWithActivitySource.cs b/examples/Console/InstrumentationWithActivitySource.cs index 240f58289d8..706d68ad993 100644 --- a/examples/Console/InstrumentationWithActivitySource.cs +++ b/examples/Console/InstrumentationWithActivitySource.cs @@ -47,13 +47,13 @@ public void Start(string url) var context = this.listener.GetContext(); using var activity = source.StartActivity( - $"{context.Request.HttpMethod}:{context.Request.Url.AbsolutePath}", + $"{context.Request.HttpMethod}:{context.Request.Url!.AbsolutePath}", ActivityKind.Server); var headerKeys = context.Request.Headers.AllKeys; foreach (var headerKey in headerKeys) { - string headerValue = context.Request.Headers[headerKey]; + string? headerValue = context.Request.Headers[headerKey]; activity?.SetTag($"http.header.{headerKey}", headerValue); } @@ -62,7 +62,7 @@ public void Start(string url) using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding)) { requestContent = reader.ReadToEnd(); - childSpan.AddEvent(new ActivityEvent("StreamReader.ReadToEnd")); + childSpan?.AddEvent(new ActivityEvent("StreamReader.ReadToEnd")); } activity?.SetTag("request.content", requestContent); @@ -90,8 +90,8 @@ public void Dispose() private class SampleClient : IDisposable { - private CancellationTokenSource cts; - private Task requestTask; + private CancellationTokenSource? cts; + private Task? requestTask; public void Start(string url) { @@ -154,7 +154,7 @@ public void Dispose() if (this.cts != null) { this.cts.Cancel(); - this.requestTask.Wait(); + this.requestTask!.Wait(); this.requestTask.Dispose(); this.cts.Dispose(); } diff --git a/examples/Console/Program.cs b/examples/Console/Program.cs index 2b93979e071..bca2e4339c7 100644 --- a/examples/Console/Program.cs +++ b/examples/Console/Program.cs @@ -33,16 +33,16 @@ public static void Main(string[] args) { Parser.Default.ParseArguments(args) .MapResult( - (ZipkinOptions options) => TestZipkinExporter.Run(options.Uri), - (PrometheusOptions options) => TestPrometheusExporter.Run(options.Port), + (ZipkinOptions options) => TestZipkinExporter.Run(options), + (PrometheusOptions options) => TestPrometheusExporter.Run(options), (MetricsOptions options) => TestMetrics.Run(options), (LogsOptions options) => TestLogs.Run(options), - (GrpcNetClientOptions options) => TestGrpcNetClient.Run(), - (HttpClientOptions options) => TestHttpClient.Run(), + (GrpcNetClientOptions options) => TestGrpcNetClient.Run(options), + (HttpClientOptions options) => TestHttpClient.Run(options), (ConsoleOptions options) => TestConsoleExporter.Run(options), (OpenTelemetryShimOptions options) => TestOTelShimWithConsoleExporter.Run(options), (OpenTracingShimOptions options) => TestOpenTracingShim.Run(options), - (OtlpOptions options) => TestOtlpExporter.Run(options.Endpoint, options.Protocol), + (OtlpOptions options) => TestOtlpExporter.Run(options), (InMemoryOptions options) => TestInMemoryExporter.Run(options), errs => 1); } @@ -54,7 +54,7 @@ public static void Main(string[] args) internal class ZipkinOptions { [Option('u', "uri", HelpText = "Please specify the uri of Zipkin backend", Required = true)] - public string Uri { get; set; } + public required string Uri { get; set; } } [Verb("prometheus", HelpText = "Specify the options required to test Prometheus")] @@ -83,10 +83,10 @@ internal class MetricsOptions public int DefaultCollectionPeriodMilliseconds { get; set; } [Option("useExporter", Default = "console", HelpText = "Options include otlp or console.", Required = false)] - public string UseExporter { get; set; } + public string? UseExporter { get; set; } [Option('e', "endpoint", HelpText = "Target to which the exporter is going to send metrics (default value depends on protocol).", Default = null)] - public string Endpoint { get; set; } + public string? Endpoint { get; set; } [Option('p', "useGrpc", HelpText = "Use gRPC or HTTP when using the OTLP exporter", Required = false, Default = true)] public bool UseGrpc { get; set; } @@ -121,26 +121,26 @@ internal class OpenTracingShimOptions internal class OtlpOptions { [Option('e', "endpoint", HelpText = "Target to which the exporter is going to send traces (default value depends on protocol).", Default = null)] - public string Endpoint { get; set; } + public string? Endpoint { get; set; } [Option('p', "protocol", HelpText = "Transport protocol used by exporter. Supported values: grpc and http/protobuf.", Default = "grpc")] - public string Protocol { get; set; } + public string? Protocol { get; set; } } [Verb("logs", HelpText = "Specify the options required to test Logs")] internal class LogsOptions { [Option("useExporter", Default = "otlp", HelpText = "Options include otlp or console.", Required = false)] - public string UseExporter { get; set; } + public string? UseExporter { get; set; } [Option('e', "endpoint", HelpText = "Target to which the OTLP exporter is going to send logs (default value depends on protocol).", Default = null)] - public string Endpoint { get; set; } + public string? Endpoint { get; set; } [Option('p', "protocol", HelpText = "Transport protocol used by OTLP exporter. Supported values: grpc and http/protobuf. Only applicable if Exporter is OTLP", Default = "grpc")] - public string Protocol { get; set; } + public string? Protocol { get; set; } [Option("processorType", Default = "batch", HelpText = "export processor type. Supported values: simple and batch", Required = false)] - public string ProcessorType { get; set; } + public string? ProcessorType { get; set; } [Option("scheduledDelay", Default = 5000, HelpText = "The delay interval in milliseconds between two consecutive exports.", Required = false)] public int ScheduledDelayInMilliseconds { get; set; } diff --git a/examples/Console/TestConsoleExporter.cs b/examples/Console/TestConsoleExporter.cs index cf3f803c4fd..7a70c0ef1e4 100644 --- a/examples/Console/TestConsoleExporter.cs +++ b/examples/Console/TestConsoleExporter.cs @@ -15,21 +15,21 @@ internal class TestConsoleExporter // (eg: C:\repos\opentelemetry-dotnet\examples\Console\) // // dotnet run console - internal static object Run(ConsoleOptions options) + internal static int Run(ConsoleOptions options) { return RunWithActivitySource(); } - private static object RunWithActivitySource() + private static int RunWithActivitySource() { // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use Console exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResource(res => res.AddService("console-test")) - .AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter - .AddConsoleExporter() - .Build(); + .AddSource("Samples.SampleClient", "Samples.SampleServer") + .ConfigureResource(res => res.AddService("console-test")) + .AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter + .AddConsoleExporter() + .Build(); // The above line is required only in applications // which decide to use OpenTelemetry. @@ -43,7 +43,7 @@ private static object RunWithActivitySource() System.Console.ReadLine(); } - return null; + return 0; } /// diff --git a/examples/Console/TestGrpcNetClient.cs b/examples/Console/TestGrpcNetClient.cs index d179d93913e..31dce4a1679 100644 --- a/examples/Console/TestGrpcNetClient.cs +++ b/examples/Console/TestGrpcNetClient.cs @@ -12,8 +12,10 @@ namespace Examples.Console; internal class TestGrpcNetClient { - internal static object Run() + internal static int Run(GrpcNetClientOptions options) { + Debug.Assert(options != null, "options was null"); + // Prerequisite for running this example. // In a separate console window, start the example // ASP.NET Core gRPC service by running the following command @@ -55,6 +57,6 @@ internal static object Run() System.Console.WriteLine("Press Enter key to exit."); System.Console.ReadLine(); - return null; + return 0; } } diff --git a/examples/Console/TestHttpClient.cs b/examples/Console/TestHttpClient.cs index 27305a50523..7629a622af7 100644 --- a/examples/Console/TestHttpClient.cs +++ b/examples/Console/TestHttpClient.cs @@ -15,8 +15,10 @@ internal class TestHttpClient // (eg: C:\repos\opentelemetry-dotnet\examples\Console\) // // dotnet run httpclient - internal static object Run() + internal static int Run(HttpClientOptions options) { + Debug.Assert(options != null, "options was null"); + System.Console.WriteLine("Hello World!"); using var tracerProvider = Sdk.CreateTracerProviderBuilder() @@ -36,6 +38,6 @@ internal static object Run() System.Console.WriteLine("Press Enter key to exit."); System.Console.ReadLine(); - return null; + return 0; } } diff --git a/examples/Console/TestInMemoryExporter.cs b/examples/Console/TestInMemoryExporter.cs index 53d3dd7f49e..057bc19cdec 100644 --- a/examples/Console/TestInMemoryExporter.cs +++ b/examples/Console/TestInMemoryExporter.cs @@ -15,7 +15,7 @@ internal class TestInMemoryExporter // (eg: C:\repos\opentelemetry-dotnet\examples\Console\) // // dotnet run inmemory - internal static object Run(InMemoryOptions options) + internal static int Run(InMemoryOptions options) { // List that will be populated with the traces by InMemoryExporter var exportedItems = new List(); @@ -28,7 +28,7 @@ internal static object Run(InMemoryOptions options) System.Console.WriteLine($"ActivitySource: {activity.Source.Name} logged the activity {activity.DisplayName}"); } - return null; + return 0; } private static void RunWithActivitySource(ICollection exportedItems) @@ -36,10 +36,10 @@ private static void RunWithActivitySource(ICollection exportedItems) // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use InMemory exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResource(r => r.AddService("inmemory-test")) - .AddInMemoryExporter(exportedItems) - .Build(); + .AddSource("Samples.SampleClient", "Samples.SampleServer") + .ConfigureResource(r => r.AddService("inmemory-test")) + .AddInMemoryExporter(exportedItems) + .Build(); // The above line is required only in applications // which decide to use OpenTelemetry. diff --git a/examples/Console/TestLogs.cs b/examples/Console/TestLogs.cs index 4c88753ffd7..427193799ac 100644 --- a/examples/Console/TestLogs.cs +++ b/examples/Console/TestLogs.cs @@ -9,7 +9,7 @@ namespace Examples.Console; internal class TestLogs { - internal static object Run(LogsOptions options) + internal static int Run(LogsOptions options) { using var loggerFactory = LoggerFactory.Create(builder => { @@ -17,7 +17,8 @@ internal static object Run(LogsOptions options) { opt.IncludeFormattedMessage = true; opt.IncludeScopes = true; - if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase)) + + if ("otlp".Equals(options.UseExporter, StringComparison.OrdinalIgnoreCase)) { /* * Prerequisite to run this example: @@ -43,31 +44,46 @@ internal static object Run(LogsOptions options) var protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc; - if (options.Protocol.Trim().ToLower().Equals("grpc")) - { - protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc; - } - else if (options.Protocol.Trim().ToLower().Equals("http/protobuf")) + if (!string.IsNullOrEmpty(options.Protocol)) { - protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf; + switch (options.Protocol.Trim()) + { + case "grpc": + protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc; + break; + case "http/protobuf": + protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf; + break; + default: + System.Console.WriteLine($"Export protocol {options.Protocol} is not supported. Default protocol 'grpc' will be used."); + break; + } } else { - System.Console.WriteLine($"Export protocol {options.Protocol} is not supported. Default protocol 'grpc' will be used."); + System.Console.WriteLine("Protocol is null or empty. Default protocol 'grpc' will be used."); } var processorType = ExportProcessorType.Batch; - if (options.ProcessorType.Trim().ToLower().Equals("batch")) - { - processorType = ExportProcessorType.Batch; - } - else if (options.ProcessorType.Trim().ToLower().Equals("simple")) + + if (!string.IsNullOrEmpty(options.ProcessorType)) { - processorType = ExportProcessorType.Simple; + switch (options.ProcessorType.Trim()) + { + case "batch": + processorType = ExportProcessorType.Batch; + break; + case "simple": + processorType = ExportProcessorType.Simple; + break; + default: + System.Console.WriteLine($"Export processor type {options.ProcessorType} is not supported. Default processor type 'batch' will be used."); + break; + } } else { - System.Console.WriteLine($"Export processor type {options.ProcessorType} is not supported. Default processor type 'batch' will be used."); + System.Console.WriteLine("Processor type is null or empty. Default processor type 'batch' will be used."); } opt.AddOtlpExporter((exporterOptions, processorOptions) => @@ -103,6 +119,6 @@ internal static object Run(LogsOptions options) logger.LogInformation("Hello from {name} {price}.", "tomato", 2.99); } - return null; + return 0; } } diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index ba943e91775..9582a0f561e 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -12,10 +12,10 @@ namespace Examples.Console; internal class TestMetrics { - internal static object Run(MetricsOptions options) + internal static int Run(MetricsOptions options) { var meterVersion = "1.0"; - var meterTags = new List> + var meterTags = new List> { new( "MeterTagKey", @@ -27,7 +27,7 @@ internal static object Run(MetricsOptions options) .ConfigureResource(r => r.AddService("myservice")) .AddMeter(meter.Name); // All instruments from this meter are enabled. - if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase)) + if ("otlp".Equals(options.UseExporter, StringComparison.OrdinalIgnoreCase)) { /* * Prerequisite to run this example: @@ -79,13 +79,13 @@ internal static object Run(MetricsOptions options) using var provider = providerBuilder.Build(); - Counter counter = null; + Counter? counter = null; if (options.FlagCounter ?? true) { counter = meter.CreateCounter("counter", "things", "A count of things"); } - Histogram histogram = null; + Histogram? histogram = null; if (options.FlagHistogram ?? false) { histogram = meter.CreateHistogram("histogram"); @@ -99,7 +99,7 @@ internal static object Run(MetricsOptions options) { new Measurement( (int)Process.GetCurrentProcess().PrivateMemorySize64, - new KeyValuePair("tag1", "value1")), + new KeyValuePair("tag1", "value1")), }; }); } @@ -111,45 +111,45 @@ internal static object Run(MetricsOptions options) histogram?.Record( 100, - new KeyValuePair("tag1", "value1")); + new KeyValuePair("tag1", "value1")); histogram?.Record( 200, - new KeyValuePair("tag1", "value2"), - new KeyValuePair("tag2", "value2")); + new KeyValuePair("tag1", "value2"), + new KeyValuePair("tag2", "value2")); histogram?.Record( 100, - new KeyValuePair("tag1", "value1")); + new KeyValuePair("tag1", "value1")); histogram?.Record( 200, - new KeyValuePair("tag2", "value2"), - new KeyValuePair("tag1", "value2")); + new KeyValuePair("tag2", "value2"), + new KeyValuePair("tag1", "value2")); counter?.Add(10); counter?.Add( 100, - new KeyValuePair("tag1", "value1")); + new KeyValuePair("tag1", "value1")); counter?.Add( 200, - new KeyValuePair("tag1", "value2"), - new KeyValuePair("tag2", "value2")); + new KeyValuePair("tag1", "value2"), + new KeyValuePair("tag2", "value2")); counter?.Add( 100, - new KeyValuePair("tag1", "value1")); + new KeyValuePair("tag1", "value1")); counter?.Add( 200, - new KeyValuePair("tag2", "value2"), - new KeyValuePair("tag1", "value2")); + new KeyValuePair("tag2", "value2"), + new KeyValuePair("tag1", "value2")); Task.Delay(500).Wait(); } - return null; + return 0; } } diff --git a/examples/Console/TestOTelShimWithConsoleExporter.cs b/examples/Console/TestOTelShimWithConsoleExporter.cs index 6557357a963..42e6f368f54 100644 --- a/examples/Console/TestOTelShimWithConsoleExporter.cs +++ b/examples/Console/TestOTelShimWithConsoleExporter.cs @@ -9,15 +9,15 @@ namespace Examples.Console; internal class TestOTelShimWithConsoleExporter { - internal static object Run(OpenTelemetryShimOptions options) + internal static int Run(OpenTelemetryShimOptions options) { // Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer" // and use a single pipeline with a custom MyProcessor, and Console exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource("MyCompany.MyProduct.MyWebServer") - .ConfigureResource(r => r.AddService("MyServiceName")) - .AddConsoleExporter() - .Build(); + .AddSource("MyCompany.MyProduct.MyWebServer") + .ConfigureResource(r => r.AddService("MyServiceName")) + .AddConsoleExporter() + .Build(); // The above line is required only in applications // which decide to use OpenTelemetry. @@ -40,6 +40,6 @@ internal static object Run(OpenTelemetryShimOptions options) System.Console.WriteLine("Press Enter key to exit."); System.Console.ReadLine(); - return null; + return 0; } } diff --git a/examples/Console/TestOpenTracingShim.cs b/examples/Console/TestOpenTracingShim.cs index 0de2419b6ef..386cfe48ab1 100644 --- a/examples/Console/TestOpenTracingShim.cs +++ b/examples/Console/TestOpenTracingShim.cs @@ -12,15 +12,15 @@ namespace Examples.Console; internal class TestOpenTracingShim { - internal static object Run(OpenTracingShimOptions options) + internal static int Run(OpenTracingShimOptions options) { // Enable OpenTelemetry for the source "opentracing-shim" // and use Console exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource("opentracing-shim") - .ConfigureResource(r => r.AddService("MyServiceName")) - .AddConsoleExporter() - .Build(); + .AddSource("opentracing-shim") + .ConfigureResource(r => r.AddService("MyServiceName")) + .AddConsoleExporter() + .Build(); // Instantiate the OpenTracing shim. The underlying OpenTelemetry tracer will create // spans using the "opentracing-shim" source. @@ -53,6 +53,6 @@ internal static object Run(OpenTracingShimOptions options) System.Console.WriteLine("Press Enter key to exit."); System.Console.ReadLine(); - return null; + return 0; } } diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 94d749eafef..3af0ceea14b 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -10,7 +10,7 @@ namespace Examples.Console; internal static class TestOtlpExporter { - internal static object Run(string endpoint, string protocol) + internal static int Run(OtlpOptions options) { /* * Prerequisite to run this example: @@ -36,36 +36,36 @@ internal static object Run(string endpoint, string protocol) * For more information about the OpenTelemetry Collector go to https://github.com/open-telemetry/opentelemetry-collector * */ - return RunWithActivitySource(endpoint, protocol); + return RunWithActivitySource(options); } - private static object RunWithActivitySource(string endpoint, string protocol) + private static int RunWithActivitySource(OtlpOptions options) { - var otlpExportProtocol = ToOtlpExportProtocol(protocol); + var otlpExportProtocol = ToOtlpExportProtocol(options.Protocol); if (!otlpExportProtocol.HasValue) { - System.Console.WriteLine($"Export protocol {protocol} is not supported. Default protocol 'grpc' will be used."); + System.Console.WriteLine($"Export protocol {options.Protocol} is not supported. Default protocol 'grpc' will be used."); otlpExportProtocol = OtlpExportProtocol.Grpc; } // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use OTLP exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResource(r => r.AddService("otlp-test")) - .AddOtlpExporter(opt => + .AddSource("Samples.SampleClient", "Samples.SampleServer") + .ConfigureResource(r => r.AddService("otlp-test")) + .AddOtlpExporter(opt => + { + // If endpoint was not specified, the proper one will be selected according to the protocol. + if (!string.IsNullOrEmpty(options.Endpoint)) { - // If endpoint was not specified, the proper one will be selected according to the protocol. - if (!string.IsNullOrEmpty(endpoint)) - { - opt.Endpoint = new Uri(endpoint); - } + opt.Endpoint = new Uri(options.Endpoint); + } - opt.Protocol = otlpExportProtocol.Value; + opt.Protocol = otlpExportProtocol.Value; - System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); - }) - .Build(); + System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}"); + }) + .Build(); // The above line is required only in Applications // which decide to use OpenTelemetry. @@ -79,11 +79,11 @@ private static object RunWithActivitySource(string endpoint, string protocol) System.Console.ReadLine(); } - return null; + return 0; } - private static OtlpExportProtocol? ToOtlpExportProtocol(string protocol) => - protocol.Trim().ToLower() switch + private static OtlpExportProtocol? ToOtlpExportProtocol(string? protocol) => + protocol?.Trim().ToLower() switch { "grpc" => OtlpExportProtocol.Grpc, "http/protobuf" => OtlpExportProtocol.HttpProtobuf, diff --git a/examples/Console/TestPrometheusExporter.cs b/examples/Console/TestPrometheusExporter.cs index 57f38c466df..a6bc1888f2b 100644 --- a/examples/Console/TestPrometheusExporter.cs +++ b/examples/Console/TestPrometheusExporter.cs @@ -17,7 +17,7 @@ internal class TestPrometheusExporter private static readonly Histogram MyHistogram = MyMeter.CreateHistogram("myHistogram"); private static readonly ThreadLocal ThreadLocalRandom = new(() => new Random()); - internal static object Run(int port) + internal static int Run(PrometheusOptions options) { /* prometheus.yml example. Adjust port as per actual. @@ -35,7 +35,7 @@ internal static object Run(int port) .AddMeter(MyMeter.Name) .AddMeter(MyMeter2.Name) .AddPrometheusHttpListener( - options => options.UriPrefixes = new string[] { $"http://localhost:{port}/" }) + o => o.UriPrefixes = new string[] { $"http://localhost:{options.Port}/" }) .Build(); var process = Process.GetCurrentProcess(); @@ -57,12 +57,12 @@ internal static object Run(int port) { Counter.Add(9.9, new("name", "apple"), new("color", "red")); Counter.Add(99.9, new("name", "lemon"), new("color", "yellow")); - MyHistogram.Record(ThreadLocalRandom.Value.Next(1, 1500), new("tag1", "value1"), new("tag2", "value2")); + MyHistogram.Record(ThreadLocalRandom.Value!.Next(1, 1500), new("tag1", "value1"), new("tag2", "value2")); Task.Delay(10).Wait(); } }); - System.Console.WriteLine($"PrometheusExporter exposes metrics via http://localhost:{port}/metrics/"); + System.Console.WriteLine($"PrometheusExporter exposes metrics via http://localhost:{options.Port}/metrics/"); System.Console.WriteLine($"Press Esc key to exit..."); while (true) { @@ -80,7 +80,7 @@ internal static object Run(int port) Task.Delay(200).Wait(); } - return null; + return 0; } private static IEnumerable> GetThreadCpuTime(Process process) diff --git a/examples/Console/TestZipkinExporter.cs b/examples/Console/TestZipkinExporter.cs index 271826a7c2b..0bb64323442 100644 --- a/examples/Console/TestZipkinExporter.cs +++ b/examples/Console/TestZipkinExporter.cs @@ -9,7 +9,7 @@ namespace Examples.Console; internal class TestZipkinExporter { - internal static object Run(string zipkinUri) + internal static int Run(ZipkinOptions options) { // Prerequisite for running this example. // Setup zipkin inside local docker using following command: @@ -23,14 +23,15 @@ internal static object Run(string zipkinUri) // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use the Zipkin exporter. + using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResource(r => r.AddService("zipkin-test")) - .AddZipkinExporter(o => - { - o.Endpoint = new Uri(zipkinUri); - }) - .Build(); + .AddSource("Samples.SampleClient", "Samples.SampleServer") + .ConfigureResource(r => r.AddService("zipkin-test")) + .AddZipkinExporter(o => + { + o.Endpoint = new Uri(options.Uri); + }) + .Build(); using (var sample = new InstrumentationWithActivitySource()) { @@ -42,6 +43,6 @@ internal static object Run(string zipkinUri) System.Console.ReadLine(); } - return null; + return 0; } } diff --git a/examples/MicroserviceExample/Utils/Messaging/RabbitMqHelper.cs b/examples/MicroserviceExample/Utils/Messaging/RabbitMqHelper.cs index 476bc26a853..cbc8f0d8344 100644 --- a/examples/MicroserviceExample/Utils/Messaging/RabbitMqHelper.cs +++ b/examples/MicroserviceExample/Utils/Messaging/RabbitMqHelper.cs @@ -54,7 +54,7 @@ public static void StartConsumer(IModel channel, Action p channel.BasicConsume(queue: TestQueueName, autoAck: true, consumer: consumer); } - public static void AddMessagingTags(Activity activity) + public static void AddMessagingTags(Activity? activity) { // These tags are added demonstrating the semantic conventions of the OpenTelemetry messaging specification // See: diff --git a/examples/MicroserviceExample/Utils/Utils.csproj b/examples/MicroserviceExample/Utils/Utils.csproj index cc7382d4995..54d07243470 100644 --- a/examples/MicroserviceExample/Utils/Utils.csproj +++ b/examples/MicroserviceExample/Utils/Utils.csproj @@ -1,9 +1,6 @@ netstandard2.0 - - - disable