diff --git a/OpenTelemetry.sln b/OpenTelemetry.sln index d72c5c82c4d..ec895d0d87a 100644 --- a/OpenTelemetry.sln +++ b/OpenTelemetry.sln @@ -222,16 +222,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "correlation", "docs\logs\co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress.Logs", "test\OpenTelemetry.Tests.Stress.Logs\OpenTelemetry.Tests.Stress.Logs.csproj", "{4298057B-24E0-47B3-BB76-C17E81AF6B39}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.LoggingExtensions", "examples\LoggingExtensions\Examples.LoggingExtensions.csproj", "{F5EFF065-7AF5-4D7D-8038-CC419ABD8777}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Serilog", "src\OpenTelemetry.Extensions.Serilog\OpenTelemetry.Extensions.Serilog.csproj", "{0D85558E-15B9-4251-BDBD-9CB7933B57E2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Serilog.Tests", "test\OpenTelemetry.Extensions.Serilog.Tests\OpenTelemetry.Extensions.Serilog.Tests.csproj", "{6A2C122A-C1CD-4B6B-AE09-2ABB7D3C50CE}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.EventSource", "src\OpenTelemetry.Extensions.EventSource\OpenTelemetry.Extensions.EventSource.csproj", "{7AFB4975-9680-4668-9F5E-C3F0CA41E982}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.EventSource.Tests", "test\OpenTelemetry.Extensions.EventSource.Tests\OpenTelemetry.Extensions.EventSource.Tests.csproj", "{304FCFFF-97DE-484B-8D8C-612C644426E5}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.AspNetCore", "src\OpenTelemetry.Exporter.Prometheus.AspNetCore\OpenTelemetry.Exporter.Prometheus.AspNetCore.csproj", "{921CF401-4C2F-4C6D-A750-0B5DC457C1F1}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.HttpListener", "src\OpenTelemetry.Exporter.Prometheus.HttpListener\OpenTelemetry.Exporter.Prometheus.HttpListener.csproj", "{6B0232B7-5F29-4FB5-B383-1AA02DFE1089}" @@ -462,26 +452,6 @@ Global {4298057B-24E0-47B3-BB76-C17E81AF6B39}.Debug|Any CPU.Build.0 = Debug|Any CPU {4298057B-24E0-47B3-BB76-C17E81AF6B39}.Release|Any CPU.ActiveCfg = Release|Any CPU {4298057B-24E0-47B3-BB76-C17E81AF6B39}.Release|Any CPU.Build.0 = Release|Any CPU - {F5EFF065-7AF5-4D7D-8038-CC419ABD8777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F5EFF065-7AF5-4D7D-8038-CC419ABD8777}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F5EFF065-7AF5-4D7D-8038-CC419ABD8777}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F5EFF065-7AF5-4D7D-8038-CC419ABD8777}.Release|Any CPU.Build.0 = Release|Any CPU - {0D85558E-15B9-4251-BDBD-9CB7933B57E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D85558E-15B9-4251-BDBD-9CB7933B57E2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D85558E-15B9-4251-BDBD-9CB7933B57E2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D85558E-15B9-4251-BDBD-9CB7933B57E2}.Release|Any CPU.Build.0 = Release|Any CPU - {6A2C122A-C1CD-4B6B-AE09-2ABB7D3C50CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6A2C122A-C1CD-4B6B-AE09-2ABB7D3C50CE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6A2C122A-C1CD-4B6B-AE09-2ABB7D3C50CE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6A2C122A-C1CD-4B6B-AE09-2ABB7D3C50CE}.Release|Any CPU.Build.0 = Release|Any CPU - {7AFB4975-9680-4668-9F5E-C3F0CA41E982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7AFB4975-9680-4668-9F5E-C3F0CA41E982}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7AFB4975-9680-4668-9F5E-C3F0CA41E982}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7AFB4975-9680-4668-9F5E-C3F0CA41E982}.Release|Any CPU.Build.0 = Release|Any CPU - {304FCFFF-97DE-484B-8D8C-612C644426E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {304FCFFF-97DE-484B-8D8C-612C644426E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {304FCFFF-97DE-484B-8D8C-612C644426E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {304FCFFF-97DE-484B-8D8C-612C644426E5}.Release|Any CPU.Build.0 = Release|Any CPU {921CF401-4C2F-4C6D-A750-0B5DC457C1F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {921CF401-4C2F-4C6D-A750-0B5DC457C1F1}.Debug|Any CPU.Build.0 = Debug|Any CPU {921CF401-4C2F-4C6D-A750-0B5DC457C1F1}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -541,7 +511,6 @@ Global {41B784AA-3301-4126-AF9F-1D59BD04B0BF} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB} {6C7A1595-36D6-4229-BBB5-5A6B5791791D} = {3862190B-E2C5-418E-AFDC-DB281FB5C705} {9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5} = {3862190B-E2C5-418E-AFDC-DB281FB5C705} - {F5EFF065-7AF5-4D7D-8038-CC419ABD8777} = {E359BB2B-9AEC-497D-B321-7DF2450C3B8E} {5FDAF679-DE5A-4C73-A49B-8ABCF2399229} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/examples/LoggingExtensions/ExampleEventSource.cs b/examples/LoggingExtensions/ExampleEventSource.cs deleted file mode 100644 index 7fa0b8cea95..00000000000 --- a/examples/LoggingExtensions/ExampleEventSource.cs +++ /dev/null @@ -1,33 +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 System.Diagnostics.Tracing; - -namespace Examples.LoggingExtensions; - -[EventSource(Name = EventSourceName)] -internal sealed class ExampleEventSource : EventSource -{ - public const string EventSourceName = "OpenTelemetry-ExampleEventSource"; - - public static ExampleEventSource Log { get; } = new(); - - [Event(1, Message = "Example event written with '{0}' reason", Level = EventLevel.Informational)] - public void ExampleEvent(string reason) - { - this.WriteEvent(1, reason); - } -} diff --git a/examples/LoggingExtensions/Examples.LoggingExtensions.csproj b/examples/LoggingExtensions/Examples.LoggingExtensions.csproj deleted file mode 100644 index 892a652ac78..00000000000 --- a/examples/LoggingExtensions/Examples.LoggingExtensions.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - diff --git a/examples/LoggingExtensions/Program.cs b/examples/LoggingExtensions/Program.cs deleted file mode 100644 index 795398f2966..00000000000 --- a/examples/LoggingExtensions/Program.cs +++ /dev/null @@ -1,55 +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 System.Diagnostics.Tracing; -using Examples.LoggingExtensions; -using OpenTelemetry; -using OpenTelemetry.Logs; -using OpenTelemetry.Resources; -using Serilog; - -var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .SetIncludeFormattedMessage(true) - .ConfigureResource(builder => builder.AddService("Examples.LoggingExtensions")) - .AddConsoleExporter() - .Build(); - -// Creates an OpenTelemetryEventSourceLogEmitter for routing ExampleEventSource -// events into logs -using var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, // <- Events will be written to openTelemetryLoggerProvider - (name) => name == ExampleEventSource.EventSourceName ? EventLevel.Informational : null, - disposeProvider: false); // <- Do not dispose the provider with OpenTelemetryEventSourceLogEmitter since in this case it is shared with Serilog - -// Configure Serilog global logger -Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry( - openTelemetryLoggerProvider, // <- Register OpenTelemetry Serilog sink writing to openTelemetryLoggerProvider - disposeProvider: false) // <- Do not dispose the provider with Serilog since in this case it is shared with OpenTelemetryEventSourceLogEmitter - .CreateLogger(); - -ExampleEventSource.Log.ExampleEvent("Startup complete"); - -// Note: Serilog ForContext API is used to set "CategoryName" on log messages -ILogger programLogger = Log.Logger.ForContext(); - -programLogger.Information("Application started {Greeting} {Location}", "Hello", "World"); - -// Note: For Serilog this call flushes all logs -Log.CloseAndFlush(); - -// Manually dispose OpenTelemetryLoggerProvider since it is being shared -openTelemetryLoggerProvider.Dispose(); diff --git a/examples/LoggingExtensions/README.md b/examples/LoggingExtensions/README.md deleted file mode 100644 index adbb1df5b7c..00000000000 --- a/examples/LoggingExtensions/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# OpenTelemetry Logging Extensions Example - -This project contains examples of the `LogEmitter` API being used to extend -existing logging platforms to write into OpenTelemetry logs. - -* Serilog: Using OpenTelemetry.Extensions.Serilog - -## References - -* [OpenTelemetry Project](https://opentelemetry.io/) diff --git a/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt index 427104a7a52..b9be4c9efb9 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,7 +1,6 @@ override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void *REMOVED*static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions -static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 427104a7a52..b9be4c9efb9 100644 --- a/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Console/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,7 +1,6 @@ override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void *REMOVED*static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions -static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.ConsoleExporterLoggingExtensions.AddConsoleExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporterAndMetricReader) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Metrics.ConsoleExporterMetricsExtensions.AddConsoleExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string name, System.Action configureExporter) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 535977e3b31..bb8c842e3af 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -11,11 +11,6 @@ management ([#3648](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3648)) -* Added overloads which accept a name to the `OpenTelemetryLoggerOptions` - `AddConsoleExporter` extension to allow for more fine-grained options - management - ([#3657](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3657)) - * Added overloads which accept a name to the `TracerProviderBuilder` `AddConsoleExporter` extension to allow for more fine-grained options management diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs index e59788e004f..3754eb089fd 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterLoggingExtensions.cs @@ -15,8 +15,6 @@ // using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Internal; @@ -30,7 +28,7 @@ public static class ConsoleExporterLoggingExtensions /// options to use. /// The instance of to chain the calls. public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions) - => AddConsoleExporter(loggerOptions, name: null, configure: null); + => AddConsoleExporter(loggerOptions, configure: null); /// /// Adds Console exporter with OpenTelemetryLoggerOptions. @@ -39,35 +37,12 @@ public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLo /// Callback action for configuring . /// The instance of to chain the calls. public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action configure) - => AddConsoleExporter(loggerOptions, name: null, configure); - - /// - /// Adds Console exporter with OpenTelemetryLoggerOptions. - /// - /// options to use. - /// Name which is used when retrieving options. - /// Callback action for configuring . - /// The instance of to chain the calls. - public static OpenTelemetryLoggerOptions AddConsoleExporter( - this OpenTelemetryLoggerOptions loggerOptions, - string name, - Action configure) { Guard.ThrowIfNull(loggerOptions); - name ??= Options.DefaultName; - - if (configure != null) - { - loggerOptions.ConfigureServices(services => services.Configure(name, configure)); - } - - return loggerOptions.ConfigureProvider((sp, provider) => - { - var options = sp.GetRequiredService>().Get(name); - - provider.AddProcessor(new SimpleLogRecordExportProcessor(new ConsoleLogRecordExporter(options))); - }); + var options = new ConsoleExporterOptions(); + configure?.Invoke(options); + return loggerOptions.AddProcessor(new SimpleLogRecordExportProcessor(new ConsoleLogRecordExporter(options))); } } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/net462/PublicAPI.Unshipped.txt index 408e03e7470..07a63e57297 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,4 +1,3 @@ OpenTelemetry.Logs.OtlpLogExporterHelperExtensions static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions -static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 408e03e7470..07a63e57297 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,4 +1,3 @@ OpenTelemetry.Logs.OtlpLogExporterHelperExtensions static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions -static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index 408e03e7470..07a63e57297 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,4 +1,3 @@ OpenTelemetry.Logs.OtlpLogExporterHelperExtensions static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions -static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, string name, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions static OpenTelemetry.Logs.OtlpLogExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/CHANGELOG.md index b84dd91f35b..dc3bdd72318 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/CHANGELOG.md @@ -7,10 +7,6 @@ `HttpProtobuf` is configured ([#3640](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3640)) -* Added overloads which accept a name to the `OpenTelemetryLoggerOptions` - `AddOtlpExporter` extension to allow for more fine-grained options management - ([#3652](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3652)) - ## 1.4.0-alpha.2 Released 2022-Aug-18 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/OtlpLogExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/OtlpLogExporterHelperExtensions.cs index 65e0c0a2503..ca2ca82b826 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/OtlpLogExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/OtlpLogExporterHelperExtensions.cs @@ -15,10 +15,7 @@ // using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; -using OpenTelemetry.Internal; namespace OpenTelemetry.Logs { @@ -30,23 +27,11 @@ public static class OtlpLogExporterHelperExtensions /// /// Adds OTLP Exporter as a configuration to the OpenTelemetry ILoggingBuilder. /// - /// + /// /// options to use. /// The instance of to chain the calls. public static OpenTelemetryLoggerOptions AddOtlpExporter(this OpenTelemetryLoggerOptions loggerOptions) - => AddOtlpExporter(loggerOptions, name: null, configure: null); - - /// - /// Adds OTLP Exporter as a configuration to the OpenTelemetry ILoggingBuilder. - /// - /// - /// options to use. - /// Callback action for configuring . - /// The instance of to chain the calls. - public static OpenTelemetryLoggerOptions AddOtlpExporter( - this OpenTelemetryLoggerOptions loggerOptions, - Action configure) - => AddOtlpExporter(loggerOptions, name: null, configure); + => AddOtlpExporter(loggerOptions, configure: null); /// /// Adds OTLP Exporter as a configuration to the OpenTelemetry ILoggingBuilder. @@ -57,59 +42,37 @@ public static OpenTelemetryLoggerOptions AddOtlpExporter( /// langword="true"/>. /// /// options to use. - /// Name which is used when retrieving options. /// Callback action for configuring . /// The instance of to chain the calls. public static OpenTelemetryLoggerOptions AddOtlpExporter( this OpenTelemetryLoggerOptions loggerOptions, - string name, Action configure) - { - Guard.ThrowIfNull(loggerOptions); - - loggerOptions.ParseStateValues = true; + => AddOtlpExporter(loggerOptions, new(), configure); - name ??= Options.DefaultName; - - if (configure != null) - { - loggerOptions.ConfigureServices(services => services.Configure(name, configure)); - } - - return loggerOptions.ConfigureProvider((sp, provider) => - { - var options = sp.GetRequiredService>().Get(name); - - AddOtlpExporter(provider, options, sp); - }); - } - - private static void AddOtlpExporter( - OpenTelemetryLoggerProvider provider, + private static OpenTelemetryLoggerOptions AddOtlpExporter( + OpenTelemetryLoggerOptions loggerOptions, OtlpExporterOptions exporterOptions, - IServiceProvider serviceProvider) + Action configure) { - exporterOptions.TryEnableIHttpClientFactoryIntegration(serviceProvider, "OtlpLogExporter"); + configure?.Invoke(exporterOptions); var otlpExporter = new OtlpLogExporter(exporterOptions); - + loggerOptions.ParseStateValues = true; if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple) { - provider.AddProcessor(new SimpleLogRecordExportProcessor(otlpExporter)); + loggerOptions.AddProcessor(new SimpleLogRecordExportProcessor(otlpExporter)); } else { - // TODO: exporterOptions.BatchExportProcessorOptions is - // BatchExportActivityProcessorOptions which is using tracing - // environment variables. There should probably be a dedicated - // setting for logs using BatchExportLogRecordProcessorOptions - provider.AddProcessor(new BatchLogRecordExportProcessor( + loggerOptions.AddProcessor(new BatchLogRecordExportProcessor( otlpExporter, exporterOptions.BatchExportProcessorOptions.MaxQueueSize, exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds, exporterOptions.BatchExportProcessorOptions.ExporterTimeoutMilliseconds, exporterOptions.BatchExportProcessorOptions.MaxExportBatchSize)); } + + return loggerOptions; } } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 2564f9b7cd7..5a2630438f7 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -123,9 +123,8 @@ services.AddOpenTelemetryTracing((builder) => builder For users using [IHttpClientFactory](https://docs.microsoft.com/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests) -you may also customize the named "OtlpTraceExporter", "OtlpMetricExporter", -and/or "OtlpLogExporter" `HttpClient` using the built-in `AddHttpClient` -extension: +you may also customize the named "OtlpTraceExporter" and/or "OtlpMetricExporter" +`HttpClient` using the built-in `AddHttpClient` extension: ```csharp services.AddHttpClient( diff --git a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.0/PublicAPI.Shipped.txt deleted file mode 100644 index 7dc5c58110b..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.0/PublicAPI.Shipped.txt +++ /dev/null @@ -1 +0,0 @@ -#nullable enable diff --git a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt deleted file mode 100644 index bd136d125a8..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ /dev/null @@ -1,6 +0,0 @@ -#nullable enable -OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter -OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.OpenTelemetryEventSourceLogEmitter(OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, System.Func! shouldListenToFunc, bool disposeProvider = true) -> void -OpenTelemetry.Logs.OpenTelemetryEventSourceLoggerOptionsExtensions -override OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.Dispose() -> void -static OpenTelemetry.Logs.OpenTelemetryEventSourceLoggerOptionsExtensions.AddEventSourceLogEmitter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Func! shouldListenToFunc) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.1/PublicAPI.Shipped.txt b/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.1/PublicAPI.Shipped.txt deleted file mode 100644 index 7dc5c58110b..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.1/PublicAPI.Shipped.txt +++ /dev/null @@ -1 +0,0 @@ -#nullable enable diff --git a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt deleted file mode 100644 index bd136d125a8..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ /dev/null @@ -1,6 +0,0 @@ -#nullable enable -OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter -OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.OpenTelemetryEventSourceLogEmitter(OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, System.Func! shouldListenToFunc, bool disposeProvider = true) -> void -OpenTelemetry.Logs.OpenTelemetryEventSourceLoggerOptionsExtensions -override OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.Dispose() -> void -static OpenTelemetry.Logs.OpenTelemetryEventSourceLoggerOptionsExtensions.AddEventSourceLogEmitter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options, System.Func! shouldListenToFunc) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! diff --git a/src/OpenTelemetry.Extensions.EventSource/AssemblyInfo.cs b/src/OpenTelemetry.Extensions.EventSource/AssemblyInfo.cs deleted file mode 100644 index 1aa11097133..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/AssemblyInfo.cs +++ /dev/null @@ -1,36 +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 System; -using System.Runtime.CompilerServices; - -[assembly: CLSCompliant(false)] -[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.EventSource.Tests" + AssemblyInfo.PublicKey)] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)] - -#if SIGNED -internal static class AssemblyInfo -{ - public const string PublicKey = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010051C1562A090FB0C9F391012A32198B5E5D9A60E9B80FA2D7B434C9E5CCB7259BD606E66F9660676AFC6692B8CDC6793D190904551D2103B7B22FA636DCBB8208839785BA402EA08FC00C8F1500CCEF28BBF599AA64FFB1E1D5DC1BF3420A3777BADFE697856E9D52070A50C3EA5821C80BEF17CA3ACFFA28F89DD413F096F898"; - public const string MoqPublicKey = ", PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; -} -#else -internal static class AssemblyInfo -{ - public const string PublicKey = ""; - public const string MoqPublicKey = ""; -} -#endif diff --git a/src/OpenTelemetry.Extensions.EventSource/CHANGELOG.md b/src/OpenTelemetry.Extensions.EventSource/CHANGELOG.md deleted file mode 100644 index 63bfc986bdc..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog - -## Unreleased - -Initial release. diff --git a/src/OpenTelemetry.Extensions.EventSource/OpenTelemetry.Extensions.EventSource.csproj b/src/OpenTelemetry.Extensions.EventSource/OpenTelemetry.Extensions.EventSource.csproj deleted file mode 100644 index dfc6d2e0a89..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/OpenTelemetry.Extensions.EventSource.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - netstandard2.1;netstandard2.0 - Extensions for using OpenTelemetry with System.Diagnostics.Tracing.EventSource - enable - AllEnabledByDefault - latest - - - - - - - - - - - diff --git a/src/OpenTelemetry.Extensions.EventSource/OpenTelemetryEventSourceLogEmitter.cs b/src/OpenTelemetry.Extensions.EventSource/OpenTelemetryEventSourceLogEmitter.cs deleted file mode 100644 index 58b244ea428..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/OpenTelemetryEventSourceLogEmitter.cs +++ /dev/null @@ -1,224 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.Tracing; -using System.Globalization; -using System.Linq; -using Microsoft.Extensions.Logging; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs -{ - /// - /// Implements an which will convert events into OpenTelemetry logs. - /// - public sealed class OpenTelemetryEventSourceLogEmitter : EventListener - { - private readonly bool includeFormattedMessage; - private readonly OpenTelemetryLoggerProvider openTelemetryLoggerProvider; - private readonly LogEmitter logEmitter; - private readonly object lockObj = new(); - private readonly Func shouldListenToFunc; - private readonly List eventSources = new(); - private readonly List? eventSourcesBeforeConstructor = new(); - private readonly bool disposeProvider; - - /// - /// Initializes a new instance of the class. - /// - /// . - /// Callback function used to decide if - /// events should be captured for a given . Return if no - /// events should be captured. - /// Controls whether or not the supplied - /// will be disposed when - /// the is disposed. Default value: . - public OpenTelemetryEventSourceLogEmitter( - OpenTelemetryLoggerProvider openTelemetryLoggerProvider, - Func shouldListenToFunc, - bool disposeProvider = true) - { - Guard.ThrowIfNull(openTelemetryLoggerProvider); - Guard.ThrowIfNull(shouldListenToFunc); - - this.includeFormattedMessage = openTelemetryLoggerProvider.IncludeFormattedMessage; - this.openTelemetryLoggerProvider = openTelemetryLoggerProvider!; - this.disposeProvider = disposeProvider; - this.shouldListenToFunc = shouldListenToFunc; - - var logEmitter = this.openTelemetryLoggerProvider.CreateEmitter(); - Debug.Assert(logEmitter != null, "logEmitter was null"); - - this.logEmitter = logEmitter!; - - lock (this.lockObj) - { - foreach (EventSource eventSource in this.eventSourcesBeforeConstructor) - { - this.ProcessSource(eventSource); - } - - this.eventSourcesBeforeConstructor = null; - } - } - - /// - public override void Dispose() - { - foreach (EventSource eventSource in this.eventSources) - { - this.DisableEvents(eventSource); - } - - this.eventSources.Clear(); - - if (this.disposeProvider) - { - this.openTelemetryLoggerProvider.Dispose(); - } - - base.Dispose(); - } - -#pragma warning disable CA1062 // Validate arguments of public methods - /// - protected override void OnEventSourceCreated(EventSource eventSource) - { - Debug.Assert(eventSource != null, "EventSource was null."); - - try - { - if (this.eventSourcesBeforeConstructor != null) - { - lock (this.lockObj) - { - if (this.eventSourcesBeforeConstructor != null) - { - this.eventSourcesBeforeConstructor.Add(eventSource!); - return; - } - } - } - - this.ProcessSource(eventSource!); - } - finally - { - base.OnEventSourceCreated(eventSource); - } - } -#pragma warning restore CA1062 // Validate arguments of public methods - -#pragma warning disable CA1062 // Validate arguments of public methods - /// - protected override void OnEventWritten(EventWrittenEventArgs eventData) - { - Debug.Assert(eventData != null, "EventData was null."); - - string? rawMessage = eventData!.Message; - - LogRecordData data = new(Activity.Current) - { -#if NETSTANDARD2_1_OR_GREATER - Timestamp = eventData.TimeStamp, -#endif - EventId = new EventId(eventData.EventId, eventData.EventName), - LogLevel = ConvertEventLevelToLogLevel(eventData.Level), - }; - - LogRecordAttributeList attributes = default; - - attributes.Add("event_source.name", eventData.EventSource.Name); - - if (eventData.ActivityId != Guid.Empty) - { - attributes.Add("event_source.activity_id", eventData.ActivityId); - } - - if (eventData.RelatedActivityId != Guid.Empty) - { - attributes.Add("event_source.related_activity_id", eventData.RelatedActivityId); - } - - int payloadCount = eventData.Payload?.Count ?? 0; - - if (payloadCount > 0 && payloadCount == eventData.PayloadNames?.Count) - { - for (int i = 0; i < payloadCount; i++) - { - string name = eventData.PayloadNames[i]; - - if (!string.IsNullOrEmpty(rawMessage) && !this.includeFormattedMessage) - { - // TODO: This code converts the event message from - // string.Format syntax (eg: "Some message {0} {1}") - // into structured log format (eg: "Some message - // {propertyName1} {propertyName2}") but it is - // expensive. Probably needs a cache. -#if NETSTANDARD2_0 - rawMessage = rawMessage.Replace($"{{{i}}}", $"{{{name}}}"); -#else - rawMessage = rawMessage.Replace($"{{{i}}}", $"{{{name}}}", StringComparison.Ordinal); -#endif - } - - attributes.Add(name, eventData.Payload![i]); - } - } - - if (!string.IsNullOrEmpty(rawMessage) && this.includeFormattedMessage && payloadCount > 0) - { - rawMessage = string.Format(CultureInfo.InvariantCulture, rawMessage, eventData.Payload!.ToArray()); - } - - data.Message = rawMessage; - - this.logEmitter.Emit(in data, in attributes); - } -#pragma warning restore CA1062 // Validate arguments of public methods - - private static LogLevel ConvertEventLevelToLogLevel(EventLevel eventLevel) - { - return eventLevel switch - { - EventLevel.Informational => LogLevel.Information, - EventLevel.Warning => LogLevel.Warning, - EventLevel.Error => LogLevel.Error, - EventLevel.Critical => LogLevel.Critical, - _ => LogLevel.Trace, - }; - } - - private void ProcessSource(EventSource eventSource) - { - EventLevel? eventLevel = this.shouldListenToFunc(eventSource.Name); - - if (eventLevel.HasValue) - { - this.eventSources.Add(eventSource); - this.EnableEvents(eventSource, eventLevel.Value, EventKeywords.All); - } - } - } -} diff --git a/src/OpenTelemetry.Extensions.EventSource/OpenTelemetryEventSourceLoggerOptionsExtensions.cs b/src/OpenTelemetry.Extensions.EventSource/OpenTelemetryEventSourceLoggerOptionsExtensions.cs deleted file mode 100644 index 582e65a5c1e..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/OpenTelemetryEventSourceLoggerOptionsExtensions.cs +++ /dev/null @@ -1,78 +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 System; -using System.Collections.Generic; -using System.Diagnostics.Tracing; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs -{ - /// - /// Contains extension methods for registering OpenTelemetry EventSource utilities into logging services. - /// - public static class OpenTelemetryEventSourceLoggerOptionsExtensions - { - /// - /// Registers an which will convert events into OpenTelemetry logs. - /// - /// . - /// Callback function used to decide if - /// events should be captured for a given . Return if no - /// events should be captured. - /// Supplied for - /// chaining calls. - public static OpenTelemetryLoggerOptions AddEventSourceLogEmitter( - this OpenTelemetryLoggerOptions options, - Func shouldListenToFunc) - { - Guard.ThrowIfNull(options); - Guard.ThrowIfNull(shouldListenToFunc); - - options.ConfigureServices(services => services.TryAddSingleton()); - - options.ConfigureProvider((sp, provider) => - { - var manager = sp.GetRequiredService(); - - manager.Emitters.Add( - new OpenTelemetryEventSourceLogEmitter(provider, shouldListenToFunc, disposeProvider: false)); - }); - - return options; - } - - internal sealed class EventSourceManager : IDisposable - { - public List Emitters { get; } = new(); - - public void Dispose() - { - foreach (var emitter in this.Emitters) - { - emitter.Dispose(); - } - - this.Emitters.Clear(); - } - } - } -} diff --git a/src/OpenTelemetry.Extensions.EventSource/README.md b/src/OpenTelemetry.Extensions.EventSource/README.md deleted file mode 100644 index b88f146a0eb..00000000000 --- a/src/OpenTelemetry.Extensions.EventSource/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# OpenTelemetry.Extensions.EventSource - -[![NuGet](https://img.shields.io/nuget/v/OpenTelemetry.Extensions.EventSource.svg)](https://www.nuget.org/packages/OpenTelemetry.Extensions.EventSource) -[![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.Extensions.EventSource.svg)](https://www.nuget.org/packages/OpenTelemetry.Extensions.EventSource) - -This project contains an -[EventListener](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventlistener) -which can be used to translate events written to an -[EventSource](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventsource) -into OpenTelemetry logs. - -## Installation - -```shell -dotnet add package OpenTelemetry.Extensions.EventSource --prerelease -``` - -## Usage Example - -### Configured using dependency injection - -```csharp -IHost host = Host.CreateDefaultBuilder(args) - .ConfigureLogging(builder => - { - builder.ClearProviders(); - - // Step 1: Configure OpenTelemetry logging... - builder.AddOpenTelemetry(options => - { - options - .ConfigureResource(builder => builder.AddService("MyService")) - .AddConsoleExporter() - // Step 2: Register OpenTelemetryEventSourceLogEmitter to listen to events... - .AddEventSourceLogEmitter((name) => name == MyEventSource.Name ? EventLevel.Informational : null); - }); - }) - .Build(); - - host.Run(); -``` - -### Configured manually - -```csharp -// Step 1: Configure OpenTelemetryLoggerProvider... -var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .ConfigureResource(builder => builder.AddService("MyService")) - .AddConsoleExporter() - .Build(); - -// Step 2: Create OpenTelemetryEventSourceLogEmitter to listen to events... -using var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == MyEventSource.Name ? EventLevel.Informational : null, - disposeProvider: true); -``` - -## References - -* [OpenTelemetry Project](https://opentelemetry.io/) diff --git a/src/OpenTelemetry.Extensions.Serilog/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Extensions.Serilog/.publicApi/netstandard2.0/PublicAPI.Shipped.txt deleted file mode 100644 index 7dc5c58110b..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/.publicApi/netstandard2.0/PublicAPI.Shipped.txt +++ /dev/null @@ -1 +0,0 @@ -#nullable enable diff --git a/src/OpenTelemetry.Extensions.Serilog/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.Serilog/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt deleted file mode 100644 index 87a33a78e05..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ /dev/null @@ -1,3 +0,0 @@ -#nullable enable -Serilog.OpenTelemetrySerilogExtensions -static Serilog.OpenTelemetrySerilogExtensions.OpenTelemetry(this Serilog.Configuration.LoggerSinkConfiguration! loggerConfiguration, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, bool disposeProvider = true) -> Serilog.LoggerConfiguration! diff --git a/src/OpenTelemetry.Extensions.Serilog/AssemblyInfo.cs b/src/OpenTelemetry.Extensions.Serilog/AssemblyInfo.cs deleted file mode 100644 index a51a83d9d1d..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/AssemblyInfo.cs +++ /dev/null @@ -1,35 +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 System; -using System.Runtime.CompilerServices; - -[assembly: CLSCompliant(false)] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)] - -#if SIGNED -internal static class AssemblyInfo -{ - public const string PublicKey = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010051C1562A090FB0C9F391012A32198B5E5D9A60E9B80FA2D7B434C9E5CCB7259BD606E66F9660676AFC6692B8CDC6793D190904551D2103B7B22FA636DCBB8208839785BA402EA08FC00C8F1500CCEF28BBF599AA64FFB1E1D5DC1BF3420A3777BADFE697856E9D52070A50C3EA5821C80BEF17CA3ACFFA28F89DD413F096F898"; - public const string MoqPublicKey = ", PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; -} -#else -internal static class AssemblyInfo -{ - public const string PublicKey = ""; - public const string MoqPublicKey = ""; -} -#endif diff --git a/src/OpenTelemetry.Extensions.Serilog/CHANGELOG.md b/src/OpenTelemetry.Extensions.Serilog/CHANGELOG.md deleted file mode 100644 index 63bfc986bdc..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog - -## Unreleased - -Initial release. diff --git a/src/OpenTelemetry.Extensions.Serilog/OpenTelemetry.Extensions.Serilog.csproj b/src/OpenTelemetry.Extensions.Serilog/OpenTelemetry.Extensions.Serilog.csproj deleted file mode 100644 index 993c4cb4811..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/OpenTelemetry.Extensions.Serilog.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - netstandard2.0 - Extensions to enable OpenTelemetry logging when using the Serilog library - $(PackageTags);serilog;logging - enable - AllEnabledByDefault - latest - - - - - - - - - - - - - - - diff --git a/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogExtensions.cs b/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogExtensions.cs deleted file mode 100644 index cf5262f00cd..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogExtensions.cs +++ /dev/null @@ -1,54 +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 OpenTelemetry.Internal; -using OpenTelemetry.Logs; -using Serilog.Configuration; - -namespace Serilog -{ - /// - /// Contains Serilog extension methods. - /// - public static class OpenTelemetrySerilogExtensions - { - /// - /// Adds a sink to Serilog which will - /// write to OpenTelemetry. - /// - /// . - /// . - /// Controls whether or not the supplied - /// will be disposed when - /// the logger is disposed. Default value: . - /// Supplied for chaining calls. - public static LoggerConfiguration OpenTelemetry( - this LoggerSinkConfiguration loggerConfiguration, - OpenTelemetryLoggerProvider openTelemetryLoggerProvider, - bool disposeProvider = true) - { - Guard.ThrowIfNull(loggerConfiguration); - Guard.ThrowIfNull(openTelemetryLoggerProvider); - -#pragma warning disable CA2000 // Dispose objects before losing scope - return loggerConfiguration.Sink(new OpenTelemetrySerilogSink(openTelemetryLoggerProvider, disposeProvider)); -#pragma warning restore CA2000 // Dispose objects before losing scope - } - } -} diff --git a/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogSink.cs b/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogSink.cs deleted file mode 100644 index 49e86653277..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogSink.cs +++ /dev/null @@ -1,135 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.Extensions.Logging; -using Serilog.Core; -using Serilog.Events; - -namespace OpenTelemetry.Logs -{ - internal sealed class OpenTelemetrySerilogSink : ILogEventSink, IDisposable - { - private readonly OpenTelemetryLoggerProvider openTelemetryLoggerProvider; - private readonly bool includeFormattedMessage; - private readonly LogEmitter logEmitter; - private readonly bool disposeProvider; - - public OpenTelemetrySerilogSink(OpenTelemetryLoggerProvider openTelemetryLoggerProvider, bool disposeProvider) - { - Debug.Assert(openTelemetryLoggerProvider != null, "openTelemetryLoggerProvider was null"); - - this.openTelemetryLoggerProvider = openTelemetryLoggerProvider!; - this.disposeProvider = disposeProvider; - - var logEmitter = this.openTelemetryLoggerProvider.CreateEmitter(); - Debug.Assert(logEmitter != null, "logEmitter was null"); - - this.logEmitter = logEmitter!; - - // TODO: This project can only access IncludeFormattedMessage - // because it can see SDK internals. At some point this is likely - // not to be the case. Need to figure out where to put - // IncludeFormattedMessage so that extensions can see it. Ideas: - // Make it public on OpenTelemetryLoggerProvider or expose it on - // LogEmitter instance. - this.includeFormattedMessage = this.openTelemetryLoggerProvider.IncludeFormattedMessage; - } - - public void Emit(LogEvent logEvent) - { - Debug.Assert(logEvent != null, "LogEvent was null."); - - LogRecordData data = new(Activity.Current) - { - Timestamp = logEvent!.Timestamp.UtcDateTime, - LogLevel = (LogLevel)(int)logEvent.Level, - Message = this.includeFormattedMessage ? logEvent.RenderMessage() : logEvent.MessageTemplate.Text, - Exception = logEvent.Exception, - }; - - LogRecordAttributeList attributes = default; - foreach (KeyValuePair property in logEvent.Properties) - { - // TODO: Serilog supports complex type logging. This is not yet - // supported in OpenTelemetry. - if (property.Key == Constants.SourceContextPropertyName - && property.Value is ScalarValue sourceContextValue) - { - data.CategoryName = sourceContextValue.Value as string; - } - else if (property.Value is ScalarValue scalarValue) - { - attributes.Add(property.Key, scalarValue.Value); - } - else if (property.Value is SequenceValue sequenceValue) - { - IReadOnlyList elements = sequenceValue.Elements; - if (elements.Count > 0) - { - // Note: The goal here is to build a typed array (eg - // int[]) if all the element types match otherwise - // fallback to object[] - - Type? elementType = null; - Array? values = null; - - for (int i = 0; i < elements.Count; i++) - { - if (elements[i] is ScalarValue value) - { - Type currentElementType = value.Value?.GetType() ?? typeof(object); - - if (values == null) - { - elementType = currentElementType; - values = Array.CreateInstance(elementType, elements.Count); - } - else if (!elementType!.IsAssignableFrom(currentElementType)) - { - // Array with mixed types detected - object[] newValues = new object[elements.Count]; - values.CopyTo(newValues, 0); - values = newValues; - elementType = typeof(object); - } - - values.SetValue(value.Value, i); - } - } - - if (values != null) - { - attributes.Add(property.Key, values); - } - } - } - } - - this.logEmitter.Emit(in data, in attributes); - } - - public void Dispose() - { - if (this.disposeProvider) - { - this.openTelemetryLoggerProvider.Dispose(); - } - } - } -} diff --git a/src/OpenTelemetry.Extensions.Serilog/README.md b/src/OpenTelemetry.Extensions.Serilog/README.md deleted file mode 100644 index 2d0c837bfbb..00000000000 --- a/src/OpenTelemetry.Extensions.Serilog/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# OpenTelemetry.Extensions.Serilog - -[![NuGet](https://img.shields.io/nuget/v/OpenTelemetry.Extensions.Serilog.svg)](https://www.nuget.org/packages/OpenTelemetry.Extensions.Serilog) -[![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.Extensions.Serilog.svg)](https://www.nuget.org/packages/OpenTelemetry.Extensions.Serilog) - -This project contains a [Serilog](https://github.com/serilog/) -[sink](https://github.com/serilog/serilog/wiki/Configuration-Basics#sinks) for -writing log messages to OpenTelemetry. - -## Installation - -```shell -dotnet add package OpenTelemetry.Extensions.Serilog --prerelease -``` - -## Usage Example - -```csharp -// Step 1: Configure OpenTelemetryLoggerProvider... -var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .ConfigureResource(builder => builder.AddService("MyService")) - .AddConsoleExporter() - .Build(); - -// Step 2: Register OpenTelemetry sink with Serilog... -Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - -// Step 3: When application is shutdown flush all log messages and dispose provider... -Log.CloseAndFlush(); -``` - -## References - -* [OpenTelemetry Project](https://opentelemetry.io/) diff --git a/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt index c9fd94087df..bf3ab6eedd6 100644 --- a/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,13 +1,5 @@ Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions.BatchExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.get -> OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions! -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.set -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.set -> void OpenTelemetry.Logs.LogRecord.CategoryName.set -> void OpenTelemetry.Logs.LogRecord.EventId.set -> void OpenTelemetry.Logs.LogRecord.Exception.set -> void @@ -17,23 +9,7 @@ OpenTelemetry.Logs.LogRecord.Timestamp.set -> void OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void OpenTelemetry.Logs.LogRecord.TraceId.set -> void OpenTelemetry.Logs.LogRecord.TraceState.set -> void -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureResource(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureServices(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeFormattedMessage(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeScopes(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetParseStateValues(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.AddProcessor(OpenTelemetry.BaseProcessor! processor) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder! @@ -53,8 +29,6 @@ OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportActivityProcessorOption OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.set -> void static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, bool disposeProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, System.Action? configure) -> Microsoft.Extensions.Logging.ILoggingBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! @@ -65,8 +39,6 @@ static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddProcessor(this static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureBuilder(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureServices(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetSampler(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder! -static OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions.Build(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -static OpenTelemetry.Sdk.CreateLoggerProviderBuilder() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, System.Action! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder! diff --git a/src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt index c9fd94087df..bf3ab6eedd6 100644 --- a/src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -1,13 +1,5 @@ Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions.BatchExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.get -> OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions! -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.set -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.set -> void OpenTelemetry.Logs.LogRecord.CategoryName.set -> void OpenTelemetry.Logs.LogRecord.EventId.set -> void OpenTelemetry.Logs.LogRecord.Exception.set -> void @@ -17,23 +9,7 @@ OpenTelemetry.Logs.LogRecord.Timestamp.set -> void OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void OpenTelemetry.Logs.LogRecord.TraceId.set -> void OpenTelemetry.Logs.LogRecord.TraceState.set -> void -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureResource(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureServices(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeFormattedMessage(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeScopes(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetParseStateValues(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.AddProcessor(OpenTelemetry.BaseProcessor! processor) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder! @@ -53,8 +29,6 @@ OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportActivityProcessorOption OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.set -> void static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, bool disposeProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, System.Action? configure) -> Microsoft.Extensions.Logging.ILoggingBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! @@ -65,8 +39,6 @@ static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddProcessor(this static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureBuilder(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureServices(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetSampler(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder! -static OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions.Build(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -static OpenTelemetry.Sdk.CreateLoggerProviderBuilder() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, System.Action! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder! diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 171b82d8e49..bf3ab6eedd6 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,13 +1,5 @@ Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions.BatchExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.get -> OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions! -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.set -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.set -> void OpenTelemetry.Logs.LogRecord.CategoryName.set -> void OpenTelemetry.Logs.LogRecord.EventId.set -> void OpenTelemetry.Logs.LogRecord.Exception.set -> void @@ -17,22 +9,6 @@ OpenTelemetry.Logs.LogRecord.Timestamp.set -> void OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void OpenTelemetry.Logs.LogRecord.TraceId.set -> void OpenTelemetry.Logs.LogRecord.TraceState.set -> void -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureServices(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeFormattedMessage(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeScopes(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetParseStateValues(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.AddProcessor(OpenTelemetry.BaseProcessor! processor) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureResource(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! @@ -53,8 +29,6 @@ OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportActivityProcessorOption OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.set -> void static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, bool disposeProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, System.Action? configure) -> Microsoft.Extensions.Logging.ILoggingBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! @@ -65,8 +39,6 @@ static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddProcessor(this static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureBuilder(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureServices(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetSampler(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder! -static OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions.Build(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -static OpenTelemetry.Sdk.CreateLoggerProviderBuilder() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, System.Action! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder! diff --git a/src/OpenTelemetry/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index c9fd94087df..bf3ab6eedd6 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -1,13 +1,5 @@ Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions -OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions.BatchExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.get -> OpenTelemetry.Logs.BatchExportLogRecordProcessorOptions! -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.BatchExportProcessorOptions.set -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportLogRecordProcessorOptions() -> void -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType -OpenTelemetry.Logs.ExportLogRecordProcessorOptions.ExportProcessorType.set -> void OpenTelemetry.Logs.LogRecord.CategoryName.set -> void OpenTelemetry.Logs.LogRecord.EventId.set -> void OpenTelemetry.Logs.LogRecord.Exception.set -> void @@ -17,23 +9,7 @@ OpenTelemetry.Logs.LogRecord.Timestamp.set -> void OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void OpenTelemetry.Logs.LogRecord.TraceId.set -> void OpenTelemetry.Logs.LogRecord.TraceState.set -> void -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureResource(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureServices(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeFormattedMessage(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetIncludeScopes(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptions.SetParseStateValues(bool enabled) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! -OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.AddProcessor(OpenTelemetry.BaseProcessor! processor) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool -OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder) -> OpenTelemetry.Metrics.MeterProviderBuilder! @@ -53,8 +29,6 @@ OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportActivityProcessorOption OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType OpenTelemetry.Trace.ExportActivityProcessorOptions.ExportProcessorType.set -> void static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! -static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, bool disposeProvider) -> Microsoft.Extensions.Logging.ILoggingBuilder! static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder! builder, System.Action? configure) -> Microsoft.Extensions.Logging.ILoggingBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddExporter(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter! exporter, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! @@ -65,8 +39,6 @@ static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddProcessor(this static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureBuilder(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureServices(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action! configure) -> OpenTelemetry.Trace.TracerProviderBuilder! static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetSampler(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder) -> OpenTelemetry.Trace.TracerProviderBuilder! -static OpenTelemetry.Logs.OpenTelemetryLoggerOptionsExtensions.Build(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! options) -> OpenTelemetry.Logs.OpenTelemetryLoggerProvider! -static OpenTelemetry.Sdk.CreateLoggerProviderBuilder() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, System.Action! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder! diff --git a/src/OpenTelemetry/AssemblyInfo.cs b/src/OpenTelemetry/AssemblyInfo.cs index f7c3848454b..df20a883c37 100644 --- a/src/OpenTelemetry/AssemblyInfo.cs +++ b/src/OpenTelemetry/AssemblyInfo.cs @@ -18,13 +18,11 @@ [assembly: InternalsVisibleTo("OpenTelemetry.Tests" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.InMemory" + AssemblyInfo.PublicKey)] -[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.EventSource" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.Shared" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.AspNetCore" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.HttpListener" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.HttpListener.Tests" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting.Tests" + AssemblyInfo.PublicKey)] -[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Serilog" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)] [assembly: InternalsVisibleTo("Benchmarks" + AssemblyInfo.PublicKey)] diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 2f972e92228..a284a1bedc5 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -11,14 +11,13 @@ * Added support for `UpDownCounter` and `ObservableUpDownCounter` instruments. ([#3606](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3606)) -* Added `AddExporter` `OpenTelemetryLoggerOptions` methods and further refined - the `OpenTelemetryLoggerProvider` dependency injection scenarios - ([#3596](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3596)) - * Added support for dependency injection scenarios when configuring `MeterProvider` ([#3646](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3646)) +* Revert new logging APIs pending OTel specification changes + ([#3702](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3702)) + ## 1.4.0-alpha.2 Released 2022-Aug-18 diff --git a/src/OpenTelemetry/Logs/BatchExportLogRecordProcessorOptions.cs b/src/OpenTelemetry/Logs/BatchExportLogRecordProcessorOptions.cs deleted file mode 100644 index f0a30da0d5e..00000000000 --- a/src/OpenTelemetry/Logs/BatchExportLogRecordProcessorOptions.cs +++ /dev/null @@ -1,75 +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 System; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs -{ - /// - /// Batch log processor options. OTEL_DOTNET_BLP_MAX_QUEUE_SIZE, - /// OTEL_DOTNET_BLP_MAX_EXPORT_BATCH_SIZE, OTEL_DOTNET_BLP_EXPORT_TIMEOUT, - /// OTEL_DOTNET_BLP_SCHEDULE_DELAY environment variables are parsed during - /// object construction. - /// - /// - /// Notes: - /// - /// The constructor throws if it fails - /// to parse any of the supported environment variables. - /// The environment variable keys are currently experimental and - /// subject to change. See: OpenTelemetry - /// Environment Variable Specification. - /// - /// - /// - public class BatchExportLogRecordProcessorOptions : BatchExportProcessorOptions - { - internal const string MaxQueueSizeEnvVarKey = "OTEL_DOTNET_BLP_MAX_QUEUE_SIZE"; - - internal const string MaxExportBatchSizeEnvVarKey = "OTEL_DOTNET_BLP_MAX_EXPORT_BATCH_SIZE"; - - internal const string ExporterTimeoutEnvVarKey = "OTEL_DOTNET_BLP_EXPORT_TIMEOUT"; - - internal const string ScheduledDelayEnvVarKey = "OTEL_DOTNET_BLP_SCHEDULE_DELAY"; - - public BatchExportLogRecordProcessorOptions() - { - int value; - - if (EnvironmentVariableHelper.LoadNumeric(ExporterTimeoutEnvVarKey, out value)) - { - this.ExporterTimeoutMilliseconds = value; - } - - if (EnvironmentVariableHelper.LoadNumeric(MaxExportBatchSizeEnvVarKey, out value)) - { - this.MaxExportBatchSize = value; - } - - if (EnvironmentVariableHelper.LoadNumeric(MaxQueueSizeEnvVarKey, out value)) - { - this.MaxQueueSize = value; - } - - if (EnvironmentVariableHelper.LoadNumeric(ScheduledDelayEnvVarKey, out value)) - { - this.ScheduledDelayMilliseconds = value; - } - } - } -} diff --git a/src/OpenTelemetry/Logs/ExportLogRecordProcessorOptions.cs b/src/OpenTelemetry/Logs/ExportLogRecordProcessorOptions.cs deleted file mode 100644 index 0915997de27..00000000000 --- a/src/OpenTelemetry/Logs/ExportLogRecordProcessorOptions.cs +++ /dev/null @@ -1,45 +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. -// - -#nullable enable - -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs; - -public class ExportLogRecordProcessorOptions -{ - private BatchExportLogRecordProcessorOptions? batchExportProcessorOptions; - - /// - /// Gets or sets the export processor type to be used. The default value is . - /// - public ExportProcessorType ExportProcessorType { get; set; } - - /// - /// Gets or sets the batch export options. Ignored unless is . - /// - public BatchExportLogRecordProcessorOptions BatchExportProcessorOptions - { - get => this.batchExportProcessorOptions ??= new(); - set - { - Guard.ThrowIfNull(value); - - this.batchExportProcessorOptions = value; - } - } -} diff --git a/src/OpenTelemetry/Logs/LogEmitter.cs b/src/OpenTelemetry/Logs/LogEmitter.cs deleted file mode 100644 index 49e63360496..00000000000 --- a/src/OpenTelemetry/Logs/LogEmitter.cs +++ /dev/null @@ -1,67 +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. -// - -#nullable enable - -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs -{ - /// - /// LogEmitter implementation. - /// - /// - /// Spec reference: LogEmitter. - /// - internal sealed class LogEmitter - { - private readonly OpenTelemetryLoggerProvider loggerProvider; - - internal LogEmitter(OpenTelemetryLoggerProvider loggerProvider) - { - Guard.ThrowIfNull(loggerProvider); - - this.loggerProvider = loggerProvider; - } - - /// - /// Emit a . - /// - /// . - /// . - public void Emit(in LogRecordData data, in LogRecordAttributeList attributes = default) - { - var provider = this.loggerProvider; - var processor = provider.Processor; - if (processor != null) - { - var pool = provider.LogRecordPool; - - var logRecord = pool.Rent(); - - logRecord.Data = data; - - attributes.ApplyToLogRecord(logRecord); - - processor.OnEnd(logRecord); - - // Attempt to return the LogRecord to the pool. This will no-op - // if a batch exporter has added a reference. - pool.Return(logRecord); - } - } - } -} diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs index 7b050b5aa3b..2d52d20399f 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs @@ -18,10 +18,8 @@ using System; using System.Collections; -using System.Diagnostics; using System.Text; using System.Threading; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OpenTelemetry.Internal; @@ -39,9 +37,7 @@ public class OpenTelemetryLoggerProvider : BaseProvider, ILoggerProvider, ISuppo internal readonly bool IncludeFormattedMessage; internal readonly bool ParseStateValues; internal BaseProcessor? Processor; - internal ResourceBuilder? ResourceBuilder; internal Resource Resource; - private readonly ServiceProvider? ownedServiceProvider; private readonly Hashtable loggers = new(); private ILogRecordPool? threadStaticPool = LogRecordThreadStaticPool.Instance; private bool disposed; @@ -57,21 +53,22 @@ static OpenTelemetryLoggerProvider() /// Initializes a new instance of the class. /// /// . - [Obsolete("Use the Sdk.CreateLoggerProviderBuilder method instead")] public OpenTelemetryLoggerProvider(IOptionsMonitor options) - : this(options?.CurrentValue ?? throw new ArgumentNullException(nameof(options)), serviceProvider: null, ownsServiceProvider: false) + : this(options?.CurrentValue ?? throw new ArgumentNullException(nameof(options))) { } - /// - /// Initializes a new instance of the class. - /// - public OpenTelemetryLoggerProvider() - : this(new(), serviceProvider: null, ownsServiceProvider: false) + internal OpenTelemetryLoggerProvider() + : this(new OpenTelemetryLoggerOptions()) + { + } + + internal OpenTelemetryLoggerProvider(Action configure) + : this(BuildOptions(configure)) { } - internal OpenTelemetryLoggerProvider(OpenTelemetryLoggerOptions options, IServiceProvider? serviceProvider, bool ownsServiceProvider) + internal OpenTelemetryLoggerProvider(OpenTelemetryLoggerOptions options) { OpenTelemetrySdkEventSource.Log.OpenTelemetryLoggerProviderEvent("Building OpenTelemetryLoggerProvider."); @@ -81,37 +78,13 @@ internal OpenTelemetryLoggerProvider(OpenTelemetryLoggerOptions options, IServic this.IncludeFormattedMessage = options.IncludeFormattedMessage; this.ParseStateValues = options.ParseStateValues; - if (ownsServiceProvider) - { - this.ownedServiceProvider = serviceProvider as ServiceProvider; - - Debug.Assert(this.ownedServiceProvider != null, "ownedServiceProvider was null"); - } + this.Resource = options.ResourceBuilder.Build(); - this.ResourceBuilder ??= ResourceBuilder.CreateDefault(); - - var configurationActions = options.ConfigurationActions; - if (configurationActions?.Count > 0) + foreach (var processor in options.Processors) { - if (serviceProvider == null) - { - throw new InvalidOperationException("Configuration actions were registered on options but no service provider was supplied."); - } - - // Note: Not using a foreach loop because additional actions can be - // added during each call. - for (int i = 0; i < configurationActions.Count; i++) - { - configurationActions[i](serviceProvider, this); - } - - OpenTelemetrySdkEventSource.Log.OpenTelemetryLoggerProviderEvent($"Number of actions configured = {configurationActions.Count}."); - options.ConfigurationActions = null; + this.AddProcessor(processor); } - this.Resource = this.ResourceBuilder.Build(); - this.ResourceBuilder = null; - OpenTelemetrySdkEventSource.Log.OpenTelemetryLoggerProviderEvent("OpenTelemetryLoggerProvider built successfully."); } @@ -177,7 +150,7 @@ public ILogger CreateLogger(string categoryName) /// /// This function guarantees thread-safety. /// - public bool ForceFlush(int timeoutMilliseconds = Timeout.Infinite) + internal bool ForceFlush(int timeoutMilliseconds = Timeout.Infinite) { OpenTelemetrySdkEventSource.Log.OpenTelemetryLoggerProviderForceFlushInvoked(timeoutMilliseconds); return this.Processor?.ForceFlush(timeoutMilliseconds) ?? true; @@ -193,7 +166,7 @@ public bool ForceFlush(int timeoutMilliseconds = Timeout.Infinite) /// /// Log processor to add. /// The supplied for chaining. - public OpenTelemetryLoggerProvider AddProcessor(BaseProcessor processor) + internal OpenTelemetryLoggerProvider AddProcessor(BaseProcessor processor) { OpenTelemetrySdkEventSource.Log.OpenTelemetryLoggerProviderEvent("Started adding processor."); @@ -246,12 +219,6 @@ public OpenTelemetryLoggerProvider AddProcessor(BaseProcessor process return this; } - /// - /// Create a . - /// - /// . - internal LogEmitter CreateEmitter() => new(this); - internal bool ContainsBatchProcessor(BaseProcessor processor) { if (processor is BatchExportProcessor) @@ -285,8 +252,6 @@ protected override void Dispose(bool disposing) // Wait for up to 5 seconds grace period this.Processor?.Shutdown(5000); this.Processor?.Dispose(); - - this.ownedServiceProvider?.Dispose(); } this.disposed = true; @@ -295,5 +260,12 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } + + private static OpenTelemetryLoggerOptions BuildOptions(Action configure) + { + var options = new OpenTelemetryLoggerOptions(); + configure?.Invoke(options); + return options; + } } } diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs index 2107b04286d..9a2f8607749 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs @@ -21,7 +21,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Configuration; -using Microsoft.Extensions.Options; using OpenTelemetry.Internal; using OpenTelemetry.Logs; @@ -58,107 +57,14 @@ public static ILoggingBuilder AddOpenTelemetry(this ILoggingBuilder builder, Act builder.AddConfiguration(); - builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton(sp => - { - var finalOptions = sp.GetRequiredService>().CurrentValue; - - return new OpenTelemetryLoggerProvider(finalOptions, sp, ownsServiceProvider: false); - })); + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); // Note: This will bind logger options element (eg "Logging:OpenTelemetry") to OpenTelemetryLoggerOptions LoggerProviderOptions.RegisterProviderOptions(builder.Services); if (configure != null) { - /* - * We do a two-phase configuration here. - * - * Step 1: Configure callback is first invoked immediately. This - * is to make "Services" available for extension authors to - * register additional dependencies into the collection if - * needed. - */ - - var options = new OpenTelemetryLoggerOptions(builder.Services); - - configure(options); - - /* - * Step 2: When ServiceProvider is built from "Services" and the - * LoggerFactory is created then the options pipeline runs and - * builds a new OpenTelemetryLoggerOptions from configuration - * and callbacks are executed. "Services" can no longer be - * modified in this phase because the ServiceProvider is already - * complete. We apply the inline options to the final instance - * to bridge this gap. - */ - - builder.Services.Configure(finalOptions => - { - options.ApplyTo(finalOptions); - }); - } - - return builder; - } - - /// - /// Adds an OpenTelemetry logger named 'OpenTelemetry' to the . - /// - /// - /// Notes: - /// - /// - /// The supplied will - /// automatically be disposed when the - /// built from is disposed. - /// - /// - /// Only a single can be - /// registered for a given . Additional - /// calls to this method will be ignored. - /// - /// - /// - /// The to use. - /// . - /// The supplied for call chaining. - public static ILoggingBuilder AddOpenTelemetry(this ILoggingBuilder builder, OpenTelemetryLoggerProvider openTelemetryLoggerProvider) - => AddOpenTelemetry(builder, openTelemetryLoggerProvider, disposeProvider: true); - - /// - /// Adds an OpenTelemetry logger named 'OpenTelemetry' to the . - /// - /// - /// Note: Only a single can be - /// registered for a given . Additional - /// calls to this method will be ignored. - /// - /// The to use. - /// . - /// Controls whether or not the supplied - /// will be disposed when - /// the is disposed. - /// The supplied for call chaining. - public static ILoggingBuilder AddOpenTelemetry( - this ILoggingBuilder builder, - OpenTelemetryLoggerProvider openTelemetryLoggerProvider, - bool disposeProvider) - { - Guard.ThrowIfNull(builder); - Guard.ThrowIfNull(openTelemetryLoggerProvider); - - // Note: Currently if multiple OpenTelemetryLoggerProvider instances - // are added to the same ILoggingBuilder everything after the first - // is silently ignored. - - if (disposeProvider) - { - builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton(sp => openTelemetryLoggerProvider)); - } - else - { - builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton(openTelemetryLoggerProvider)); + builder.Services.Configure(configure); } return builder; diff --git a/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptions.cs b/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptions.cs index 265e79e7fa4..022df5c1175 100644 --- a/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptions.cs +++ b/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptions.cs @@ -18,10 +18,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; using OpenTelemetry.Internal; using OpenTelemetry.Resources; @@ -32,51 +28,22 @@ namespace OpenTelemetry.Logs /// public class OpenTelemetryLoggerOptions { - internal List>? ConfigurationActions = new(); - - private const bool DefaultIncludeScopes = false; - private const bool DefaultIncludeFormattedMessage = false; - private const bool DefaultParseStateValues = false; - - private IServiceCollection? services; - private bool? includeScopes; - private bool? includeFormattedMessage; - private bool? parseStateValues; - - /// - /// Initializes a new instance of the class. - /// - public OpenTelemetryLoggerOptions() - : this(services: null) - { - } - - internal OpenTelemetryLoggerOptions(IServiceCollection? services) - { - this.services = services; - } + internal readonly List> Processors = new(); + internal ResourceBuilder ResourceBuilder = ResourceBuilder.CreateDefault(); /// /// Gets or sets a value indicating whether or not log scopes should be /// included on generated s. Default value: /// False. /// - public bool IncludeScopes - { - get => this.includeScopes ?? DefaultIncludeScopes; - set => this.includeScopes = value; - } + public bool IncludeScopes { get; set; } /// /// Gets or sets a value indicating whether or not formatted log message /// should be included on generated s. Default /// value: False. /// - public bool IncludeFormattedMessage - { - get => this.includeFormattedMessage ?? DefaultIncludeFormattedMessage; - set => this.includeFormattedMessage = value; - } + public bool IncludeFormattedMessage { get; set; } /// /// Gets or sets a value indicating whether or not log state should be @@ -88,142 +55,18 @@ public bool IncludeFormattedMessage /// langword="true"/> will always be . /// - public bool ParseStateValues - { - get => this.parseStateValues ?? DefaultParseStateValues; - set => this.parseStateValues = value; - } - - internal IServiceCollection? Services => this.services; + public bool ParseStateValues { get; set; } /// /// Adds processor to the options. /// - /// - /// Note: The supplied will be - /// automatically disposed when then the final built from the options is - /// disposed. - /// /// Log processor to add. /// Returns for chaining. public OpenTelemetryLoggerOptions AddProcessor(BaseProcessor processor) { Guard.ThrowIfNull(processor); - this.ConfigureProvider((sp, provider) => provider.AddProcessor(processor)); - - return this; - } - - /// - /// Adds a processor to the options which will be retrieved using dependency injection. - /// - /// - /// Note: The type specified by will be - /// registered as a singleton service into application services. - /// - /// Processor type. - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddProcessor() - where T : BaseProcessor - { - this.TryAddSingleton(); - this.ConfigureProvider((sp, provider) => provider.AddProcessor(sp.GetRequiredService())); - - return this; - } - - /// - /// Adds an exporter to the provider. - /// - /// . - /// LogRecord exporter to add. - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddExporter(ExportProcessorType exportProcessorType, BaseExporter exporter) - => this.AddExporter(exportProcessorType, exporter, name: null, configure: null); - - /// - /// Adds an exporter to the provider. - /// - /// . - /// LogRecord exporter to add. - /// - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddExporter(ExportProcessorType exportProcessorType, BaseExporter exporter, Action configure) - => this.AddExporter(exportProcessorType, exporter, name: null, configure); - - /// - /// Adds an exporter to the provider. - /// - /// . - /// LogRecord exporter to add. - /// Name which is used when retrieving options. - /// - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddExporter( - ExportProcessorType exportProcessorType, - BaseExporter exporter, - string? name, - Action? configure) - { - Guard.ThrowIfNull(exporter); - - this.ConfigureProvider((sp, provider) - => provider.AddProcessor( - BuildExportProcessor(sp, exportProcessorType, exporter, name, configure))); - - return this; - } - - /// - /// Adds an exporter to the provider which will be retrieved using dependency injection. - /// - /// - /// Exporter type. - /// . - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddExporter(ExportProcessorType exportProcessorType) - where T : BaseExporter - => this.AddExporter(exportProcessorType, name: null, configure: null); - - /// - /// Adds an exporter to the provider which will be retrieved using dependency injection. - /// - /// - /// Exporter type. - /// . - /// - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddExporter(ExportProcessorType exportProcessorType, Action configure) - where T : BaseExporter - => this.AddExporter(exportProcessorType, name: null, configure); - - /// - /// Adds an exporter to the provider which will be retrieved using dependency injection. - /// - /// - /// Note: The type specified by will be - /// registered as a singleton service into application services. - /// - /// Exporter type. - /// . - /// Name which is used when retrieving options. - /// Callback action to configure . Only invoked when is . - /// Returns for chaining. - public OpenTelemetryLoggerOptions AddExporter( - ExportProcessorType exportProcessorType, - string? name, - Action? configure) - where T : BaseExporter - { - this.TryAddSingleton(); - this.ConfigureProvider((sp, provider) - => provider.AddProcessor( - BuildExportProcessor(sp, exportProcessorType, sp.GetRequiredService(), name, configure))); + this.Processors.Add(processor); return this; } @@ -231,8 +74,6 @@ public OpenTelemetryLoggerOptions AddExporter( /// /// Sets the from which the Resource associated with /// this provider is built from. Overwrites currently set ResourceBuilder. - /// You should usually use instead - /// (call if desired). /// /// from which Resource will be built. /// Returns for chaining. @@ -240,7 +81,8 @@ public OpenTelemetryLoggerOptions SetResourceBuilder(ResourceBuilder resourceBui { Guard.ThrowIfNull(resourceBuilder); - return this.ConfigureProvider((sp, provider) => provider.ResourceBuilder = resourceBuilder); + this.ResourceBuilder = resourceBuilder; + return this; } /// @@ -249,212 +91,11 @@ public OpenTelemetryLoggerOptions SetResourceBuilder(ResourceBuilder resourceBui /// /// An action which modifies the provided in-place. /// Returns for chaining. - public OpenTelemetryLoggerOptions ConfigureResource( - Action configure) - { - Guard.ThrowIfNull(configure); - - this.ConfigureProvider((sp, provider) => - { - Debug.Assert(provider.ResourceBuilder != null, "provider.ResourceBuilder was null"); - - configure(provider.ResourceBuilder!); - }); - - return this; - } - - /// - /// Register a callback action to configure the where logging services are configured. - /// - /// - /// Note: Logging services are only available during the application - /// configuration phase. When using "Options" pattern via or interfaces such as - /// logging services will be - /// unavailable because "Options" are built after application services - /// have been configured. - /// - /// Configuration callback. - /// The supplied for chaining. - public OpenTelemetryLoggerOptions ConfigureServices( - Action configure) + public OpenTelemetryLoggerOptions ConfigureResource(Action configure) { - Guard.ThrowIfNull(configure); - - var services = this.services; - - if (services == null) - { - throw new NotSupportedException("Services cannot be configured outside of application configuration phase."); - } - - configure(services); - + Guard.ThrowIfNull(configure, nameof(configure)); + configure(this.ResourceBuilder); return this; } - - /// - /// Register a callback action to configure the once the application is available. - /// - /// Configuration callback. - /// The supplied for chaining. - public OpenTelemetryLoggerOptions ConfigureProvider( - Action configure) - { - Guard.ThrowIfNull(configure); - - var configurationActions = this.ConfigurationActions; - if (configurationActions == null) - { - throw new NotSupportedException("Configuration actions cannot be registered on options after OpenTelemetryLoggerProvider has been created."); - } - - configurationActions.Add(configure); - - return this; - } - - /// - /// Sets the value of the options. - /// - /// to enable the option or - /// to disable it. - /// The supplied for - /// chaining. - public OpenTelemetryLoggerOptions SetIncludeFormattedMessage(bool enabled) - { - this.includeFormattedMessage = enabled; - return this; - } - - /// - /// Sets the value of the options. - /// - /// to enable the option or - /// to disable it. - /// The supplied for - /// chaining. - public OpenTelemetryLoggerOptions SetIncludeScopes(bool enabled) - { - this.includeScopes = enabled; - return this; - } - - /// - /// Sets the value of the options. - /// - /// to enable the option or - /// to disable it. - /// The supplied for - /// chaining. - public OpenTelemetryLoggerOptions SetParseStateValues(bool enabled) - { - this.parseStateValues = enabled; - return this; - } - - internal OpenTelemetryLoggerProvider Build() - { - var services = this.services; - - if (services == null) - { - throw new NotSupportedException("OpenTelemetryLoggerOptions build method cannot be called multiple times."); - } - - this.services = null; - -#if DEBUG - bool validateScopes = true; -#else - bool validateScopes = false; -#endif - var serviceProvider = services.BuildServiceProvider(validateScopes); - - var finalOptions = serviceProvider.GetRequiredService>().CurrentValue; - - this.ApplyTo(finalOptions); - - var provider = new OpenTelemetryLoggerProvider( - finalOptions, - serviceProvider, - ownsServiceProvider: true); - - this.ConfigurationActions = null; - - return provider; - } - - internal void ApplyTo(OpenTelemetryLoggerOptions other) - { - Debug.Assert(other != null, "other instance was null"); - - if (this.includeFormattedMessage.HasValue) - { - other!.includeFormattedMessage = this.includeFormattedMessage; - } - - if (this.includeScopes.HasValue) - { - other!.includeScopes = this.includeScopes; - } - - if (this.parseStateValues.HasValue) - { - other!.parseStateValues = this.parseStateValues; - } - - Debug.Assert(this.ConfigurationActions != null && other!.ConfigurationActions != null, "ConfigurationActions was null"); - - foreach (var configurationAction in this.ConfigurationActions!) - { - other!.ConfigurationActions!.Add(configurationAction); - } - } - - private static BaseProcessor BuildExportProcessor( - IServiceProvider serviceProvider, - ExportProcessorType exportProcessorType, - BaseExporter exporter, - string? name, - Action? configure) - { - name ??= Options.DefaultName; - - switch (exportProcessorType) - { - case ExportProcessorType.Simple: - return new SimpleLogRecordExportProcessor(exporter); - case ExportProcessorType.Batch: - var options = serviceProvider.GetRequiredService>().Get(name); - - options.ExportProcessorType = ExportProcessorType.Batch; - - configure?.Invoke(options); - - var batchOptions = options.BatchExportProcessorOptions; - - return new BatchLogRecordExportProcessor( - exporter, - batchOptions.MaxQueueSize, - batchOptions.ScheduledDelayMilliseconds, - batchOptions.ExporterTimeoutMilliseconds, - batchOptions.MaxExportBatchSize); - default: - throw new NotSupportedException($"ExportProcessorType '{exportProcessorType}' is not supported."); - } - } - - private void TryAddSingleton() - where T : class - { - var services = this.services; - - services?.TryAddSingleton(); - } } } diff --git a/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptionsExtensions.cs b/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptionsExtensions.cs deleted file mode 100644 index eb613e2dee3..00000000000 --- a/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptionsExtensions.cs +++ /dev/null @@ -1,45 +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. -// - -#nullable enable - -using System; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs; - -/// -/// Contains extension methods for the class. -/// -public static class OpenTelemetryLoggerOptionsExtensions -{ - /// - /// Run the given actions to initialize the . - /// - /// . - /// . - public static OpenTelemetryLoggerProvider Build(this OpenTelemetryLoggerOptions options) - { - Guard.ThrowIfNull(options); - - if (options is not OpenTelemetryLoggerOptionsSdk openTelemetryLoggerOptionsSdk) - { - throw new NotSupportedException("Build is only supported on options instances created using the Sdk.CreateLoggerProviderBuilder method."); - } - - return openTelemetryLoggerOptionsSdk.Build(); - } -} diff --git a/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptionsSdk.cs b/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptionsSdk.cs deleted file mode 100644 index 48f2a53b492..00000000000 --- a/src/OpenTelemetry/Logs/Options/OpenTelemetryLoggerOptionsSdk.cs +++ /dev/null @@ -1,30 +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. -// - -#nullable enable - -using Microsoft.Extensions.DependencyInjection; - -namespace OpenTelemetry.Logs; - -internal sealed class OpenTelemetryLoggerOptionsSdk : OpenTelemetryLoggerOptions -{ - public OpenTelemetryLoggerOptionsSdk() - : base(new ServiceCollection()) - { - this.ConfigureServices(services => services.AddOptions()); - } -} diff --git a/src/OpenTelemetry/Sdk.cs b/src/OpenTelemetry/Sdk.cs index eb17c6d3631..62fb0da26d1 100644 --- a/src/OpenTelemetry/Sdk.cs +++ b/src/OpenTelemetry/Sdk.cs @@ -19,7 +19,6 @@ using System.Diagnostics; using OpenTelemetry.Context.Propagation; using OpenTelemetry.Internal; -using OpenTelemetry.Logs; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -59,19 +58,6 @@ public static void SetDefaultTextMapPropagator(TextMapPropagator textMapPropagat Propagators.DefaultTextMapPropagator = textMapPropagator; } - /// - /// Creates a which is used to build - /// an . In a typical application, a single - /// is created at application startup and disposed - /// at application shutdown. It is important to ensure that the provider is not - /// disposed too early. - /// - /// instance, which is used to build a . - public static OpenTelemetryLoggerOptions CreateLoggerProviderBuilder() - { - return new OpenTelemetryLoggerOptionsSdk(); - } - /// /// Creates a which is used to build /// a . In a typical application, a single diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index cfe27e80bed..8feab03e185 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -113,32 +113,6 @@ public void AddOtlpLogExporterParseStateValueCanBeTurnedOffHosting() Assert.Null(logRecord.StateValues); } - [Fact] - public void AddOtlpLogExporterNamedOptionsSupported() - { - int defaultExporterOptionsConfigureOptionsInvocations = 0; - int namedExporterOptionsConfigureOptionsInvocations = 0; - - using var loggerFactory = LoggerFactory.Create(builder => - { - builder.AddOpenTelemetry(options => - { - options - .ConfigureServices(services => - { - services.Configure(o => defaultExporterOptionsConfigureOptionsInvocations++); - - services.Configure("Exporter2", o => namedExporterOptionsConfigureOptionsInvocations++); - }) - .AddOtlpExporter() - .AddOtlpExporter("Exporter2", o => { }); - }); - }); - - Assert.Equal(1, defaultExporterOptionsConfigureOptionsInvocations); - Assert.Equal(1, namedExporterOptionsConfigureOptionsInvocations); - } - [Fact] public void OtlpLogRecordTestWhenStateValuesArePopulated() { diff --git a/test/OpenTelemetry.Extensions.EventSource.Tests/AssemblyInfo.cs b/test/OpenTelemetry.Extensions.EventSource.Tests/AssemblyInfo.cs deleted file mode 100644 index 11bfd5a2025..00000000000 --- a/test/OpenTelemetry.Extensions.EventSource.Tests/AssemblyInfo.cs +++ /dev/null @@ -1,19 +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 System; - -[assembly: CLSCompliant(false)] diff --git a/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetry.Extensions.EventSource.Tests.csproj b/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetry.Extensions.EventSource.Tests.csproj deleted file mode 100644 index 855502dd5b3..00000000000 --- a/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetry.Extensions.EventSource.Tests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - Unit test project for OpenTelemetry EventSource extensions - - net6.0 - $(TargetFrameworks);net462 - enable - AllEnabledByDefault - latest - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - diff --git a/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetryEventSourceLogEmitterTests.cs b/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetryEventSourceLogEmitterTests.cs deleted file mode 100644 index e21b60c109f..00000000000 --- a/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetryEventSourceLogEmitterTests.cs +++ /dev/null @@ -1,328 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.Tracing; -using System.Globalization; -using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; -using Xunit; - -namespace OpenTelemetry.Extensions.EventSource.Tests -{ - public class OpenTelemetryEventSourceLogEmitterTests - { - [Theory] - [InlineData(true)] - [InlineData(false)] - public void OpenTelemetryEventSourceLogEmitterDisposesProviderTests(bool dispose) - { -#pragma warning disable CA2000 // Dispose objects before losing scope - var disposeTrackingProcessor = new DisposeTrackingProcessor(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(disposeTrackingProcessor) - .Build()) - { - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => null, - disposeProvider: dispose)) - { - } - - Assert.Equal(dispose, disposeTrackingProcessor.Disposed); - - openTelemetryLoggerProvider.Dispose(); - } - - Assert.True(disposeTrackingProcessor.Disposed); - } - - [Theory] - [InlineData(TestEventSource.EventSourceName, EventLevel.LogAlways, 2)] - [InlineData(TestEventSource.EventSourceName, EventLevel.Warning, 1)] - [InlineData("_invalid_", EventLevel.LogAlways, 0)] - public void OpenTelemetryEventSourceLogEmitterFilterTests(string sourceName, EventLevel? eventLevel, int expectedNumberOfLogRecords) - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == sourceName ? eventLevel : null)) - { - TestEventSource.Log.SimpleEvent(); - TestEventSource.Log.ComplexEvent("Test_Message", 18); - } - - Assert.Equal(expectedNumberOfLogRecords, exportedItems.Count); - } - - [Fact] - public void OpenTelemetryEventSourceLogEmitterCapturesExistingSourceTest() - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - TestEventSource.Log.SimpleEvent(); - - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == TestEventSource.EventSourceName ? EventLevel.LogAlways : null)) - { - TestEventSource.Log.SimpleEvent(); - } - - Assert.Single(exportedItems); - } - - [Fact] - public void OpenTelemetryEventSourceLogEmitterSimpleEventTest() - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == TestEventSource.EventSourceName ? EventLevel.LogAlways : null)) - { - TestEventSource.Log.SimpleEvent(); - } - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotEqual(DateTime.MinValue, logRecord.Timestamp); - Assert.Equal(TestEventSource.SimpleEventMessage, logRecord.FormattedMessage); - Assert.Equal(TestEventSource.SimpleEventId, logRecord.EventId.Id); - Assert.Equal(nameof(TestEventSource.SimpleEvent), logRecord.EventId.Name); - Assert.Equal(LogLevel.Warning, logRecord.LogLevel); - Assert.Null(logRecord.CategoryName); - Assert.Null(logRecord.Exception); - - Assert.Equal(default, logRecord.TraceId); - Assert.Equal(default, logRecord.SpanId); - Assert.Null(logRecord.TraceState); - Assert.Equal(ActivityTraceFlags.None, logRecord.TraceFlags); - - Assert.NotNull(logRecord.StateValues); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "event_source.name" && (string?)kvp.Value == TestEventSource.EventSourceName); - } - - [Fact] - public void OpenTelemetryEventSourceLogEmitterSimpleEventWithActivityTest() - { - using var activity = new Activity("Test"); - activity.Start(); - - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == TestEventSource.EventSourceName ? EventLevel.LogAlways : null)) - { - TestEventSource.Log.SimpleEvent(); - } - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotEqual(default, logRecord.TraceId); - - Assert.Equal(activity.TraceId, logRecord.TraceId); - Assert.Equal(activity.SpanId, logRecord.SpanId); - Assert.Equal(activity.TraceStateString, logRecord.TraceState); - Assert.Equal(activity.ActivityTraceFlags, logRecord.TraceFlags); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void OpenTelemetryEventSourceLogEmitterComplexEventTest(bool formatMessage) - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .SetIncludeFormattedMessage(formatMessage) - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == TestEventSource.EventSourceName ? EventLevel.LogAlways : null)) - { - TestEventSource.Log.ComplexEvent("Test_Message", 18); - } - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotEqual(DateTime.MinValue, logRecord.Timestamp); - if (!formatMessage) - { - Assert.Equal(TestEventSource.ComplexEventMessageStructured, logRecord.FormattedMessage); - } - else - { - string expectedMessage = string.Format(CultureInfo.InvariantCulture, TestEventSource.ComplexEventMessage, "Test_Message", 18); - Assert.Equal(expectedMessage, logRecord.FormattedMessage); - } - - Assert.Equal(TestEventSource.ComplexEventId, logRecord.EventId.Id); - Assert.Equal(nameof(TestEventSource.ComplexEvent), logRecord.EventId.Name); - Assert.Equal(LogLevel.Information, logRecord.LogLevel); - Assert.Null(logRecord.CategoryName); - Assert.Null(logRecord.Exception); - - Assert.Equal(default, logRecord.TraceId); - Assert.Equal(default, logRecord.SpanId); - Assert.Null(logRecord.TraceState); - Assert.Equal(ActivityTraceFlags.None, logRecord.TraceFlags); - - Assert.NotNull(logRecord.StateValues); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "event_source.name" && (string?)kvp.Value == TestEventSource.EventSourceName); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "arg1" && (string?)kvp.Value == "Test_Message"); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "arg2" && (int?)kvp.Value == 18); - } - - [Theory(Skip = "Not runnable in CI, see note.")] - [InlineData(true)] - [InlineData(false)] - public void OpenTelemetryEventSourceLogEmitterActivityIdTest(bool enableTplListener) - { - /* - * Note: - * - * To enable Activity ID the 'System.Threading.Tasks.TplEventSource' - * source must be enabled see: - * https://docs.microsoft.com/en-us/dotnet/core/diagnostics/eventsource-activity-ids#tracking-work-using-an-activity-id - * - * Once enabled, it cannot be turned off: - * https://github.com/dotnet/runtime/blob/0fbdb1ed6e076829e4693a61ae5d11c4cb23e7ee/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/ActivityTracker.cs#L208 - * - * That behavior makes testing it difficult. - */ - using var tplListener = enableTplListener ? new TplEventSourceListener() : null; - - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter( - openTelemetryLoggerProvider, - (name) => name == TestEventSource.EventSourceName ? EventLevel.LogAlways : null)) - { - TestEventSource.Log.WorkStart(); - - TestEventSource.Log.SubworkStart(); - - TestEventSource.Log.SubworkStop(); - - TestEventSource.Log.WorkStop(); - } - - Assert.Equal(4, exportedItems.Count); - - var logRecord = exportedItems[1]; - Assert.NotNull(logRecord.StateValues); - if (enableTplListener) - { - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "event_source.activity_id"); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "event_source.related_activity_id"); - } - else - { - Assert.DoesNotContain(logRecord.StateValues, kvp => kvp.Key == "event_source.activity_id"); - Assert.DoesNotContain(logRecord.StateValues, kvp => kvp.Key == "event_source.related_activity_id"); - } - } - - private sealed class DisposeTrackingProcessor : BaseProcessor - { - public bool Disposed { get; private set; } - - protected override void Dispose(bool disposing) - { - this.Disposed = true; - - base.Dispose(disposing); - } - } - - private sealed class TplEventSourceListener : EventListener - { - private readonly List eventSources = new(); - - /// - public override void Dispose() - { - foreach (System.Diagnostics.Tracing.EventSource eventSource in this.eventSources) - { - this.DisableEvents(eventSource); - } - - this.eventSources.Clear(); - - base.Dispose(); - } - - protected override void OnEventSourceCreated(System.Diagnostics.Tracing.EventSource eventSource) - { - if (eventSource.Name == "System.Threading.Tasks.TplEventSource") - { - // Activity IDs aren't enabled by default. - // Enabling Keyword 0x80 on the TplEventSource turns them on - this.EnableEvents(eventSource, EventLevel.LogAlways, (EventKeywords)0x80); - this.eventSources.Add(eventSource); - } - } - } - } -} diff --git a/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetryEventSourceLoggerOptionsExtensionsTests.cs b/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetryEventSourceLoggerOptionsExtensionsTests.cs deleted file mode 100644 index 0dea48dd69f..00000000000 --- a/test/OpenTelemetry.Extensions.EventSource.Tests/OpenTelemetryEventSourceLoggerOptionsExtensionsTests.cs +++ /dev/null @@ -1,65 +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. -// - -#nullable enable - -using System.Collections.Generic; -using System.Diagnostics.Tracing; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; -using Xunit; - -namespace OpenTelemetry.Extensions.EventSource.Tests -{ - public class OpenTelemetryEventSourceLoggerOptionsExtensionsTests - { - [Fact] - public void AddOpenTelemetryEventSourceLogEmitterTest() - { - var exportedItems = new List(); - - var services = new ServiceCollection(); - - services.AddLogging(configure => - { - configure.AddOpenTelemetry(options => - { - options - .AddInMemoryExporter(exportedItems) - .AddEventSourceLogEmitter((name) => name == TestEventSource.EventSourceName ? EventLevel.LogAlways : null); - }); - }); - - OpenTelemetryEventSourceLoggerOptionsExtensions.EventSourceManager? eventSourceManager = null; - - using (var serviceProvider = services.BuildServiceProvider()) - { - var loggerFactory = serviceProvider.GetRequiredService(); - - eventSourceManager = serviceProvider.GetRequiredService(); - - Assert.Single(eventSourceManager.Emitters); - - TestEventSource.Log.SimpleEvent(); - } - - Assert.Single(exportedItems); - - Assert.Empty(eventSourceManager.Emitters); - } - } -} diff --git a/test/OpenTelemetry.Extensions.EventSource.Tests/TestEventSource.cs b/test/OpenTelemetry.Extensions.EventSource.Tests/TestEventSource.cs deleted file mode 100644 index aee8f12b888..00000000000 --- a/test/OpenTelemetry.Extensions.EventSource.Tests/TestEventSource.cs +++ /dev/null @@ -1,71 +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 System.Diagnostics.Tracing; - -namespace OpenTelemetry.Extensions.EventSource.Tests -{ - [EventSource(Name = TestEventSource.EventSourceName)] - public sealed class TestEventSource : System.Diagnostics.Tracing.EventSource - { - public const string EventSourceName = "OpenTelemetry.Extensions.EventSource.Tests"; - - public const int SimpleEventId = 1; - public const string SimpleEventMessage = "Warning event with no arguments."; - - public const int ComplexEventId = 2; - public const string ComplexEventMessage = "Information event with two arguments: '{0}' & '{1}'."; - public const string ComplexEventMessageStructured = "Information event with two arguments: '{arg1}' & '{arg2}'."; - - public static TestEventSource Log { get; } = new(); - - [Event(SimpleEventId, Message = SimpleEventMessage, Level = EventLevel.Warning)] - public void SimpleEvent() - { - this.WriteEvent(SimpleEventId); - } - - [Event(ComplexEventId, Message = ComplexEventMessage, Level = EventLevel.Informational)] - public void ComplexEvent(string arg1, int arg2) - { - this.WriteEvent(ComplexEventId, arg1, arg2); - } - - [Event(3, Level = EventLevel.Verbose)] - public void WorkStart() - { - this.WriteEvent(3); - } - - [Event(4, Level = EventLevel.Verbose)] - public void WorkStop() - { - this.WriteEvent(4); - } - - [Event(5, Level = EventLevel.Verbose)] - public void SubworkStart() - { - this.WriteEvent(5); - } - - [Event(6, Level = EventLevel.Verbose)] - public void SubworkStop() - { - this.WriteEvent(6); - } - } -} diff --git a/test/OpenTelemetry.Extensions.Serilog.Tests/AssemblyInfo.cs b/test/OpenTelemetry.Extensions.Serilog.Tests/AssemblyInfo.cs deleted file mode 100644 index 11bfd5a2025..00000000000 --- a/test/OpenTelemetry.Extensions.Serilog.Tests/AssemblyInfo.cs +++ /dev/null @@ -1,19 +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 System; - -[assembly: CLSCompliant(false)] diff --git a/test/OpenTelemetry.Extensions.Serilog.Tests/OpenTelemetry.Extensions.Serilog.Tests.csproj b/test/OpenTelemetry.Extensions.Serilog.Tests/OpenTelemetry.Extensions.Serilog.Tests.csproj deleted file mode 100644 index daa1bc3dfeb..00000000000 --- a/test/OpenTelemetry.Extensions.Serilog.Tests/OpenTelemetry.Extensions.Serilog.Tests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - Unit test project for OpenTelemetry Serilog extensions - - net6.0 - $(TargetFrameworks);net462 - enable - AllEnabledByDefault - latest - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - diff --git a/test/OpenTelemetry.Extensions.Serilog.Tests/OpenTelemetrySerilogSinkTests.cs b/test/OpenTelemetry.Extensions.Serilog.Tests/OpenTelemetrySerilogSinkTests.cs deleted file mode 100644 index cee32f26b53..00000000000 --- a/test/OpenTelemetry.Extensions.Serilog.Tests/OpenTelemetrySerilogSinkTests.cs +++ /dev/null @@ -1,285 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; -using Serilog; -using Xunit; -using ILogger = Serilog.ILogger; - -namespace OpenTelemetry.Extensions.Serilog.Tests -{ - public class OpenTelemetrySerilogSinkTests - { - [Theory] - [InlineData(true)] - [InlineData(false)] - public void SerilogDisposesProviderTests(bool dispose) - { -#pragma warning disable CA2000 // Dispose objects before losing scope - var disposeTrackingProcessor = new DisposeTrackingProcessor(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - using (var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(disposeTrackingProcessor) - .Build()) - { - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: dispose) - .CreateLogger(); - - Log.CloseAndFlush(); - - Assert.Equal(dispose, disposeTrackingProcessor.Disposed); - } - - Assert.True(disposeTrackingProcessor.Disposed); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void SerilogBasicLogTests(bool includeFormattedMessage) - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .SetIncludeFormattedMessage(includeFormattedMessage) - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - - Log.Logger.Information("Hello {greeting}", "World"); - - Log.CloseAndFlush(); - - Assert.Single(exportedItems); - - LogRecord logRecord = exportedItems[0]; - - if (!includeFormattedMessage) - { - Assert.Equal("Hello {greeting}", logRecord.FormattedMessage); - } - else - { - Assert.Equal("Hello \"World\"", logRecord.FormattedMessage); - } - - Assert.NotEqual(DateTime.MinValue, logRecord.Timestamp); - Assert.Equal(DateTimeKind.Utc, logRecord.Timestamp.Kind); - Assert.Equal(LogLevel.Information, logRecord.LogLevel); - Assert.Null(logRecord.CategoryName); - - Assert.NotNull(logRecord.StateValues); - Assert.Single(logRecord.StateValues); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "greeting" && (string?)kvp.Value == "World"); - - Assert.Equal(default, logRecord.TraceId); - Assert.Equal(default, logRecord.SpanId); - Assert.Null(logRecord.TraceState); - Assert.Equal(ActivityTraceFlags.None, logRecord.TraceFlags); - } - - [Fact] - public void SerilogBasicLogWithActivityTest() - { - using var activity = new Activity("Test"); - activity.Start(); - - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - - Log.Logger.Information("Hello {greeting}", "World"); - - Log.CloseAndFlush(); - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotEqual(default, logRecord.TraceId); - - Assert.Equal(activity.TraceId, logRecord.TraceId); - Assert.Equal(activity.SpanId, logRecord.SpanId); - Assert.Equal(activity.TraceStateString, logRecord.TraceState); - Assert.Equal(activity.ActivityTraceFlags, logRecord.TraceFlags); - } - - [Fact] - public void SerilogCategoryNameTest() - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - - // Note: Serilog ForContext API is used to set "CategoryName" on log messages - ILogger logger = Log.Logger.ForContext(); - - logger.Information("Hello {greeting}", "World"); - - Log.CloseAndFlush(); - - Assert.Single(exportedItems); - - LogRecord logRecord = exportedItems[0]; - - Assert.Equal("OpenTelemetry.Extensions.Serilog.Tests.OpenTelemetrySerilogSinkTests", logRecord.CategoryName); - } - - [Fact] - public void SerilogComplexMessageTemplateTest() - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - - ComplexType complexType = new(); - - Log.Logger.Information("Hello {greeting} {id} {@complexObj} {$complexStr}", "World", 18, complexType, complexType); - - Log.CloseAndFlush(); - - Assert.Single(exportedItems); - - LogRecord logRecord = exportedItems[0]; - - Assert.NotNull(logRecord.StateValues); - Assert.Equal(3, logRecord.StateValues!.Count); // Note: complexObj is currently not supported/ignored. - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "greeting" && (string?)kvp.Value == "World"); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "id" && (int?)kvp.Value == 18); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "complexStr" && (string?)kvp.Value == "ComplexTypeToString"); - } - - [Fact] - public void SerilogArrayMessageTemplateTest() - { - List exportedItems = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - - ComplexType complexType = new(); - - var intArray = new int[] { 0, 1, 2, 3, 4 }; - var mixedArray = new object?[] { 0, null, "3", 18.0D }; - - Log.Logger.Information("Int array {data}", intArray); - Log.Logger.Information("Mixed array {data}", new object[] { mixedArray }); - - Log.CloseAndFlush(); - - Assert.Equal(2, exportedItems.Count); - - LogRecord logRecord = exportedItems[0]; - - Assert.NotNull(logRecord.StateValues); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "data" && kvp.Value is int[] typedArray && intArray.SequenceEqual(typedArray)); - - logRecord = exportedItems[1]; - Assert.NotNull(logRecord.StateValues); - Assert.Contains(logRecord.StateValues, kvp => kvp.Key == "data" && kvp.Value is object?[] typedArray && mixedArray.SequenceEqual(typedArray)); - } - - [Fact] - public void SerilogExceptionTest() - { - List exportedItems = new(); - - InvalidOperationException ex = new(); - -#pragma warning disable CA2000 // Dispose objects before losing scope - var openTelemetryLoggerProvider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); -#pragma warning restore CA2000 // Dispose objects before losing scope - - Log.Logger = new LoggerConfiguration() - .WriteTo.OpenTelemetry(openTelemetryLoggerProvider, disposeProvider: true) - .CreateLogger(); - - ComplexType complexType = new(); - - Log.Logger.Information(ex, "Exception"); - - Log.CloseAndFlush(); - - Assert.Single(exportedItems); - - LogRecord logRecord = exportedItems[0]; - - Assert.Equal(ex, logRecord.Exception); - } - - private sealed class DisposeTrackingProcessor : BaseProcessor - { - public bool Disposed { get; private set; } - - protected override void Dispose(bool disposing) - { - this.Disposed = true; - - base.Dispose(disposing); - } - } - - private sealed class ComplexType - { - public override string ToString() => "ComplexTypeToString"; - } - } -} diff --git a/test/OpenTelemetry.Tests/Logs/LogEmitterTests.cs b/test/OpenTelemetry.Tests/Logs/LogEmitterTests.cs deleted file mode 100644 index e8da01b66f0..00000000000 --- a/test/OpenTelemetry.Tests/Logs/LogEmitterTests.cs +++ /dev/null @@ -1,173 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.Extensions.Logging; -using Xunit; - -namespace OpenTelemetry.Logs.Tests -{ - public sealed class LogEmitterTests - { - [Fact] - public void LogEmitterBasicTest() - { - var exportedItems = new List(); - - using var provider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); - - var logEmitter = provider.CreateEmitter(); - - Exception ex = new InvalidOperationException(); - - logEmitter.Emit( - new() - { - CategoryName = "LogEmitter", - Message = "Hello world", - LogLevel = LogLevel.Warning, - EventId = new EventId(18, "CustomEvent"), - Exception = ex, - }, - new() - { - ["key1"] = "value1", - ["key2"] = "value2", - }); - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotNull(logRecord); - Assert.Equal("LogEmitter", logRecord.CategoryName); - Assert.Equal("Hello world", logRecord.FormattedMessage); - Assert.Equal(LogLevel.Warning, logRecord.LogLevel); - Assert.Equal(18, logRecord.EventId.Id); - Assert.Equal("CustomEvent", logRecord.EventId.Name); - Assert.Equal(ex, logRecord.Exception); - Assert.NotEqual(DateTime.MinValue, logRecord.Timestamp); - - Assert.Equal(default, logRecord.TraceId); - Assert.Equal(default, logRecord.SpanId); - Assert.Equal(ActivityTraceFlags.None, logRecord.TraceFlags); - Assert.Null(logRecord.TraceState); - - Assert.NotNull(logRecord.StateValues); - Assert.Equal(2, logRecord.StateValues.Count); - Assert.Contains(logRecord.StateValues, item => item.Key == "key1" && (string)item.Value == "value1"); - Assert.Contains(logRecord.StateValues, item => item.Key == "key2" && (string)item.Value == "value2"); - } - - [Fact] - public void LogEmitterFromActivityTest() - { - var exportedItems = new List(); - - using var provider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); - - var logEmitter = provider.CreateEmitter(); - - using var activity = new Activity("Test"); - - activity.Start(); - - activity.ActivityTraceFlags = ActivityTraceFlags.Recorded; - activity.TraceStateString = "key1=value1"; - - logEmitter.Emit(new(activity)); - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotNull(logRecord); - - Assert.Equal(activity.TraceId, logRecord.TraceId); - Assert.Equal(activity.SpanId, logRecord.SpanId); - Assert.Equal(activity.ActivityTraceFlags, logRecord.TraceFlags); - Assert.Equal(activity.TraceStateString, logRecord.TraceState); - - Assert.Null(logRecord.StateValues); - } - - [Fact] - public void LogEmitterLocalToUtcTimestampTest() - { - var exportedItems = new List(); - - using var provider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); - - var logEmitter = provider.CreateEmitter(); - - DateTime timestamp = DateTime.SpecifyKind( - new DateTime(2022, 6, 30, 16, 0, 0), - DateTimeKind.Local); - - logEmitter.Emit(new() - { - Timestamp = timestamp, - }); - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotNull(logRecord); - - Assert.Equal(timestamp.ToUniversalTime(), logRecord.Timestamp); - Assert.Equal(DateTimeKind.Utc, logRecord.Timestamp.Kind); - } - - [Fact] - public void LogEmitterUnspecifiedTimestampTest() - { - var exportedItems = new List(); - - using var provider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); - - var logEmitter = provider.CreateEmitter(); - - DateTime timestamp = DateTime.SpecifyKind( - new DateTime(2022, 6, 30, 16, 0, 0), - DateTimeKind.Unspecified); - - logEmitter.Emit(new() - { - Timestamp = timestamp, - }); - - Assert.Single(exportedItems); - - var logRecord = exportedItems[0]; - - Assert.NotNull(logRecord); - - Assert.Equal(timestamp, logRecord.Timestamp); - Assert.Equal(DateTimeKind.Unspecified, logRecord.Timestamp.Kind); - } - } -} diff --git a/test/OpenTelemetry.Tests/Logs/LoggerOptionsTest.cs b/test/OpenTelemetry.Tests/Logs/LoggerOptionsTest.cs index aacc1e82f2a..57989649553 100644 --- a/test/OpenTelemetry.Tests/Logs/LoggerOptionsTest.cs +++ b/test/OpenTelemetry.Tests/Logs/LoggerOptionsTest.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using Microsoft.Extensions.DependencyInjection; using Xunit; namespace OpenTelemetry.Logs.Tests @@ -26,18 +25,13 @@ public sealed class LoggerOptionsTest [InlineData(false)] public void VerifyOptionsCannotBeChangedAfterInit(bool initialValue) { - OpenTelemetryLoggerOptions options = null; - - using var provider = Sdk.CreateLoggerProviderBuilder() - .ConfigureServices(services => services.Configure(o => - { - options = o; - - o.IncludeFormattedMessage = initialValue; - o.IncludeScopes = initialValue; - o.ParseStateValues = initialValue; - })) - .Build(); + var options = new OpenTelemetryLoggerOptions + { + IncludeFormattedMessage = initialValue, + IncludeScopes = initialValue, + ParseStateValues = initialValue, + }; + var provider = new OpenTelemetryLoggerProvider(options); // Verify initial set Assert.Equal(initialValue, provider.IncludeFormattedMessage); diff --git a/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerOptionsSdkTests.cs b/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerOptionsSdkTests.cs deleted file mode 100644 index bb9d1a3fa7b..00000000000 --- a/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerOptionsSdkTests.cs +++ /dev/null @@ -1,119 +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. -// - -#nullable enable - -using System; -using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; -using OpenTelemetry.Resources; -using Xunit; - -namespace OpenTelemetry.Logs.Tests; - -public class OpenTelemetryLoggerOptionsSdkTests -{ - [Fact] - public void CreateLoggerProviderBuilderBuildValidProviderTest() - { - List exportedItems = new(); - - using var provider = Sdk.CreateLoggerProviderBuilder() - .AddInMemoryExporter(exportedItems) - .Build(); - - Assert.NotNull(provider); - - provider.CreateEmitter().Emit(new() - { - Message = "Hello world", - }); - - Assert.Single(exportedItems); - } - - [Fact] - public void CreateLoggerProviderBuilderExtensionPointsTest() - { - int optionsConfigureInvocations = 0; - OpenTelemetryLoggerProvider? providerFromConfigureCallback = null; - - var returnedOptions = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(new CustomProcessor()) - .AddProcessor() - .ConfigureServices(services => - { - services.AddSingleton(); - services.Configure(o => - { - optionsConfigureInvocations++; - - Assert.Null(o.Services); - - Assert.Throws(() => o.ConfigureServices(s => { })); - - o.ConfigureResource(r => r.AddAttributes(new Dictionary { ["key1"] = "value1" })); - - o.ConfigureProvider((sp, p) => optionsConfigureInvocations++); - }); - }) - .ConfigureProvider((sp, p) => - { - Assert.NotNull(sp); - - providerFromConfigureCallback = p; - - Assert.NotNull(sp.GetService()); - }); - - using var provider = returnedOptions.Build(); - - Assert.NotNull(provider); - - Assert.Throws(() => returnedOptions.ConfigureServices(s => { })); - Assert.Throws(() => returnedOptions.ConfigureResource(r => { })); - Assert.Throws(() => returnedOptions.ConfigureProvider((sp, p) => { })); - Assert.Throws(() => returnedOptions.Build()); - - Assert.Equal(2, optionsConfigureInvocations); - Assert.NotNull(providerFromConfigureCallback); - Assert.Equal(provider, providerFromConfigureCallback); - - Assert.NotNull(provider.Resource?.Attributes); - Assert.Contains(provider.Resource!.Attributes, kvp => kvp.Key == "key1" && (string)kvp.Value == "value1"); - - var processor = provider.Processor as CompositeProcessor; - Assert.NotNull(processor); - - int count = 0; - var current = processor?.Head; - while (current != null) - { - count++; - current = current.Next; - } - - Assert.Equal(2, count); - } - - private sealed class TestClass1 - { - } - - private sealed class CustomProcessor : BaseProcessor - { - } -} diff --git a/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerProviderTests.cs b/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerProviderTests.cs index d4c9c492900..6ddd5d7caa4 100644 --- a/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerProviderTests.cs +++ b/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerProviderTests.cs @@ -16,7 +16,6 @@ using System.Collections.Generic; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using OpenTelemetry.Exporter; using OpenTelemetry.Resources; using Xunit; @@ -44,15 +43,18 @@ public void ConfigureCtorTests() { OpenTelemetryLoggerOptions defaults = new(); - using OpenTelemetryLoggerProvider provider = Sdk.CreateLoggerProviderBuilder() - .SetIncludeScopes(!defaults.IncludeScopes) - .SetIncludeFormattedMessage(!defaults.IncludeFormattedMessage) - .SetParseStateValues(!defaults.ParseStateValues) - .SetResourceBuilder(ResourceBuilder + using OpenTelemetryLoggerProvider provider = new(options => + { + options.IncludeScopes = !defaults.IncludeScopes; + options.IncludeFormattedMessage = !defaults.IncludeFormattedMessage; + options.ParseStateValues = !defaults.ParseStateValues; + + options.SetResourceBuilder(ResourceBuilder .CreateEmpty() - .AddAttributes(new[] { new KeyValuePair("key1", "value1") })) - .AddInMemoryExporter(new List()) - .Build(); + .AddAttributes(new[] { new KeyValuePair("key1", "value1") })); + + options.AddInMemoryExporter(new List()); + }); Assert.Equal(!defaults.IncludeScopes, provider.IncludeScopes); Assert.Equal(!defaults.IncludeFormattedMessage, provider.IncludeFormattedMessage); @@ -87,20 +89,20 @@ public void ForceFlushTest() [Fact] public void ThreadStaticPoolUsedByProviderTests() { - using var provider1 = new OpenTelemetryLoggerProvider(); + using var provider1 = new OpenTelemetryLoggerProvider(new OpenTelemetryLoggerOptions()); Assert.Equal(LogRecordThreadStaticPool.Instance, provider1.LogRecordPool); - using var provider2 = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())) - .Build(); + var options = new OpenTelemetryLoggerOptions(); + options.AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())); + + using var provider2 = new OpenTelemetryLoggerProvider(options); Assert.Equal(LogRecordThreadStaticPool.Instance, provider2.LogRecordPool); - using var provider3 = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())) - .AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())) - .Build(); + options.AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())); + + using var provider3 = new OpenTelemetryLoggerProvider(options); Assert.Equal(LogRecordThreadStaticPool.Instance, provider3.LogRecordPool); } @@ -108,27 +110,30 @@ public void ThreadStaticPoolUsedByProviderTests() [Fact] public void SharedPoolUsedByProviderTests() { - using var provider1 = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(new BatchLogRecordExportProcessor(new NoopExporter())) - .Build(); + var options = new OpenTelemetryLoggerOptions(); + options.AddProcessor(new BatchLogRecordExportProcessor(new NoopExporter())); + + using var provider1 = new OpenTelemetryLoggerProvider(options); Assert.Equal(LogRecordSharedPool.Current, provider1.LogRecordPool); - using var provider2 = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())) - .AddProcessor(new BatchLogRecordExportProcessor(new NoopExporter())) - .Build(); + options = new OpenTelemetryLoggerOptions(); + options.AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())); + options.AddProcessor(new BatchLogRecordExportProcessor(new NoopExporter())); + + using var provider2 = new OpenTelemetryLoggerProvider(options); Assert.Equal(LogRecordSharedPool.Current, provider2.LogRecordPool); - using var provider3 = Sdk.CreateLoggerProviderBuilder() - .AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())) - .AddProcessor(new CompositeProcessor(new BaseProcessor[] - { - new SimpleLogRecordExportProcessor(new NoopExporter()), - new BatchLogRecordExportProcessor(new NoopExporter()), - })) - .Build(); + options = new OpenTelemetryLoggerOptions(); + options.AddProcessor(new SimpleLogRecordExportProcessor(new NoopExporter())); + options.AddProcessor(new CompositeProcessor(new BaseProcessor[] + { + new SimpleLogRecordExportProcessor(new NoopExporter()), + new BatchLogRecordExportProcessor(new NoopExporter()), + })); + + using var provider3 = new OpenTelemetryLoggerProvider(options); Assert.Equal(LogRecordSharedPool.Current, provider3.LogRecordPool); } diff --git a/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggingExtensionsTests.cs b/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggingExtensionsTests.cs index 87211995098..c6a6aa5a893 100644 --- a/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggingExtensionsTests.cs +++ b/test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggingExtensionsTests.cs @@ -16,11 +16,8 @@ #nullable enable -using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using OpenTelemetry.Resources; using Xunit; namespace OpenTelemetry.Logs.Tests; @@ -28,7 +25,7 @@ namespace OpenTelemetry.Logs.Tests; public sealed class OpenTelemetryLoggingExtensionsTests { [Fact] - public void LoggingBuilderAddOpenTelemetryNoParametersTest() + public void ServiceCollectionAddOpenTelemetryNoParametersTest() { bool optionsCallbackInvoked = false; @@ -54,9 +51,10 @@ public void LoggingBuilderAddOpenTelemetryNoParametersTest() } [Theory] - [InlineData(1)] - [InlineData(5)] - public void LoggingBuilderAddOpenTelemetryConfigureActionTests(int numberOfOptionsRegistrations) + [InlineData(1, 0)] + [InlineData(1, 1)] + [InlineData(5, 5)] + public void ServiceCollectionAddOpenTelemetryConfigureActionTests(int numberOfBuilderRegistrations, int numberOfOptionsRegistrations) { int configureCallbackInvocations = 0; int optionsCallbackInvocations = 0; @@ -66,8 +64,10 @@ public void LoggingBuilderAddOpenTelemetryConfigureActionTests(int numberOfOptio serviceCollection.AddLogging(configure => { - configure.AddOpenTelemetry(); // <- Just to verify this doesn't cause a throw. - configure.AddOpenTelemetry(ConfigureCallback); + for (int i = 0; i < numberOfBuilderRegistrations; i++) + { + configure.AddOpenTelemetry(ConfigureCallback); + } }); for (int i = 0; i < numberOfOptionsRegistrations; i++) @@ -75,17 +75,15 @@ public void LoggingBuilderAddOpenTelemetryConfigureActionTests(int numberOfOptio serviceCollection.Configure(OptionsCallback); } - Assert.NotNull(optionsInstance); - using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); - optionsInstance = null; - ILoggerFactory? loggerFactory = serviceProvider.GetService(); Assert.NotNull(loggerFactory); - Assert.Equal(1, configureCallbackInvocations); + Assert.NotNull(optionsInstance); + + Assert.Equal(numberOfBuilderRegistrations, configureCallbackInvocations); Assert.Equal(numberOfOptionsRegistrations, optionsCallbackInvocations); void ConfigureCallback(OpenTelemetryLoggerOptions options) @@ -96,8 +94,7 @@ void ConfigureCallback(OpenTelemetryLoggerOptions options) } else { - // Note: In the callback phase each options instance is unique - Assert.NotEqual(optionsInstance, options); + Assert.Equal(optionsInstance, options); } configureCallbackInvocations++; @@ -111,518 +108,10 @@ void OptionsCallback(OpenTelemetryLoggerOptions options) } else { - // Note: In the options phase each instance is the same Assert.Equal(optionsInstance, options); } optionsCallbackInvocations++; } } - - [Fact] - public void LoggingBuilderAddOpenTelemetryMultipleBuildersTest() - { - var serviceCollection = new ServiceCollection(); - - OpenTelemetryLoggerProvider? provider = null; - - serviceCollection.AddLogging(configure => - { - configure.AddOpenTelemetry(options - => options.ConfigureResource( - r => r.AddAttributes(new Dictionary() { ["key1"] = "value1" }))); - configure.AddOpenTelemetry(options - => options.ConfigureResource( - r => r.AddAttributes(new Dictionary() { ["key2"] = "value2" }))); - - configure.AddOpenTelemetry(options - => options.ConfigureProvider((sp, p) => provider = p)); - }); - - using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); - - var loggerFactory = serviceProvider.GetService(); - - Assert.NotNull(loggerFactory); - - Assert.NotNull(provider); - - Assert.Contains(provider!.Resource.Attributes, kvp => kvp.Key == "key1" && (string)kvp.Value == "value1"); - Assert.Contains(provider!.Resource.Attributes, kvp => kvp.Key == "key2" && (string)kvp.Value == "value2"); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryWithProviderTest() - { - var provider = new WrappedOpenTelemetryLoggerProvider(); - - var serviceCollection = new ServiceCollection(); - - serviceCollection.AddLogging(configure => - { - configure.AddOpenTelemetry(provider); - }); - - using (ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider()) - { - ILoggerFactory? loggerFactory = serviceProvider.GetService(); - - Assert.NotNull(loggerFactory); - - loggerFactory!.Dispose(); - - // Note: Provider disposal does not actually happen until serviceProvider is disposed - Assert.False(provider.Disposed); - } - - Assert.True(provider.Disposed); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void LoggingBuilderAddOpenTelemetryWithProviderAndDisposeSpecifiedTests(bool dispose) - { - var provider = new WrappedOpenTelemetryLoggerProvider(); - - var serviceCollection = new ServiceCollection(); - - serviceCollection.AddLogging(configure => - { - configure.AddOpenTelemetry(provider, disposeProvider: dispose); - }); - - using (ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider()) - { - ILoggerFactory? loggerFactory = serviceProvider.GetService(); - - Assert.NotNull(loggerFactory); - - loggerFactory!.Dispose(); - - // Note: Provider disposal does not actually happen until serviceProvider is disposed - Assert.False(provider.Disposed); - } - - Assert.Equal(dispose, provider.Disposed); - - provider.Dispose(); - - Assert.True(provider.Disposed); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void LoggerFactoryCreateAddOpenTelemetryWithProviderAndDisposeSpecifiedTests(bool dispose) - { - var provider = new WrappedOpenTelemetryLoggerProvider(); - - using (var factory = LoggerFactory.Create(configure => - { - configure.AddOpenTelemetry(provider, disposeProvider: dispose); - })) - { - Assert.False(provider.Disposed); - } - - Assert.Equal(dispose, provider.Disposed); - - provider.Dispose(); - - Assert.True(provider.Disposed); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryServicesAvailableTest() - { - int invocationCount = 0; - - var services = new ServiceCollection(); - - services.AddLogging(configure => - { - configure.AddOpenTelemetry(options => - { - invocationCount++; - Assert.NotNull(options.Services); - }); - }); - - services.Configure(options => - { - invocationCount++; - - // Note: Services are no longer available once OpenTelemetryLoggerOptions has been created - - Assert.Null(options.Services); - }); - - using var serviceProvider = services.BuildServiceProvider(); - - var loggerFactory = serviceProvider.GetRequiredService(); - - Assert.Equal(2, invocationCount); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryProcessorThroughDependencyTest() - { - CustomProcessor.InstanceCount = 0; - - var services = new ServiceCollection(); - - services.AddLogging(configure => - { - configure.AddOpenTelemetry(options => - { - options.AddProcessor(); - }); - }); - - CustomProcessor? customProcessor = null; - - using (var serviceProvider = services.BuildServiceProvider()) - { - var loggerFactory = serviceProvider.GetRequiredService(); - - customProcessor = serviceProvider.GetRequiredService(); - - Assert.NotNull(customProcessor); - - loggerFactory.Dispose(); - - Assert.False(customProcessor!.Disposed); - } - - Assert.True(customProcessor.Disposed); - - Assert.Equal(1, CustomProcessor.InstanceCount); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryConfigureCallbackTest() - { - var services = new ServiceCollection(); - - services.AddSingleton(); - - CustomProcessor? customProcessor = null; - - services.AddLogging(configure => - { - configure.AddOpenTelemetry(options => - { - options.ConfigureProvider((sp, provider) => - { - var testClass = sp.GetRequiredService(); - - customProcessor = new CustomProcessor - { - TestClass = testClass, - }; - - provider.AddProcessor(customProcessor); - }); - }); - }); - - using var serviceProvider = services.BuildServiceProvider(); - - var loggerFactory = serviceProvider.GetRequiredService(); - - Assert.NotNull(customProcessor?.TestClass); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryOptionsOrderingTest() - { - int configureInvocationCount = 0; - - var services = new ServiceCollection(); - - OpenTelemetryLoggerProvider? provider = null; - - services.Configure(options => - { - // Note: This will be applied first to the final options - options.IncludeFormattedMessage = true; - options.IncludeScopes = true; - options.ParseStateValues = true; - - options.AddProcessor(new CustomProcessor(0)); - - options.ConfigureProvider((sp, p) => - { - Assert.Null(provider); - provider = p; - configureInvocationCount++; - }); - }); - - services.AddLogging(configure => - { - configure.AddOpenTelemetry(options => - { - // Note: This will run first, but be applied second to the final options - options.IncludeFormattedMessage = false; - options.ParseStateValues = false; - - options.AddProcessor(new CustomProcessor(1)); - - options.ConfigureProvider((sp, p) => - { - configureInvocationCount++; - - Assert.NotNull(provider); - Assert.Equal(provider, p); - }); - }); - }); - - services.Configure(options => - { - // Note: This will be applied last to the final options - options.ParseStateValues = true; - - options.AddProcessor(new CustomProcessor(2)); - - options.ConfigureProvider((sp, p) => - { - configureInvocationCount++; - - Assert.NotNull(provider); - Assert.Equal(provider, p); - }); - }); - - using var serviceProvider = services.BuildServiceProvider(); - - var loggerFactory = serviceProvider.GetRequiredService(); - - Assert.NotNull(provider); - Assert.Equal(3, configureInvocationCount); - - var finalOptions = serviceProvider.GetRequiredService>().CurrentValue; - - Assert.False(finalOptions.IncludeFormattedMessage); - Assert.True(finalOptions.IncludeScopes); - Assert.True(finalOptions.ParseStateValues); - - var processor = provider!.Processor as CompositeProcessor; - - Assert.NotNull(processor); - - int count = 0; - var current = processor!.Head; - while (current != null) - { - var instance = current.Value as CustomProcessor; - Assert.Equal(count, instance?.Id); - - count++; - current = current.Next; - } - - Assert.Equal(3, count); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryResourceTest() - { - var services = new ServiceCollection(); - - OpenTelemetryLoggerProvider? provider = null; - - services.AddLogging(configure => - { - configure.AddOpenTelemetry(options => - { - options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Examples.LoggingExtensions")); - - options.ConfigureProvider((sp, p) => provider = p); - }); - }); - - services.Configure(options => - { - options.ConfigureResource(builder => builder.AddAttributes(new Dictionary { ["key1"] = "value1" })); - }); - - services.Configure(options => - { - options.ConfigureResource(builder => builder.AddAttributes(new Dictionary { ["key2"] = "value2" })); - }); - - using var serviceProvider = services.BuildServiceProvider(); - - var loggerFactory = serviceProvider.GetRequiredService(); - - Assert.NotNull(provider); - - var resource = provider!.Resource; - - Assert.NotNull(resource); - - Assert.Contains(resource.Attributes, kvp => kvp.Key == "service.name"); - Assert.Contains(resource.Attributes, kvp => kvp.Key == "service.instance.id"); - Assert.Contains(resource.Attributes, kvp => kvp.Key == "key1"); - Assert.Contains(resource.Attributes, kvp => kvp.Key == "key2"); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryAddExporterTest() - { - var builder = Sdk.CreateLoggerProviderBuilder(); - - builder.AddExporter(ExportProcessorType.Simple, new CustomExporter()); - builder.AddExporter(ExportProcessorType.Batch); - - using var provider = builder.Build(); - - Assert.NotNull(provider); - - var processor = provider.Processor as CompositeProcessor; - - Assert.NotNull(processor); - - var firstProcessor = processor!.Head.Value; - var secondProcessor = processor.Head.Next?.Value; - - Assert.True(firstProcessor is SimpleLogRecordExportProcessor simpleProcessor && simpleProcessor.Exporter is CustomExporter); - Assert.True(secondProcessor is BatchLogRecordExportProcessor batchProcessor && batchProcessor.Exporter is CustomExporter); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryAddExporterWithOptionsTest() - { - int optionsInvocations = 0; - - var builder = Sdk.CreateLoggerProviderBuilder(); - - builder.ConfigureServices(services => - { - services.Configure(options => - { - // Note: This is testing options integration - - optionsInvocations++; - - options.BatchExportProcessorOptions.MaxExportBatchSize = 18; - }); - }); - - builder.AddExporter( - ExportProcessorType.Simple, - new CustomExporter(), - options => - { - // Note: Options delegate isn't invoked for simple processor type - Assert.True(false); - }); - builder.AddExporter( - ExportProcessorType.Batch, - options => - { - optionsInvocations++; - - Assert.Equal(18, options.BatchExportProcessorOptions.MaxExportBatchSize); - - options.BatchExportProcessorOptions.MaxExportBatchSize = 100; - }); - - using var provider = builder.Build(); - - Assert.NotNull(provider); - - Assert.Equal(2, optionsInvocations); - - var processor = provider.Processor as CompositeProcessor; - - Assert.NotNull(processor); - - var firstProcessor = processor!.Head.Value; - var secondProcessor = processor.Head.Next?.Value; - - Assert.True(firstProcessor is SimpleLogRecordExportProcessor simpleProcessor && simpleProcessor.Exporter is CustomExporter); - Assert.True(secondProcessor is BatchLogRecordExportProcessor batchProcessor - && batchProcessor.Exporter is CustomExporter - && batchProcessor.MaxExportBatchSize == 100); - } - - [Fact] - public void LoggingBuilderAddOpenTelemetryAddExporterNamedOptionsTest() - { - var builder = Sdk.CreateLoggerProviderBuilder(); - - int defaultOptionsConfigureInvocations = 0; - int namedOptionsConfigureInvocations = 0; - - builder.ConfigureServices(services => - { - services.Configure(o => defaultOptionsConfigureInvocations++); - - services.Configure("Exporter2", o => namedOptionsConfigureInvocations++); - }); - - builder.AddExporter(ExportProcessorType.Batch, new CustomExporter()); - builder.AddExporter(ExportProcessorType.Batch, new CustomExporter(), name: "Exporter2", configure: null); - builder.AddExporter(ExportProcessorType.Batch); - builder.AddExporter(ExportProcessorType.Batch, name: "Exporter2", configure: null); - - using var provider = builder.Build(); - - Assert.NotNull(provider); - - Assert.Equal(1, defaultOptionsConfigureInvocations); - Assert.Equal(1, namedOptionsConfigureInvocations); - } - - private sealed class WrappedOpenTelemetryLoggerProvider : OpenTelemetryLoggerProvider - { - public bool Disposed { get; private set; } - - protected override void Dispose(bool disposing) - { - this.Disposed = true; - - base.Dispose(disposing); - } - } - - private sealed class CustomProcessor : BaseProcessor - { - public CustomProcessor(int? id = null) - { - this.Id = id; - InstanceCount++; - } - - public static int InstanceCount { get; set; } - - public int? Id { get; } - - public bool Disposed { get; private set; } - - public TestClass? TestClass { get; set; } - - protected override void Dispose(bool disposing) - { - this.Disposed = true; - - base.Dispose(disposing); - } - } - - private sealed class CustomExporter : BaseExporter - { - public override ExportResult Export(in Batch batch) - { - return ExportResult.Success; - } - } - - private sealed class TestClass - { - } }