Skip to content

Commit

Permalink
[AzureMonitorDistro] New Public API for Azure Monitor Distro (Azure#3…
Browse files Browse the repository at this point in the history
…5250)

* New Public API for Azure Monitor Distro.

* Update Readme
  • Loading branch information
rajkumar-rangaraj authored Mar 30, 2023
1 parent fa13e7e commit d0eb2bb
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

### Features Added

* Added new public APIs `Services.AddOpenTelemetry().WithAzureMonitor()` and `Services.AddOpenTelemetry().WithAzureMonitor(Action<AzureMonitorOptions> configureAzureMonitor)`.

### Breaking Changes

* Removed public APIs `Services.AddAzureMonitor()`, `Services.AddAzureMonitor(AzureMonitorOptions options)` and `Services.AddAzureMonitor(Action<AzureMonitorOptions> configureAzureMonitor)`.

### Bugs Fixed

### Other Changes
Expand All @@ -14,7 +18,7 @@

### Other Changes

- Upgraded dependent `Azure.Core` to `1.30.0` due to an [issue in `ArrayBackedPropertyBag`](https://github.com/Azure/azure-sdk-for-net/pull/34800) in `Azure.Core` version `1.29.0`.
* Upgraded dependent `Azure.Core` to `1.30.0` due to an [issue in `ArrayBackedPropertyBag`](https://github.com/Azure/azure-sdk-for-net/pull/34800) in `Azure.Core` version `1.29.0`.

## 1.0.0-beta.1 (2023-03-07)

Expand Down
8 changes: 4 additions & 4 deletions sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To enable Azure Monitor Distro, add `AddAzureMonitor()` to your `Program.cs` fil
var builder = WebApplication.CreateBuilder(args);

// The following line enables Azure Monitor Distro.
builder.Services.AddAzureMonitor();
builder.Services.AddOpenTelemetry().WithAzureMonitor();

// This code adds other services for your application.
builder.Services.AddMvc();
Expand All @@ -55,7 +55,7 @@ To enable Azure Monitor Distro with a hard-coded connection string, add `AddAzur
var builder = WebApplication.CreateBuilder(args);

// The following line enables Azure Monitor Distro with hard-coded connection string.
builder.Services.AddAzureMonitor(o => o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");
builder.Services.AddOpenTelemetry().WithAzureMonitor(o => o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");

// This code adds other services for your application.
builder.Services.AddMvc();
Expand All @@ -70,8 +70,8 @@ Note that in the examples above, `AddAzureMonitor` is added to the `IServiceColl
Azure Active Directory (AAD) authentication is an optional feature that can be used with Azure Monitor Distro. To enable AAD authentication, set the `Credential` property in `AzureMonitorOptions`. This is made easy with the [Azure Identity library](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity/README.md), which provides support for authenticating Azure SDK clients with their corresponding Azure services.

```C#
// Call AddAzureMonitor and set Credential to authenticate through Active Directory.
builder.Services.AddAzureMonitor(o =>
// Call WithAzureMonitor and set Credential to authenticate through Active Directory.
builder.Services.AddOpenTelemetry().WithAzureMonitor(o =>
{
o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
o.Credential = new DefaultAzureCredential();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
namespace Azure.Monitor.OpenTelemetry.AspNetCore
{
public static partial class AzureMonitorExtensions
{
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.AspNetCore.AzureMonitorOptions options) { throw null; }
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAzureMonitor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Azure.Monitor.OpenTelemetry.AspNetCore.AzureMonitorOptions> configureAzureMonitor) { throw null; }
}
public partial class AzureMonitorOptions
public partial class AzureMonitorOptions : Azure.Core.ClientOptions
{
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 { } }
public bool EnableLogs { get { throw null; } set { } }
public bool EnableMetrics { get { throw null; } set { } }
public bool EnableTraces { get { throw null; } set { } }
public string StorageDirectory { get { throw null; } set { } }
}
public static partial class OpenTelemetryBuilderExtensions
{
public static OpenTelemetry.OpenTelemetryBuilder WithAzureMonitor(this OpenTelemetry.OpenTelemetryBuilder builder) { throw null; }
public static OpenTelemetry.OpenTelemetryBuilder WithAzureMonitor(this OpenTelemetry.OpenTelemetryBuilder builder, System.Action<Azure.Monitor.OpenTelemetry.AspNetCore.AzureMonitorOptions> configureAzureMonitor) { throw null; }
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
#nullable disable

using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Monitor.OpenTelemetry.Exporter;

namespace Azure.Monitor.OpenTelemetry.AspNetCore
{
/// <summary>
/// Options that allow users to configure the Azure Monitor.
/// </summary>
public class AzureMonitorOptions
public class AzureMonitorOptions : ClientOptions
{
/// <summary>
/// The Connection String provides users with a single configuration setting to identify the Azure Monitor resource and endpoint.
Expand All @@ -37,43 +36,11 @@ public class AzureMonitorOptions
/// </summary>
public bool DisableOfflineStorage { get; set; }

/// <summary>
/// Gets or sets a value indicating whether Logs should be enabled.
/// </summary>
public bool EnableLogs { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether Metrics should be enabled.
/// </summary>
public bool EnableMetrics { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether Traces should be enabled.
/// </summary>
public bool EnableTraces { get; set; } = true;

/// <summary>
/// Override the default directory for offline storage.
/// </summary>
public string StorageDirectory { get; set; }

// Used for testing purpose
internal HttpPipelineTransport Transport;

internal void Clone(AzureMonitorOptions options)
{
if (options != null)
{
ConnectionString = options.ConnectionString;
DisableOfflineStorage = options.DisableOfflineStorage;
EnableLogs = options.EnableLogs;
EnableMetrics = options.EnableMetrics;
EnableTraces = options.EnableTraces;
StorageDirectory = options.StorageDirectory;
Transport = options.Transport;
}
}

internal void SetValueToExporterOptions(AzureMonitorExporterOptions exporterOptions)
{
exporterOptions.ConnectionString = ConnectionString;
Expand Down
Loading

0 comments on commit d0eb2bb

Please sign in to comment.