From bed969f492c1726526950feb25ff8f95531b3480 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 2 Jul 2024 14:20:38 +0200 Subject: [PATCH 1/4] Initial version of an Auto Instrumentation Plugin --- Elastic.OpenTelemetry.sln | 7 ++ .../Example.AspNetCore.Mvc.csproj | 2 +- .../Example.Console/Example.Console.csproj | 4 +- .../Example.MinimalApi.csproj | 2 +- .../Example.WorkerService.csproj | 2 +- .../ServiceDefaults/ServiceDefaults.csproj | 14 ++-- ...Telemetry.AutoInstrumentationPlugin.csproj | 17 +++++ .../ElasticAutoInstrumentationPlugin.cs | 67 ++++++++++++++++++ .../Elastic.OpenTelemetry.csproj | 16 ++--- .../ElasticOpenTelemetryBuilder.cs | 70 ++++++++----------- .../MeterProviderBuilderExtensions.cs | 30 ++++++++ .../OpenTelemetryBuilderExtensions.cs | 1 + .../OpenTelemetryLoggerOptionsExtensions.cs | 26 +++++++ .../Extensions/ResourceBuilderExtensions.cs | 12 ++-- .../TracerProviderBuilderExtensions.cs | 19 ++++- .../Elastic.OpenTelemetry.Tests.csproj | 2 +- 16 files changed, 218 insertions(+), 73 deletions(-) create mode 100644 src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj create mode 100644 src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs create mode 100644 src/Elastic.OpenTelemetry/Extensions/MeterProviderBuilderExtensions.cs create mode 100644 src/Elastic.OpenTelemetry/Extensions/OpenTelemetryLoggerOptionsExtensions.cs diff --git a/Elastic.OpenTelemetry.sln b/Elastic.OpenTelemetry.sln index 0a81329..cba35c0 100644 --- a/Elastic.OpenTelemetry.sln +++ b/Elastic.OpenTelemetry.sln @@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppHost", "examples\AppHost EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDefaults", "examples\ServiceDefaults\ServiceDefaults.csproj", "{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.OpenTelemetry.AutoInstrumentationPlugin", "src\Elastic.OpenTelemetry.AutoInstrumentationPlugin\Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj", "{B61D749B-21E5-430D-B50D-CA02EBAA7F2F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -95,6 +97,10 @@ Global {A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU {A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU {A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Release|Any CPU.Build.0 = Release|Any CPU + {B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -109,6 +115,7 @@ Global {863CAB86-5EB0-4E9F-B01D-F51687EC6597} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9} {206203BD-3EBA-4E9A-8881-1189D95AB037} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9} {A3D1ED4D-863B-45D7-9829-305DD33B4CE5} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9} + {B61D749B-21E5-430D-B50D-CA02EBAA7F2F} = {E622CFF2-C6C4-40FB-BE42-7C4F2B38B75A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {573B2B5F-8CBB-4D52-A55A-4E65E282AAFB} diff --git a/examples/Example.AspNetCore.Mvc/Example.AspNetCore.Mvc.csproj b/examples/Example.AspNetCore.Mvc/Example.AspNetCore.Mvc.csproj index 4206dfe..ac48547 100644 --- a/examples/Example.AspNetCore.Mvc/Example.AspNetCore.Mvc.csproj +++ b/examples/Example.AspNetCore.Mvc/Example.AspNetCore.Mvc.csproj @@ -12,7 +12,7 @@ - + diff --git a/examples/Example.Console/Example.Console.csproj b/examples/Example.Console/Example.Console.csproj index ac8c462..ff660d3 100644 --- a/examples/Example.Console/Example.Console.csproj +++ b/examples/Example.Console/Example.Console.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/examples/Example.MinimalApi/Example.MinimalApi.csproj b/examples/Example.MinimalApi/Example.MinimalApi.csproj index dd8647f..11c4254 100644 --- a/examples/Example.MinimalApi/Example.MinimalApi.csproj +++ b/examples/Example.MinimalApi/Example.MinimalApi.csproj @@ -12,7 +12,7 @@ - + diff --git a/examples/Example.WorkerService/Example.WorkerService.csproj b/examples/Example.WorkerService/Example.WorkerService.csproj index 47936dc..6838c59 100644 --- a/examples/Example.WorkerService/Example.WorkerService.csproj +++ b/examples/Example.WorkerService/Example.WorkerService.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/ServiceDefaults/ServiceDefaults.csproj b/examples/ServiceDefaults/ServiceDefaults.csproj index ff7dc92..766d807 100644 --- a/examples/ServiceDefaults/ServiceDefaults.csproj +++ b/examples/ServiceDefaults/ServiceDefaults.csproj @@ -12,13 +12,13 @@ - - - - - - - + + + + + + + diff --git a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj new file mode 100644 index 0000000..8faa871 --- /dev/null +++ b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.0;netstandard2.1;net8.0;net6.0;net462 + net8.0 + enable + enable + + + + + + + + + + diff --git a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs new file mode 100644 index 0000000..ae2a644 --- /dev/null +++ b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs @@ -0,0 +1,67 @@ +using System.Diagnostics.Tracing; +using Elastic.OpenTelemetry.Configuration; +using Elastic.OpenTelemetry.Extensions; +using Microsoft.Extensions.Logging; +using OpenTelemetry.Logs; +using OpenTelemetry.Metrics; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; + +namespace Elastic.OpenTelemetry.AutoInstrumentationPlugin; + +/// +/// Elastic Distribution for OpenTelemetry .NET plugin for Auto Instrumentation. +/// Ensures all signals are rich enough to report to Elastic +/// +// ReSharper disable once UnusedType.Global +public class ElasticAutoInstrumentationPlugin +{ + private readonly ILogger _logger; + private readonly EventListener _eventListener; + + /// + public ElasticAutoInstrumentationPlugin() + { + var options = new ElasticOpenTelemetryBuilderOptions(); + var (eventListener, logger) = ElasticOpenTelemetryBuilder.Bootstrap(options); + + _logger = logger; + _eventListener= eventListener; + } + + /// To access TracerProvider right after TracerProviderBuilder.Build() is executed. + public void TracerProviderInitialized(TracerProvider tracerProvider) + { + } + + /// To access MeterProvider right after MeterProviderBuilder.Build() is executed. + public void MeterProviderInitialized(MeterProvider meterProvider) + { + } + + /// To configure tracing SDK before Auto Instrumentation configured SDK + public TracerProviderBuilder BeforeConfigureTracerProvider(TracerProviderBuilder builder) => + builder.UseElasticDefaults(_logger); + + + /// To configure tracing SDK after Auto Instrumentation configured SDK + public TracerProviderBuilder AfterConfigureTracerProvider(TracerProviderBuilder builder) => + builder; + + /// To configure metrics SDK before Auto Instrumentation configured SDK + public MeterProviderBuilder BeforeConfigureMeterProvider(MeterProviderBuilder builder) => + builder.UseElasticDefaults(_logger); + + /// To configure metrics SDK after Auto Instrumentation configured SDK + public MeterProviderBuilder AfterConfigureMeterProvider(MeterProviderBuilder builder) => + builder; + + + /// To configure logs SDK (the method name is the same as for other logs options) + public void ConfigureLogsOptions(OpenTelemetryLoggerOptions options) => + options.UseElasticDefaults(_logger); + + /// To configure Resource + public ResourceBuilder ConfigureResource(ResourceBuilder builder) => + builder.UseElasticDefaults(_logger); +} diff --git a/src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj b/src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj index 2d1cb20..d0a6200 100644 --- a/src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj +++ b/src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj @@ -18,14 +18,14 @@ - - - - - - - - + + + + + + + + diff --git a/src/Elastic.OpenTelemetry/ElasticOpenTelemetryBuilder.cs b/src/Elastic.OpenTelemetry/ElasticOpenTelemetryBuilder.cs index a082965..751a9ff 100644 --- a/src/Elastic.OpenTelemetry/ElasticOpenTelemetryBuilder.cs +++ b/src/Elastic.OpenTelemetry/ElasticOpenTelemetryBuilder.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using System.Diagnostics; +using System.Diagnostics.Tracing; using Elastic.OpenTelemetry.Configuration; using Elastic.OpenTelemetry.Diagnostics; using Elastic.OpenTelemetry.Diagnostics.Logging; @@ -48,6 +49,23 @@ public class ElasticOpenTelemetryBuilder : IOpenTelemetryBuilder /// public IServiceCollection Services { get; } + /// + /// Shared bootstrap routine for the Elastic OpenTelemetry Distribution. + /// Used to ensure auto instrumentation and manual instrumentation bootstrap the same way. + /// + public static (EventListener, ILogger) Bootstrap(ElasticOpenTelemetryBuilderOptions options) + { + var logger = new CompositeLogger(options); + + // Enables logging of OpenTelemetry-SDK event source events + var eventListener = new LoggingEventListener(logger, options.DistroOptions); + + logger.LogAgentPreamble(); + logger.LogElasticOpenTelemetryBuilderInitialized(Environment.NewLine, new StackTrace(true)); + options.DistroOptions.LogConfigSources(logger); + return (eventListener, logger); + } + /// /// Creates an instance of the configured with default options. /// @@ -61,14 +79,10 @@ public ElasticOpenTelemetryBuilder() /// public ElasticOpenTelemetryBuilder(ElasticOpenTelemetryBuilderOptions options) { - Logger = new CompositeLogger(options); + var (eventListener, logger) = Bootstrap(options); - // Enables logging of OpenTelemetry-SDK event source events - EventListener = new LoggingEventListener(Logger, options.DistroOptions); - - Logger.LogAgentPreamble(); - Logger.LogElasticOpenTelemetryBuilderInitialized(Environment.NewLine, new StackTrace(true)); - options.DistroOptions.LogConfigSources(Logger); + Logger = (CompositeLogger)logger; + EventListener = (LoggingEventListener)eventListener; Services = options.Services ?? new ServiceCollection(); @@ -81,6 +95,9 @@ public ElasticOpenTelemetryBuilder(ElasticOpenTelemetryBuilderOptions options) var openTelemetry = Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetry(Services); + // We always add this so we can identify a distro is being used, even if all Elastic defaults are disabled. + openTelemetry.ConfigureResource(r => r.UseElasticDefaults()); + if (options.DistroOptions.EnabledDefaults.Equals(ElasticOpenTelemetryOptions.EnabledElasticDefaults.None)) { Logger.LogNoElasticDefaults(); @@ -90,7 +107,7 @@ public ElasticOpenTelemetryBuilder(ElasticOpenTelemetryBuilderOptions options) return; } - openTelemetry.ConfigureResource(r => r.AddElasticResourceDefaults(Logger)); + openTelemetry.ConfigureResource(r => r.UseElasticDefaults(Logger)); //https://github.com/open-telemetry/opentelemetry-dotnet/pull/5400 if (!options.DistroOptions.SkipOtlpExporter) @@ -98,44 +115,15 @@ public ElasticOpenTelemetryBuilder(ElasticOpenTelemetryBuilderOptions options) if (options.DistroOptions.EnabledDefaults.HasFlag(ElasticOpenTelemetryOptions.EnabledElasticDefaults.Logging)) { - // TODO: Move to WithLogging once it gets stable. - Services.Configure(logging => - { - logging.IncludeFormattedMessage = true; - logging.IncludeScopes = true; - }); - - // Note: We use this log method for now as the WithLogging method is not yet stable. - Logger.LogConfiguredSignalProvider("logging", nameof(OpenTelemetryLoggerOptions)); + //TODO Move to WithLogging once it gets stable + Services.Configure(logging => logging.UseElasticDefaults()); } if (options.DistroOptions.EnabledDefaults.HasFlag(ElasticOpenTelemetryOptions.EnabledElasticDefaults.Tracing)) - { - openTelemetry.WithTracing(tracing => - { - tracing - .AddHttpClientInstrumentation() - .AddGrpcClientInstrumentation() - .AddEntityFrameworkCoreInstrumentation(); - - tracing.AddElasticProcessors(Logger); - }); - - Logger.LogConfiguredSignalProvider("tracing", nameof(TracerProviderBuilder)); - } + openTelemetry.WithTracing(tracing => tracing.UseElasticDefaults(Logger)); if (options.DistroOptions.EnabledDefaults.HasFlag(ElasticOpenTelemetryOptions.EnabledElasticDefaults.Metrics)) - { - openTelemetry.WithMetrics(metrics => - { - metrics - .AddProcessInstrumentation() - .AddRuntimeInstrumentation() - .AddHttpClientInstrumentation(); - - Logger.LogConfiguredSignalProvider("metrics", nameof(MeterProviderBuilder)); - }); - } + openTelemetry.WithMetrics(metrics => metrics.UseElasticDefaults(Logger)); } } diff --git a/src/Elastic.OpenTelemetry/Extensions/MeterProviderBuilderExtensions.cs b/src/Elastic.OpenTelemetry/Extensions/MeterProviderBuilderExtensions.cs new file mode 100644 index 0000000..4be5dd6 --- /dev/null +++ b/src/Elastic.OpenTelemetry/Extensions/MeterProviderBuilderExtensions.cs @@ -0,0 +1,30 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using OpenTelemetry.Metrics; + +namespace Elastic.OpenTelemetry.Extensions; + +/// +/// Elastic extensions for . +/// +public static class MeterProviderBuilderExtensions +{ + /// Use Elastic distribution defaults for + public static MeterProviderBuilder UseElasticDefaults(this MeterProviderBuilder builder, ILogger? logger = null) + { + logger ??= NullLogger.Instance; + + builder + .AddProcessInstrumentation() + .AddRuntimeInstrumentation() + .AddHttpClientInstrumentation(); + + logger.LogConfiguredSignalProvider("metrics", nameof(MeterProviderBuilder)); + + return builder; + } +} diff --git a/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryBuilderExtensions.cs b/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryBuilderExtensions.cs index b9ea121..f472a93 100644 --- a/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryBuilderExtensions.cs +++ b/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryBuilderExtensions.cs @@ -2,6 +2,7 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using Elastic.OpenTelemetry.Diagnostics.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using OpenTelemetry; diff --git a/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryLoggerOptionsExtensions.cs b/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryLoggerOptionsExtensions.cs new file mode 100644 index 0000000..e0b8ac0 --- /dev/null +++ b/src/Elastic.OpenTelemetry/Extensions/OpenTelemetryLoggerOptionsExtensions.cs @@ -0,0 +1,26 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using OpenTelemetry.Logs; + +namespace Elastic.OpenTelemetry.Extensions; + +/// +/// Elastic extensions for . +/// +public static class OpenTelemetryLoggerOptionsExtensions +{ + /// + /// Ensures Elastic distro options are set for + /// + public static void UseElasticDefaults(this OpenTelemetryLoggerOptions options, ILogger? logger = null) + { + logger ??= NullLogger.Instance; + options.IncludeFormattedMessage = true; + options.IncludeScopes = true; + logger.LogConfiguredSignalProvider("logging", nameof(OpenTelemetryLoggerOptions)); + } +} diff --git a/src/Elastic.OpenTelemetry/Extensions/ResourceBuilderExtensions.cs b/src/Elastic.OpenTelemetry/Extensions/ResourceBuilderExtensions.cs index 3c4f817..651c730 100644 --- a/src/Elastic.OpenTelemetry/Extensions/ResourceBuilderExtensions.cs +++ b/src/Elastic.OpenTelemetry/Extensions/ResourceBuilderExtensions.cs @@ -38,21 +38,19 @@ public static class ResourceBuilderExtensions /// resource configuration. /// /// A that will be configured with Elastic defaults. + /// Optionally provide a logger to log to /// The for chaining calls. - public static ResourceBuilder AddElasticResourceDefaults(this ResourceBuilder builder) => - builder.AddElasticResourceDefaults(NullLogger.Instance); - - internal static ResourceBuilder AddElasticResourceDefaults(this ResourceBuilder builder, ILogger logger) + public static ResourceBuilder UseElasticDefaults(this ResourceBuilder builder, ILogger? logger = null) { + // ReSharper disable once RedundantAssignment + logger ??= NullLogger.Instance; var defaultServiceName = "unknown_service"; try { var processName = Process.GetCurrentProcess().ProcessName; if (!string.IsNullOrWhiteSpace(processName)) - { defaultServiceName = $"{defaultServiceName}:{processName}"; - } } catch { @@ -70,9 +68,7 @@ internal static ResourceBuilder AddElasticResourceDefaults(this ResourceBuilder .AddDistroAttributes() .AddEnvironmentVariableDetector(); -#if NET462_OR_GREATER || NET6_0_OR_GREATER builder.AddDetector(new HostDetector(logger)); -#endif return builder; } diff --git a/src/Elastic.OpenTelemetry/Extensions/TracerProviderBuilderExtensions.cs b/src/Elastic.OpenTelemetry/Extensions/TracerProviderBuilderExtensions.cs index 080e943..6db8a08 100644 --- a/src/Elastic.OpenTelemetry/Extensions/TracerProviderBuilderExtensions.cs +++ b/src/Elastic.OpenTelemetry/Extensions/TracerProviderBuilderExtensions.cs @@ -12,9 +12,7 @@ namespace Elastic.OpenTelemetry.Extensions; -/// -/// Elastic extensions for . -/// +/// Elastic extensions for . public static class TracerProviderBuilderExtensions { /// @@ -34,4 +32,19 @@ private static TracerProviderBuilder LogAndAddProcessor(this TracerProviderBuild logger.LogProcessorAdded(processor.GetType().ToString(), builder.GetType().Name); return builder.AddProcessor(processor); } + + /// Use Elastic distribution defaults for + public static TracerProviderBuilder UseElasticDefaults(this TracerProviderBuilder builder, ILogger? logger = null) + { + logger ??= NullLogger.Instance; + + builder + .AddHttpClientInstrumentation() + .AddGrpcClientInstrumentation() + .AddEntityFrameworkCoreInstrumentation(); + + builder.AddElasticProcessors(logger); + logger.LogConfiguredSignalProvider("tracing", nameof(TracerProviderBuilder)); + return builder; + } } diff --git a/tests/Elastic.OpenTelemetry.Tests/Elastic.OpenTelemetry.Tests.csproj b/tests/Elastic.OpenTelemetry.Tests/Elastic.OpenTelemetry.Tests.csproj index dd39f24..af48afc 100644 --- a/tests/Elastic.OpenTelemetry.Tests/Elastic.OpenTelemetry.Tests.csproj +++ b/tests/Elastic.OpenTelemetry.Tests/Elastic.OpenTelemetry.Tests.csproj @@ -11,7 +11,7 @@ - + From da3bba48cf88579a328e8fe00708f59ba8932d14 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 2 Jul 2024 14:22:41 +0200 Subject: [PATCH 2/4] do not package plugin for now --- .../Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj index 8faa871..0f457b7 100644 --- a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj +++ b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj @@ -5,6 +5,7 @@ net8.0 enable enable + False From 77033bafcb54bd50be95572ea517668b8dfb7b57 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 2 Jul 2024 14:24:36 +0200 Subject: [PATCH 3/4] formatting --- .../ElasticAutoInstrumentationPlugin.cs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs index ae2a644..846a43b 100644 --- a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs +++ b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.Tracing; +using System.Diagnostics.Tracing; using Elastic.OpenTelemetry.Configuration; using Elastic.OpenTelemetry.Extensions; using Microsoft.Extensions.Logging; @@ -20,48 +20,48 @@ public class ElasticAutoInstrumentationPlugin private readonly EventListener _eventListener; /// - public ElasticAutoInstrumentationPlugin() + public ElasticAutoInstrumentationPlugin() { var options = new ElasticOpenTelemetryBuilderOptions(); var (eventListener, logger) = ElasticOpenTelemetryBuilder.Bootstrap(options); _logger = logger; - _eventListener= eventListener; - } + _eventListener = eventListener; + } - /// To access TracerProvider right after TracerProviderBuilder.Build() is executed. - public void TracerProviderInitialized(TracerProvider tracerProvider) - { - } + /// To access TracerProvider right after TracerProviderBuilder.Build() is executed. + public void TracerProviderInitialized(TracerProvider tracerProvider) + { + } - /// To access MeterProvider right after MeterProviderBuilder.Build() is executed. - public void MeterProviderInitialized(MeterProvider meterProvider) - { - } + /// To access MeterProvider right after MeterProviderBuilder.Build() is executed. + public void MeterProviderInitialized(MeterProvider meterProvider) + { + } - /// To configure tracing SDK before Auto Instrumentation configured SDK - public TracerProviderBuilder BeforeConfigureTracerProvider(TracerProviderBuilder builder) => + /// To configure tracing SDK before Auto Instrumentation configured SDK + public TracerProviderBuilder BeforeConfigureTracerProvider(TracerProviderBuilder builder) => builder.UseElasticDefaults(_logger); /// To configure tracing SDK after Auto Instrumentation configured SDK - public TracerProviderBuilder AfterConfigureTracerProvider(TracerProviderBuilder builder) => + public TracerProviderBuilder AfterConfigureTracerProvider(TracerProviderBuilder builder) => builder; - /// To configure metrics SDK before Auto Instrumentation configured SDK - public MeterProviderBuilder BeforeConfigureMeterProvider(MeterProviderBuilder builder) => + /// To configure metrics SDK before Auto Instrumentation configured SDK + public MeterProviderBuilder BeforeConfigureMeterProvider(MeterProviderBuilder builder) => builder.UseElasticDefaults(_logger); /// To configure metrics SDK after Auto Instrumentation configured SDK - public MeterProviderBuilder AfterConfigureMeterProvider(MeterProviderBuilder builder) => + public MeterProviderBuilder AfterConfigureMeterProvider(MeterProviderBuilder builder) => builder; - /// To configure logs SDK (the method name is the same as for other logs options) - public void ConfigureLogsOptions(OpenTelemetryLoggerOptions options) => + /// To configure logs SDK (the method name is the same as for other logs options) + public void ConfigureLogsOptions(OpenTelemetryLoggerOptions options) => options.UseElasticDefaults(_logger); /// To configure Resource - public ResourceBuilder ConfigureResource(ResourceBuilder builder) => + public ResourceBuilder ConfigureResource(ResourceBuilder builder) => builder.UseElasticDefaults(_logger); } From 90e8e4651591724cf0c0ac1ab7fd72aff3c4529f Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 2 Jul 2024 14:27:51 +0200 Subject: [PATCH 4/4] license header --- .../ElasticAutoInstrumentationPlugin.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs index 846a43b..d5f78d4 100644 --- a/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs +++ b/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/ElasticAutoInstrumentationPlugin.cs @@ -1,3 +1,7 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + using System.Diagnostics.Tracing; using Elastic.OpenTelemetry.Configuration; using Elastic.OpenTelemetry.Extensions;