-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AzureMonitorExporter] api feedback (#37996)
* merge Extensions classes * update Options class * changelog * update public api * remove nullables from public api * changelog * changelog * export public api * reset enum integer
- Loading branch information
1 parent
7b97ef7
commit 7e36acc
Showing
8 changed files
with
207 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 8 additions & 15 deletions
23
...Monitor.OpenTelemetry.Exporter/api/Azure.Monitor.OpenTelemetry.Exporter.netstandard2.0.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
namespace Azure.Monitor.OpenTelemetry.Exporter | ||
{ | ||
public static partial class AzureMonitorExporterLoggingExtensions | ||
public static partial class AzureMonitorExporterExtensions | ||
{ | ||
public static OpenTelemetry.Logs.OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action<Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions>? configure = null, Azure.Core.TokenCredential? credential = null) { throw null; } | ||
} | ||
public static partial class AzureMonitorExporterMetricExtensions | ||
{ | ||
public static OpenTelemetry.Metrics.MeterProviderBuilder AddAzureMonitorMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions>? configure = null, Azure.Core.TokenCredential? credential = null, string? name = null) { throw null; } | ||
public static OpenTelemetry.Logs.OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions loggerOptions, System.Action<Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions> configure = null, Azure.Core.TokenCredential credential = null) { throw null; } | ||
public static OpenTelemetry.Metrics.MeterProviderBuilder AddAzureMonitorMetricExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions> configure = null, Azure.Core.TokenCredential credential = null, string name = null) { throw null; } | ||
public static OpenTelemetry.Trace.TracerProviderBuilder AddAzureMonitorTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions> configure = null, Azure.Core.TokenCredential credential = null, string name = null) { throw null; } | ||
} | ||
public partial class AzureMonitorExporterOptions : Azure.Core.ClientOptions | ||
{ | ||
public AzureMonitorExporterOptions() { } | ||
public AzureMonitorExporterOptions(Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions.ServiceVersion version = Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions.ServiceVersion.v2_1) { } | ||
public string? ConnectionString { get { throw null; } set { } } | ||
public Azure.Core.TokenCredential? Credential { get { throw null; } set { } } | ||
public string ConnectionString { get { throw null; } set { } } | ||
public Azure.Core.TokenCredential Credential { get { throw null; } set { } } | ||
public bool DisableOfflineStorage { get { throw null; } set { } } | ||
public float SamplingRatio { get { throw null; } set { } } | ||
public string? StorageDirectory { get { throw null; } set { } } | ||
public string StorageDirectory { get { throw null; } set { } } | ||
public Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions.ServiceVersion Version { get { throw null; } set { } } | ||
public enum ServiceVersion | ||
{ | ||
V2020_09_15_Preview = 1, | ||
v2_1 = 2, | ||
v2_1 = 1, | ||
} | ||
} | ||
public static partial class AzureMonitorExporterTraceExtensions | ||
{ | ||
public static OpenTelemetry.Trace.TracerProviderBuilder AddAzureMonitorTraceExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions>? configure = null, Azure.Core.TokenCredential? credential = null, string? name = null) { throw null; } | ||
} | ||
} |
184 changes: 184 additions & 0 deletions
184
sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/AzureMonitorExporterExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using Azure.Core; | ||
using Azure.Monitor.OpenTelemetry.Exporter.Internals; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace Azure.Monitor.OpenTelemetry.Exporter | ||
{ | ||
/// <summary> | ||
/// Extension methods to simplify registering of Azure Monitor Exporter for all signals. | ||
/// </summary> | ||
public static class AzureMonitorExporterExtensions | ||
{ | ||
/// <summary> | ||
/// Adds Azure Monitor Trace exporter to the TracerProvider. | ||
/// </summary> | ||
/// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param> | ||
/// <param name="configure">Callback action for configuring <see cref="AzureMonitorExporterOptions"/>.</param> | ||
/// <param name="credential"> | ||
/// An Azure <see cref="TokenCredential" /> capable of providing an OAuth token. | ||
/// Note: if a credential is provided to both <see cref="AzureMonitorExporterOptions"/> and this parameter, | ||
/// the Options will take precedence. | ||
/// </param> | ||
/// <param name="name">Name which is used when retrieving options.</param> | ||
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns> | ||
public static TracerProviderBuilder AddAzureMonitorTraceExporter( | ||
this TracerProviderBuilder builder, | ||
Action<AzureMonitorExporterOptions> configure = null, | ||
TokenCredential credential = null, | ||
string name = null) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
var finalOptionsName = name ?? Options.DefaultName; | ||
|
||
if (name != null && configure != null) | ||
{ | ||
// If we are using named options we register the | ||
// configuration delegate into options pipeline. | ||
builder.ConfigureServices(services => services.Configure(finalOptionsName, configure)); | ||
} | ||
|
||
var deferredBuilder = builder as IDeferredTracerProviderBuilder; | ||
if (deferredBuilder == null) | ||
{ | ||
throw new InvalidOperationException("The provided TracerProviderBuilder does not implement IDeferredTracerProviderBuilder."); | ||
} | ||
|
||
return deferredBuilder.Configure((sp, builder) => | ||
{ | ||
var exporterOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorExporterOptions>>().Get(finalOptionsName); | ||
if (name == null && configure != null) | ||
{ | ||
// If we are NOT using named options, we execute the | ||
// configuration delegate inline. The reason for this is | ||
// AzureMonitorExporterOptions is shared by all signals. Without a | ||
// name, delegates for all signals will mix together. See: | ||
// https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 | ||
configure(exporterOptions); | ||
} | ||
|
||
builder.SetSampler(new ApplicationInsightsSampler(exporterOptions.SamplingRatio)); | ||
|
||
if (credential != null) | ||
{ | ||
// Credential can be set by either AzureMonitorExporterOptions or Extension Method Parameter. | ||
// Options should take precedence. | ||
exporterOptions.Credential ??= credential; | ||
} | ||
|
||
builder.AddProcessor(new CompositeProcessor<Activity>(new BaseProcessor<Activity>[] | ||
{ | ||
new StandardMetricsExtractionProcessor(new AzureMonitorMetricExporter(exporterOptions)), | ||
new BatchActivityExportProcessor(new AzureMonitorTraceExporter(exporterOptions)) | ||
})); | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Adds Azure Monitor Metric exporter. | ||
/// </summary> | ||
/// <param name="builder"><see cref="MeterProviderBuilder"/> builder to use.</param> | ||
/// <param name="configure">Exporter configuration options.</param> | ||
/// <param name="credential"> | ||
/// An Azure <see cref="TokenCredential" /> capable of providing an OAuth token. | ||
/// Note: if a credential is provided to both <see cref="AzureMonitorExporterOptions"/> and this parameter, | ||
/// the Options will take precedence. | ||
/// </param> | ||
/// <param name="name">Name which is used when retrieving options.</param> | ||
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns> | ||
public static MeterProviderBuilder AddAzureMonitorMetricExporter( | ||
this MeterProviderBuilder builder, | ||
Action<AzureMonitorExporterOptions> configure = null, | ||
TokenCredential credential = null, | ||
string name = null) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
var finalOptionsName = name ?? Options.DefaultName; | ||
|
||
if (name != null && configure != null) | ||
{ | ||
// If we are using named options we register the | ||
// configuration delegate into options pipeline. | ||
builder.ConfigureServices(services => services.Configure(finalOptionsName, configure)); | ||
} | ||
|
||
return builder.AddReader(sp => | ||
{ | ||
var exporterOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorExporterOptions>>().Get(finalOptionsName); | ||
|
||
if (name == null && configure != null) | ||
{ | ||
// If we are NOT using named options, we execute the | ||
// configuration delegate inline. The reason for this is | ||
// AzureMonitorExporterOptions is shared by all signals. Without a | ||
// name, delegates for all signals will mix together. See: | ||
// https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043 | ||
configure(exporterOptions); | ||
} | ||
|
||
if (credential != null) | ||
{ | ||
// Credential can be set by either AzureMonitorExporterOptions or Extension Method Parameter. | ||
// Options should take precedence. | ||
exporterOptions.Credential ??= credential; | ||
} | ||
|
||
return new PeriodicExportingMetricReader(new AzureMonitorMetricExporter(exporterOptions)) | ||
{ TemporalityPreference = MetricReaderTemporalityPreference.Delta }; | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Adds Azure Monitor Log Exporter with OpenTelemetryLoggerOptions. | ||
/// </summary> | ||
/// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param> | ||
/// <param name="configure">Exporter configuration options.</param> | ||
/// <param name="credential"> | ||
/// An Azure <see cref="TokenCredential" /> capable of providing an OAuth token. | ||
/// Note: if a credential is provided to both <see cref="AzureMonitorExporterOptions"/> and this parameter, | ||
/// the Options will take precedence. | ||
/// </param> | ||
/// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns> | ||
public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter( | ||
this OpenTelemetryLoggerOptions loggerOptions, | ||
Action<AzureMonitorExporterOptions> configure = null, | ||
TokenCredential credential = null) | ||
{ | ||
if (loggerOptions == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerOptions)); | ||
} | ||
|
||
var options = new AzureMonitorExporterOptions(); | ||
configure?.Invoke(options); | ||
|
||
if (credential != null) | ||
{ | ||
// Credential can be set by either AzureMonitorExporterOptions or Extension Method Parameter. | ||
// Options should take precedence. | ||
options.Credential ??= credential; | ||
} | ||
|
||
return loggerOptions.AddProcessor(new BatchLogRecordExportProcessor(new AzureMonitorLogExporter(options))); | ||
} | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
...monitor/Azure.Monitor.OpenTelemetry.Exporter/src/AzureMonitorExporterLoggingExtensions.cs
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/AzureMonitorExporterMetricExtensions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.