diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/api/Azure.Monitor.OpenTelemetry.netstandard2.0.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/api/Azure.Monitor.OpenTelemetry.netstandard2.0.cs index 366486a8d398..6e8521ab45de 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/api/Azure.Monitor.OpenTelemetry.netstandard2.0.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/api/Azure.Monitor.OpenTelemetry.netstandard2.0.cs @@ -1,14 +1,14 @@ namespace Azure.Monitor.OpenTelemetry { - public static partial class AzureMonitorOpenTelemetryExtensions + public static partial class AzureMonitorExtensions { - public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitorOpenTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) { throw null; } - public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitorOpenTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Azure.Monitor.OpenTelemetry.AzureMonitorOpenTelemetryOptions options) { throw null; } - public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitorOpenTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureAzureMonitorOpenTelemetry) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Azure.Monitor.OpenTelemetry.AzureMonitorOptions options) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureAzureMonitor) { throw null; } } - public partial class AzureMonitorOpenTelemetryOptions + public partial class AzureMonitorOptions { - public AzureMonitorOpenTelemetryOptions() { } + public AzureMonitorOptions() { } public string ConnectionString { get { throw null; } set { } } public Azure.Core.TokenCredential Credential { get { throw null; } set { } } public bool DisableOfflineStorage { get { throw null; } set { } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorExtensions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorExtensions.cs new file mode 100644 index 000000000000..c3e4fd15269b --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorExtensions.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Options; + +namespace Azure.Monitor.OpenTelemetry +{ + /// + /// Extension methods for setting up Azure Monitor in an . + /// + public static class AzureMonitorExtensions + { + /// + /// Adds Azure Monitor into service collection. + /// + /// The to add services to. + /// The so that additional calls can be chained. + public static IServiceCollection AddAzureMonitor(this IServiceCollection services) + { + services.TryAddSingleton, + DefaultAzureMonitorOptions>(); + return services.AddAzureMonitor(o => o = new AzureMonitorOptions()); + } + + /// + /// Adds Azure Monitor into service collection. + /// + /// The to add services to. + /// The instance for configuration. + /// The so that additional calls can be chained. + public static IServiceCollection AddAzureMonitor(this IServiceCollection services, AzureMonitorOptions options) + { + options ??= new AzureMonitorOptions(); + return services.AddAzureMonitor(o => o.Clone(options)); + } + + /// + /// Adds Azure Monitor into service collection. + /// + /// . + /// Callback action for configuring . + /// . + public static IServiceCollection AddAzureMonitor(this IServiceCollection services, Action configureAzureMonitor) + { + return AzureMonitorImplementations.AddAzureMonitorWithAction(services, configureAzureMonitor); + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryImplementations.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorImplementations.cs similarity index 89% rename from sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryImplementations.cs rename to sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorImplementations.cs index d48ba333d37b..33db1d3a910e 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryImplementations.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorImplementations.cs @@ -12,18 +12,18 @@ namespace Azure.Monitor.OpenTelemetry { - internal class AzureMonitorOpenTelemetryImplementations + internal class AzureMonitorImplementations { - internal static IServiceCollection AddAzureMonitorOpenTelemetryWithAction(IServiceCollection services, Action configureAzureMonitorOpenTelemetry) + internal static IServiceCollection AddAzureMonitorWithAction(IServiceCollection services, Action configureAzureMonitor) { if (services == null) { throw new ArgumentNullException(nameof(services)); } - if (configureAzureMonitorOpenTelemetry != null) + if (configureAzureMonitor != null) { - services.Configure(configureAzureMonitorOpenTelemetry); + services.Configure(configureAzureMonitor); } var builder = services.AddOpenTelemetry(); @@ -42,10 +42,10 @@ internal static IServiceCollection AddAzureMonitorOpenTelemetryWithAction(IServi services.AddLogging(logging => { - AzureMonitorOpenTelemetryOptions logExporterOptions = new(); - if (configureAzureMonitorOpenTelemetry != null) + AzureMonitorOptions logExporterOptions = new(); + if (configureAzureMonitor != null) { - configureAzureMonitorOpenTelemetry(logExporterOptions); + configureAzureMonitor(logExporterOptions); } if (logExporterOptions.EnableLogs) @@ -95,7 +95,7 @@ internal static IServiceCollection AddAzureMonitorOpenTelemetryWithAction(IServi services.AddSingleton(sp => { - var options = sp.GetRequiredService>().Get(""); + var options = sp.GetRequiredService>().Get(""); if (!options.EnableTraces) { return new NoopTracerProvider(); @@ -111,7 +111,7 @@ internal static IServiceCollection AddAzureMonitorOpenTelemetryWithAction(IServi services.AddSingleton(sp => { - var options = sp.GetRequiredService>().Get(""); + var options = sp.GetRequiredService>().Get(""); if (!options.EnableMetrics) { return new NoopMeterProvider(); diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryExtensions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryExtensions.cs deleted file mode 100644 index d6e7f3cb0809..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryExtensions.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; - -namespace Azure.Monitor.OpenTelemetry -{ - /// - /// Extension methods for setting up Azure Monitor OpenTelemetry in an . - /// - public static class AzureMonitorOpenTelemetryExtensions - { - /// - /// Adds Azure Monitor OpenTelemetry into service collection. - /// - /// The to add services to. - /// The so that additional calls can be chained. - public static IServiceCollection AddAzureMonitorOpenTelemetry(this IServiceCollection services) - { - services.TryAddSingleton, - DefaultAzureMonitorOpenTelemetryOptions>(); - return services.AddAzureMonitorOpenTelemetry(o => o = new AzureMonitorOpenTelemetryOptions()); - } - - /// - /// Adds Azure Monitor OpenTelemetry into service collection. - /// - /// The to add services to. - /// The instance for configuration. - /// The so that additional calls can be chained. - public static IServiceCollection AddAzureMonitorOpenTelemetry(this IServiceCollection services, AzureMonitorOpenTelemetryOptions options) - { - options ??= new AzureMonitorOpenTelemetryOptions(); - return services.AddAzureMonitorOpenTelemetry(o => o.Clone(options)); - } - - /// - /// Adds Azure Monitor OpenTelemetry into service collection. - /// - /// . - /// Callback action for configuring . - /// . - public static IServiceCollection AddAzureMonitorOpenTelemetry(this IServiceCollection services, Action configureAzureMonitorOpenTelemetry) - { - return AzureMonitorOpenTelemetryImplementations.AddAzureMonitorOpenTelemetryWithAction(services, configureAzureMonitorOpenTelemetry); - } - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryOptions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOptions.cs similarity index 93% rename from sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryOptions.cs rename to sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOptions.cs index fecf93422274..2d9f8f63c000 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOpenTelemetryOptions.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/AzureMonitorOptions.cs @@ -12,9 +12,9 @@ namespace Azure.Monitor.OpenTelemetry { /// - /// Options that allow users to configure the Azure Monitor OpenTelemetry. + /// Options that allow users to configure the Azure Monitor. /// - public class AzureMonitorOpenTelemetryOptions + public class AzureMonitorOptions { /// /// The Connection String provides users with a single configuration setting to identify the Azure Monitor resource and endpoint. @@ -59,7 +59,7 @@ public class AzureMonitorOpenTelemetryOptions /// public string StorageDirectory { get; set; } - internal AzureMonitorOpenTelemetryOptions Clone(AzureMonitorOpenTelemetryOptions options) + internal AzureMonitorOptions Clone(AzureMonitorOptions options) { if (options != null) { diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/DefaultAzureMonitorOpenTelemetryOptions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/DefaultAzureMonitorOptions.cs similarity index 62% rename from sdk/monitor/Azure.Monitor.OpenTelemetry/src/DefaultAzureMonitorOpenTelemetryOptions.cs rename to sdk/monitor/Azure.Monitor.OpenTelemetry/src/DefaultAzureMonitorOptions.cs index e832d8eef0fc..c3277eafefa8 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/src/DefaultAzureMonitorOpenTelemetryOptions.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/src/DefaultAzureMonitorOptions.cs @@ -7,26 +7,26 @@ namespace Azure.Monitor.OpenTelemetry { - internal class DefaultAzureMonitorOpenTelemetryOptions : IConfigureOptions + internal class DefaultAzureMonitorOptions : IConfigureOptions { - private const string AzureMonitorOpenTelemetrySectionFromConfig = "AzureMonitorOpenTelemetry"; + private const string AzureMonitorSectionFromConfig = "AzureMonitor"; private const string ConnectionStringEnvironmentVariable = "APPLICATIONINSIGHTS_CONNECTION_STRING"; private readonly IConfiguration? _configuration; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// from which configuration for ApplicationInsights can be retrieved. - public DefaultAzureMonitorOpenTelemetryOptions(IConfiguration? configuration = null) + /// from which configuration for Azure Monitor can be retrieved. + public DefaultAzureMonitorOptions(IConfiguration? configuration = null) { _configuration = configuration; } - public void Configure(AzureMonitorOpenTelemetryOptions options) + public void Configure(AzureMonitorOptions options) { if (_configuration != null) { - _configuration.GetSection(AzureMonitorOpenTelemetrySectionFromConfig).Bind(options); + _configuration.GetSection(AzureMonitorSectionFromConfig).Bind(options); } string connectionString = Environment.GetEnvironmentVariable(ConnectionStringEnvironmentVariable); diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/Program.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/Program.cs index ee8f9634c068..4cd33155393e 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/Program.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/Program.cs @@ -11,9 +11,9 @@ var builder = WebApplication.CreateBuilder(args); -builder.Services.AddAzureMonitorOpenTelemetry(); +builder.Services.AddAzureMonitor(); /* -builder.Services.AddAzureMonitorOpenTelemetry(o => +builder.Services.AddAzureMonitor(o => { o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000"; // Set the Credential property to enable AAD based authentication: @@ -24,7 +24,7 @@ // To customize sampling, Set ApplicationInsightsSampler to desired sampling ratio and // configure with OpenTelemetryTracerProvider. // Please note that ConfigureOpenTelemetryTracerProvider should be called after -// builder.Services.AddAzureMonitorOpenTelemetry(). +// builder.Services.AddAzureMonitor(). builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.SetSampler(new ApplicationInsightsSampler(0.9F))); var app = builder.Build(); diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/appsettings.json b/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/appsettings.json index 39f22ca37057..32e0abd784c1 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/appsettings.json +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/appsettings.json @@ -1,5 +1,5 @@ { - "AzureMonitorOpenTelemetry": { + "AzureMonitor": { "ConnectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000123" } }