From 7139c7a656ad43baff471ef0641c7dc828902c48 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 16 Feb 2023 14:04:45 -0800 Subject: [PATCH 1/6] [Otlp] Make sure Otlp trace and metric exporters have dedicated options instances (#4200) * Make sure Otlp trace and metric exporters have dedicated options instances. * CHANGELOG patch. --- .../CHANGELOG.md | 4 ++++ .../OtlpMetricExporterExtensions.cs | 19 ++++++++++++++----- .../OtlpTraceExporterHelperExtensions.cs | 19 ++++++++++++++----- .../OtlpTraceExporterTests.cs | 13 +++++++------ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index f6822468af9..f4b74cb539f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* `AddOtlpExporter` extension methods will now always create a new options + instance when named options are NOT used. + ([#4200](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4200)) + ## 1.4.0-rc.4 Released 2023-Feb-10 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs index 80979dd38f9..df4f9e5be80 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs @@ -73,16 +73,25 @@ public static MeterProviderBuilder AddOtlpExporter( return builder.AddReader(sp => { - var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + OtlpExporterOptions exporterOptions; - if (name == null && configureExporter != null) + if (name == null) { - // If we are NOT using named options, we execute the - // configuration delegate inline. The reason for this is + // If we are NOT using named options we create a new + // instance always. The reason for this is // OtlpExporterOptions is shared by all signals. Without a // name, delegates for all signals will mix together. See: // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 - configureExporter(exporterOptions); + exporterOptions = sp.GetRequiredService>().Create(finalOptionsName); + + // Configuration delegate is executed inline on the fresh instance. + configureExporter?.Invoke(exporterOptions); + } + else + { + // When using named options we can properly utilize Options + // API to create or reuse an instance. + exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); } return BuildOtlpExporterMetricReader( diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs index 728ce1f503a..31e8cbbfe2f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs @@ -76,16 +76,25 @@ public static TracerProviderBuilder AddOtlpExporter( return builder.AddProcessor(sp => { - var exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); + OtlpExporterOptions exporterOptions; - if (name == null && configure != null) + if (name == null) { - // If we are NOT using named options, we execute the - // configuration delegate inline. The reason for this is + // If we are NOT using named options we create a new + // instance always. The reason for this is // OtlpExporterOptions is shared by all signals. Without a // name, delegates for all signals will mix together. See: // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 - configure(exporterOptions); + exporterOptions = sp.GetRequiredService>().Create(finalOptionsName); + + // Configuration delegate is executed inline on the fresh instance. + configure?.Invoke(exporterOptions); + } + else + { + // When using named options we can properly utilize Options + // API to create or reuse an instance. + exporterOptions = sp.GetRequiredService>().Get(finalOptionsName); } // Note: Not using finalOptionsName here for SdkLimitOptions. diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index dd94e5dc95e..a3003baf8a7 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -641,6 +641,8 @@ public void Null_BatchExportProcessorOptions_SupportedTest() [Fact] public void NonnamedOptionsMutateSharedInstanceTest() { + var testOptionsInstance = new OtlpExporterOptions(); + OtlpExporterOptions tracerOptions = null; OtlpExporterOptions meterOptions = null; @@ -649,11 +651,15 @@ public void NonnamedOptionsMutateSharedInstanceTest() services.AddOpenTelemetry() .WithTracing(builder => builder.AddOtlpExporter(o => { + Assert.Equal(testOptionsInstance.Endpoint, o.Endpoint); + tracerOptions = o; o.Endpoint = new("http://localhost/traces"); })) .WithMetrics(builder => builder.AddOtlpExporter(o => { + Assert.Equal(testOptionsInstance.Endpoint, o.Endpoint); + meterOptions = o; o.Endpoint = new("http://localhost/metrics"); })); @@ -676,12 +682,7 @@ public void NonnamedOptionsMutateSharedInstanceTest() Assert.NotNull(meterOptions); Assert.Equal("http://localhost/metrics", meterOptions.Endpoint.OriginalString); - // Note: tracerOptions & meterOptions are actually the same instance - // in memory and that instance was actually mutated after - // OtlpTraceExporter was created but this is OK because it doesn't - // use the options after ctor. - Assert.True(ReferenceEquals(tracerOptions, meterOptions)); - Assert.Equal("http://localhost/metrics", tracerOptions.Endpoint.OriginalString); + Assert.False(ReferenceEquals(tracerOptions, meterOptions)); } [Fact] From 814206dd216ef31ef1957b2bd9d8b2de2ea3f3db Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 23 Feb 2023 11:18:15 +0530 Subject: [PATCH 2/6] Improve log message written by selfdiagnostics to file. (#4219) --- .../Internal/SelfDiagnosticsConfigRefresher.cs | 6 +++--- .../Internal/SelfDiagnosticsConfigRefresherTest.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs b/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs index 924b044d7a4..5590a8faea2 100644 --- a/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs +++ b/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs @@ -30,7 +30,7 @@ namespace OpenTelemetry.Internal /// internal class SelfDiagnosticsConfigRefresher : IDisposable { - public static readonly byte[] MessageOnNewFile = Encoding.UTF8.GetBytes("Successfully opened file.\n"); + public static readonly byte[] MessageOnNewFile = Encoding.UTF8.GetBytes("If you are seeing this message, it means that the OpenTelemetry SDK has successfully created the log file used to write self-diagnostic logs. This file will be appended with logs as they appear. If you do not see any logs following this line, it means no logs of the configured LogLevel is occurring. You may change the LogLevel to show lower log levels, so that logs of lower severities will be shown.\n"); private const int ConfigurationUpdatePeriodMilliSeconds = 10000; @@ -208,7 +208,7 @@ private void OpenLogFile(string newLogDirectory, int newFileSize) // Because the API [MemoryMappedFile.CreateFromFile][1](the string version) behaves differently on // .NET Framework and .NET Core, here I am using the [FileStream version][2] of it. - // Taking the last four prameter values from [.NET Framework] + // Taking the last four parameter values from [.NET Framework] // (https://referencesource.microsoft.com/#system.core/System/IO/MemoryMappedFiles/MemoryMappedFile.cs,148) // and [.NET Core] // (https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.cs#L152) @@ -263,7 +263,7 @@ private void Dispose(bool disposing) this.cancellationTokenSource.Dispose(); } - // Dispose EventListner before files, because EventListner writes to files. + // Dispose EventListener before files, because EventListener writes to files. if (this.eventListener != null) { this.eventListener.Dispose(); diff --git a/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs b/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs index 5d07c85ad6a..56b55b41f02 100644 --- a/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs +++ b/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs @@ -70,8 +70,9 @@ public void SelfDiagnosticsConfigRefresher_CaptureAsConfigured() // Emitting event of EventLevel.Error OpenTelemetrySdkEventSource.Log.SpanProcessorException("Event string sample", "Exception string sample"); + string expectedMessage = "Unknown error in SpanProcessor event '{0}': '{1}'.{Event string sample}{Exception string sample}"; - int bufferSize = 512; + int bufferSize = 2 * (MessageOnNewFileString.Length + expectedMessage.Length); byte[] actualBytes = ReadFile(bufferSize); string logText = Encoding.UTF8.GetString(actualBytes); Assert.StartsWith(MessageOnNewFileString, logText); @@ -79,7 +80,6 @@ public void SelfDiagnosticsConfigRefresher_CaptureAsConfigured() // The event was captured string logLine = logText.Substring(MessageOnNewFileString.Length); string logMessage = ParseLogMessage(logLine); - string expectedMessage = "Unknown error in SpanProcessor event '{0}': '{1}'.{Event string sample}{Exception string sample}"; Assert.StartsWith(expectedMessage, logMessage); } finally From bdf1e08bd781558508a095ea73611802de57e6e4 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 23 Feb 2023 23:25:46 +0530 Subject: [PATCH 3/6] Updates to OTLP Exporter readme (#4222) --- examples/Console/TestMetrics.cs | 5 - examples/Console/TestOtlpExporter.cs | 5 - .../README.md | 102 +++++++++++------- 3 files changed, 65 insertions(+), 47 deletions(-) diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index 213423e6161..da7e720f775 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -57,11 +57,6 @@ internal static object Run(MetricsOptions options) * */ - // Adding the OtlpExporter creates a GrpcChannel. - // This switch must be set before creating a GrpcChannel when calling an insecure gRPC service. - // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - providerBuilder .AddOtlpExporter((exporterOptions, metricReaderOptions) => { diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 53e6b1a7243..eee1789991d 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -54,11 +54,6 @@ internal static object Run(string endpoint, string protocol) private static object RunWithActivitySource(string endpoint, string protocol) { - // Adding the OtlpExporter creates a GrpcChannel. - // This switch must be set before creating a GrpcChannel when calling an insecure gRPC service. - // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - var otlpExportProtocol = ToOtlpExportProtocol(protocol); if (!otlpExportProtocol.HasValue) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 177f9639443..8b8f60c6d62 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -8,7 +8,8 @@ implementation. ## Prerequisite -* [Get OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) +* An endpoint capable of accepting OTLP, like [OpenTelemetry + Collector](https://opentelemetry.io/docs/collector/) or similar. ## Installation @@ -16,24 +17,79 @@ implementation. dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol ``` +## Enable Trace Exporter + +This exporter provides `AddOtlpExporter()` extension method on `TracerProviderBuilder` +to enable exporting of traces. The following snippet adds the Exporter with default +[configuration](#configuration). + +```csharp +var tracerProvider = Sdk.CreateTracerProviderBuilder() + // rest of config not shown here. + .AddOtlpExporter() + .Build(); +``` + +See the [`TestOtlpExporter.cs`](../../examples/Console/TestOtlpExporter.cs) for +runnable example. + +## Enable Metric Exporter + +This exporter provides `AddOtlpExporter()` extension method on `MeterProviderBuilder` +to enable exporting of metrics. The following snippet adds the Exporter with default +[configuration](#configuration). + +```csharp +var meterProvider = Sdk.CreateMeterProviderBuilder() + // rest of config not shown here. + .AddOtlpExporter() + .Build(); +``` + +See the [`TestMetrics.cs`](../../examples/Console/TestMetrics.cs) for +runnable example. + +## Enable Log Exporter + +This package currently only supports exporting traces and metrics. Support for +exporting logs is provided by installing the +[`OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs`](../OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/README.md) +package. + +Once the OTLP log exporter is stable, it'll be folded into this package. Check +[this](https://github.com/open-telemetry/opentelemetry-dotnet/milestone/35) +milestone for tracking. + ## Configuration -You can configure the `OtlpExporter` through `Options` types properties +You can configure the `OtlpExporter` through `OtlpExporterOptions` and environment variables. -The `Options` type setters take precedence over the environment variables. +The `OtlpExporterOptions` type setters take precedence over the environment variables. -## Options Properties +This can be achieved by providing an `Action` delegate to the +`AddOtlpExporter()` method. -* `BatchExportProcessorOptions`: Configuration options for the batch exporter. - Only used if ExportProcessorType is set to Batch. +TODO: Show metrics specific configuration (i.e MetricReaderOptions). -* `Endpoint`: Target to which the exporter is going to send traces or metrics. - The endpoint must be a valid Uri with scheme (http or https) and host, and MAY - contain a port and path. +## OtlpExporterOptions * `ExportProcessorType`: Whether the exporter should use [Batch or Simple exporting processor](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#built-in-span-processors). + The default is Batch. + +* `BatchExportProcessorOptions`: Configuration options for the batch exporter. + Only used if ExportProcessorType is set to Batch. + +* `Protocol`: OTLP transport protocol. Supported values: + `OtlpExportProtocol.Grpc` and `OtlpExportProtocol.HttpProtobuf`. + The default is `OtlpExportProtocol.Grpc`. + +* `Endpoint`: Target to which the exporter is going to send traces or metrics. + The endpoint must be a valid Uri with scheme (http or https) and host, and MAY + contain a port and path. The default is "localhost:4317" for + `OtlpExportProtocol.Grpc` and "localhost:4318" for + `OtlpExportProtocol.HttpProtobuf`. * `Headers`: Optional headers for the connection. @@ -44,9 +100,6 @@ The `Options` type setters take precedence over the environment variables. * `TimeoutMilliseconds` : Max waiting time for the backend to process a batch. -* `Protocol`: OTLP transport protocol. Supported values: - `OtlpExportProtocol.Grpc` and `OtlpExportProtocol.HttpProtobuf`. - See the [`TestOtlpExporter.cs`](../../examples/Console/TestOtlpExporter.cs) for an example of how to use the exporter. @@ -90,31 +143,6 @@ values of the span limits * `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT` * `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT` -## OTLP Logs - -This package currently only supports exporting traces and metrics. Support for -exporting logs is provided by installing the -[`OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs`](../OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/README.md) -package. - -Once the OTLP log exporter is stable, it'll be folded into this package. Check -[this](https://github.com/open-telemetry/opentelemetry-dotnet/milestone/35) -milestone for tracking. - -## Special case when using insecure channel - -If your application is targeting .NET Core 3.1, and you are using an insecure -(HTTP) endpoint, the following switch must be set before adding `OtlpExporter`. - -```csharp -AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", - true); -``` - -See -[this](https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client) -for more information. - ## Configure HttpClient The `HttpClientFactory` option is provided on `OtlpExporterOptions` for users From 5b1889dd3d4f3c2eda896a6082847fd2af3b5a21 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 23 Feb 2023 12:44:34 -0800 Subject: [PATCH 4/6] [Hosting] Remove obsolete methods ahead of 1.4.0 release (#4071) * Remove obsolete methods from hosting library ahead of 1.4.0 release. * Warning cleanup. * CHANGELOG patch. * Merge fixes. * MD lint fix. * Slim down the changes shown on the diff. * More diff slimming. * CHANGELOG fix. --------- Co-authored-by: Cijo Thomas Co-authored-by: Alan West <3676547+alanwest@users.noreply.github.com> --- .../netstandard2.0/PublicAPI.Unshipped.txt | 11 +-- .../CHANGELOG.md | 4 + .../Metrics/MeterProviderBuilderExtensions.cs | 70 ------------- .../OpenTelemetryServicesExtensions.cs | 98 ------------------- .../Trace/TracerProviderBuilderExtensions.cs | 70 ------------- 5 files changed, 5 insertions(+), 248 deletions(-) delete mode 100644 src/OpenTelemetry.Extensions.Hosting/Metrics/MeterProviderBuilderExtensions.cs delete mode 100644 src/OpenTelemetry.Extensions.Hosting/Trace/TracerProviderBuilderExtensions.cs diff --git a/src/OpenTelemetry.Extensions.Hosting/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.Hosting/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 5e8365829f9..3812863f17c 100644 --- a/src/OpenTelemetry.Extensions.Hosting/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Extensions.Hosting/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,5 +1,4 @@ Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions -OpenTelemetry.Metrics.MeterProviderBuilderExtensions OpenTelemetry.OpenTelemetryBuilder OpenTelemetry.OpenTelemetryBuilder.ConfigureResource(System.Action! configure) -> OpenTelemetry.OpenTelemetryBuilder! OpenTelemetry.OpenTelemetryBuilder.Services.get -> Microsoft.Extensions.DependencyInjection.IServiceCollection! @@ -7,13 +6,5 @@ OpenTelemetry.OpenTelemetryBuilder.WithMetrics() -> OpenTelemetry.OpenTelemetryB OpenTelemetry.OpenTelemetryBuilder.WithMetrics(System.Action! configure) -> OpenTelemetry.OpenTelemetryBuilder! OpenTelemetry.OpenTelemetryBuilder.WithTracing() -> OpenTelemetry.OpenTelemetryBuilder! OpenTelemetry.OpenTelemetryBuilder.WithTracing(System.Action! configure) -> OpenTelemetry.OpenTelemetryBuilder! -OpenTelemetry.Trace.TracerProviderBuilderExtensions static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> OpenTelemetry.OpenTelemetryBuilder! -static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.Configure(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, System.Action! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder! -static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.GetServices(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.Configure(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.GetServices(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! + diff --git a/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md b/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md index 8ab3122a182..480d06e5918 100644 --- a/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md +++ b/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Removed deprecated extensions: `AddOpenTelemetryTracing`, + `AddOpenTelemetryMetrics`, `Configure`, & `GetServices`. + ([#4071](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4071)) + ## 1.4.0-rc.4 Released 2023-Feb-10 diff --git a/src/OpenTelemetry.Extensions.Hosting/Metrics/MeterProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions.Hosting/Metrics/MeterProviderBuilderExtensions.cs deleted file mode 100644 index e2af1280573..00000000000 --- a/src/OpenTelemetry.Extensions.Hosting/Metrics/MeterProviderBuilderExtensions.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using Microsoft.Extensions.DependencyInjection; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Metrics -{ - /// - /// Contains extension methods for the class. - /// - public static class MeterProviderBuilderExtensions - { - /// - /// Register a callback action to configure the once the application is available. - /// - /// . - /// Configuration callback. - /// The supplied for chaining. - [Obsolete("Configure has been replaced by factory extensions. This method will be removed in a future version.")] - public static MeterProviderBuilder Configure(this MeterProviderBuilder meterProviderBuilder, Action configure) - { - if (meterProviderBuilder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder) - { - deferredMeterProviderBuilder.Configure(configure); - } - - return meterProviderBuilder; - } - - /// - /// Gets the application attached to - /// the . - /// - /// . - /// or - /// if services are unavailable. - [Obsolete("Call ConfigureServices instead this method will be removed in a future version.")] - public static IServiceCollection GetServices(this MeterProviderBuilder meterProviderBuilder) - { - Guard.ThrowIfNull(meterProviderBuilder); - - IServiceCollection? services = null; - - meterProviderBuilder.ConfigureServices(s => services = s); - - if (services == null) - { - throw new NotSupportedException($"GetServices is not supported on the '{meterProviderBuilder.GetType()}' builder type."); - } - - return services; - } - } -} diff --git a/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs b/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs index 7ebc142b358..dff14ca1b38 100644 --- a/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs +++ b/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs @@ -52,102 +52,4 @@ public static OpenTelemetryBuilder AddOpenTelemetry(this IServiceCollection serv return new(services); } - - /// - /// Configure OpenTelemetry and register a - /// to automatically start tracing services in the supplied . - /// - /// - /// Notes: - /// - /// - /// This is safe to be called multiple times. Only a single will be created for a given . - /// - /// - /// This method should be called by application host code. Library - /// authors should call - /// instead. - /// - /// - /// - /// . - /// Supplied for chaining - /// calls. - [Obsolete("Use the AddOpenTelemetry().WithTracing(configure) pattern instead. This method will be removed in a future version.")] - public static IServiceCollection AddOpenTelemetryTracing(this IServiceCollection services) - => AddOpenTelemetryTracing(services, b => { }); - - /// - /// Configure OpenTelemetry and register a - /// to automatically start tracing services in the supplied . - /// - /// - /// . - /// Callback action to configure the . - /// Supplied for chaining - /// calls. - [Obsolete("Use the AddOpenTelemetry().WithTracing(configure) pattern instead. This method will be removed in a future version.")] - public static IServiceCollection AddOpenTelemetryTracing(this IServiceCollection services, Action configure) - { - services.AddOpenTelemetry().WithTracing(configure); - - return services; - } - - /// - /// Configure OpenTelemetry and register a - /// to automatically start metric services in the supplied . - /// - /// - /// Notes: - /// - /// - /// This is safe to be called multiple times. Only a single will be created for a given . - /// - /// - /// This method should be called by application host code. Library - /// authors should call - /// instead. - /// - /// - /// - /// . - /// Supplied for chaining - /// calls. - [Obsolete("Use the AddOpenTelemetry().WithMetrics(configure) pattern instead. This method will be removed in a future version.")] - public static IServiceCollection AddOpenTelemetryMetrics(this IServiceCollection services) - => AddOpenTelemetryMetrics(services, b => { }); - - /// - /// Configure OpenTelemetry and register a - /// to automatically start metric services in the supplied . - /// - /// - /// . - /// Callback action to configure the . - /// Supplied for chaining - /// calls. - [Obsolete("Use the AddOpenTelemetry().WithMetrics(configure) pattern instead. This method will be removed in a future version.")] - public static IServiceCollection AddOpenTelemetryMetrics(this IServiceCollection services, Action configure) - { - services.AddOpenTelemetry().WithMetrics(configure); - - return services; - } } diff --git a/src/OpenTelemetry.Extensions.Hosting/Trace/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions.Hosting/Trace/TracerProviderBuilderExtensions.cs deleted file mode 100644 index 55e6629c8a7..00000000000 --- a/src/OpenTelemetry.Extensions.Hosting/Trace/TracerProviderBuilderExtensions.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using Microsoft.Extensions.DependencyInjection; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Trace -{ - /// - /// Contains extension methods for the class. - /// - public static class TracerProviderBuilderExtensions - { - /// - /// Register a callback action to configure the once the application is available. - /// - /// . - /// Configuration callback. - /// The supplied for chaining. - [Obsolete("Configure has been replaced by factory extensions. This method will be removed in a future version.")] - public static TracerProviderBuilder Configure(this TracerProviderBuilder tracerProviderBuilder, Action configure) - { - if (tracerProviderBuilder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder) - { - deferredTracerProviderBuilder.Configure(configure); - } - - return tracerProviderBuilder; - } - - /// - /// Gets the application attached to - /// the . - /// - /// . - /// or - /// if services are unavailable. - [Obsolete("Call ConfigureServices instead this method will be removed in a future version.")] - public static IServiceCollection GetServices(this TracerProviderBuilder tracerProviderBuilder) - { - Guard.ThrowIfNull(tracerProviderBuilder); - - IServiceCollection? services = null; - - tracerProviderBuilder.ConfigureServices(s => services = s); - - if (services == null) - { - throw new NotSupportedException($"GetServices is not supported on the '{tracerProviderBuilder.GetType()}' builder type."); - } - - return services; - } - } -} From 4f2bb57df70b43d627ef4a87b55c1001ea70e6a8 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 23 Feb 2023 13:55:05 -0800 Subject: [PATCH 5/6] Project and README updates for 1.4. (#4223) --- src/OpenTelemetry.Api.ProviderBuilderExtensions/README.md | 2 +- .../Implementation/TelemetryHostedService.cs | 4 ++-- .../OpenTelemetry.Extensions.Hosting.csproj | 8 +++++++- src/OpenTelemetry.Extensions.Hosting/README.md | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/OpenTelemetry.Api.ProviderBuilderExtensions/README.md b/src/OpenTelemetry.Api.ProviderBuilderExtensions/README.md index 5954755a9af..fcd754126b1 100644 --- a/src/OpenTelemetry.Api.ProviderBuilderExtensions/README.md +++ b/src/OpenTelemetry.Api.ProviderBuilderExtensions/README.md @@ -6,7 +6,7 @@ ## Installation ```shell -dotnet add package --prerelease OpenTelemetry.Api.ProviderBuilderExtensions +dotnet add package OpenTelemetry.Api.ProviderBuilderExtensions ``` ## Overview diff --git a/src/OpenTelemetry.Extensions.Hosting/Implementation/TelemetryHostedService.cs b/src/OpenTelemetry.Extensions.Hosting/Implementation/TelemetryHostedService.cs index e0057979b10..3e260c6e41a 100644 --- a/src/OpenTelemetry.Extensions.Hosting/Implementation/TelemetryHostedService.cs +++ b/src/OpenTelemetry.Extensions.Hosting/Implementation/TelemetryHostedService.cs @@ -53,13 +53,13 @@ internal static void Initialize(IServiceProvider serviceProvider) { Debug.Assert(serviceProvider != null, "serviceProvider was null"); - var meterProvider = serviceProvider.GetService(); + var meterProvider = serviceProvider!.GetService(); if (meterProvider == null) { HostingExtensionsEventSource.Log.MeterProviderNotRegistered(); } - var tracerProvider = serviceProvider.GetService(); + var tracerProvider = serviceProvider!.GetService(); if (tracerProvider == null) { HostingExtensionsEventSource.Log.TracerProviderNotRegistered(); diff --git a/src/OpenTelemetry.Extensions.Hosting/OpenTelemetry.Extensions.Hosting.csproj b/src/OpenTelemetry.Extensions.Hosting/OpenTelemetry.Extensions.Hosting.csproj index 21f9aa4b039..cc1b956abf8 100644 --- a/src/OpenTelemetry.Extensions.Hosting/OpenTelemetry.Extensions.Hosting.csproj +++ b/src/OpenTelemetry.Extensions.Hosting/OpenTelemetry.Extensions.Hosting.csproj @@ -1,11 +1,12 @@ + netstandard2.0 Contains extensions to start OpenTelemetry in applications using Microsoft.Extensions.Hosting OpenTelemetry core- - enable + latest-all @@ -15,8 +16,13 @@ + + + + + diff --git a/src/OpenTelemetry.Extensions.Hosting/README.md b/src/OpenTelemetry.Extensions.Hosting/README.md index 7be08606c52..d7e9cedce72 100644 --- a/src/OpenTelemetry.Extensions.Hosting/README.md +++ b/src/OpenTelemetry.Extensions.Hosting/README.md @@ -6,7 +6,7 @@ ## Installation ```shell -dotnet add package --prerelease OpenTelemetry.Extensions.Hosting +dotnet add package OpenTelemetry.Extensions.Hosting ``` ## Overview From 0971088451eb0ec8cef06b852d86cff640e4ec6d Mon Sep 17 00:00:00 2001 From: xiang17 Date: Thu, 23 Feb 2023 15:53:00 -0800 Subject: [PATCH 6/6] Fix CHANGELOG (#4224) --- src/OpenTelemetry/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 8d9b81c2bc0..e4645324677 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -161,6 +161,10 @@ Released 2022-Aug-02 ([#3378](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3378)) * Handle possible exception when initializing the default service name. ([#3405](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3405)) +* Add `ConfigureResource` which can replace SetResourceBuilder more succinctly + in most cases and has greater flexibility (applies to TracerProviderBuilder, + MeterProviderBuilder, OpenTelemetryLoggingOptions). + ([#3307](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3307)) * `LogRecord` instances are now reused to reduce memory pressure ([#3385](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3385)) * Fix exact match of activity source name when `wildcard` is used. @@ -182,10 +186,6 @@ Released 2022-June-1 * Swallow `ObjectDisposedException` in `BatchExportProcessor` and `PeriodicExportingMetricReader`. ([#3291](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3291)) -* Add `ConfigureResource` which can replace SetResourceBuilder more succinctly - in most cases and has greater flexibility (applies to TracerProviderBuilder, - MeterProviderBuilder, OpenTelemetryLoggingOptions). - ([#3307](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3307)) ## 1.3.0-beta.2