-
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.
[AzureMonitorLiveMetrics] [PoC] Add Live Metrics Extraction Processor (…
…#39750) * Add Live Metrics Extraction Processor * Remove comment * Convert public to internal in LiveMetricsExporterOptions
- Loading branch information
1 parent
a2ef17c
commit 0603001
Showing
8 changed files
with
507 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/LiveMetricConstants.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,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Monitor.OpenTelemetry.LiveMetrics | ||
{ | ||
internal static class LiveMetricConstants | ||
{ | ||
internal const string LiveMetricMeterName = "LiveMetricMeterName"; | ||
internal const string RequestDurationInstrumentName = "RequestDurationLiveMetric"; | ||
internal const string RequestsInstrumentName = "RequestsLiveMetric"; | ||
internal const string RequestsSucceededPerSecondInstrumentName = "RequestsSucceededPerSecondLiveMetric"; | ||
internal const string RequestsFailedPerSecondInstrumentName = "RequestsFailedPerSecondLiveMetric"; | ||
internal const string DependencyDurationInstrumentName = "DependencyDurationLiveMetric"; | ||
internal const string DependencyInstrumentName = "DependencyLiveMetric"; | ||
internal const string DependencySucceededPerSecondInstrumentName = "DependencySucceededPerSecondLiveMetric"; | ||
internal const string DependencyFailedPerSecondInstrumentName = "DependencyFailedPerSecondLiveMetric"; | ||
internal const string ExceptionsPerSecondInstrumentName = "ExceptionsPerSecondLiveMetric"; | ||
internal const string MemoryCommittedBytesInstrumentName = "CommittedBytesLiveMetric"; | ||
internal const string ProcessorTimeInstrumentName = "ProcessorTimeBytesLiveMetric"; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/LiveMetricsExporter.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,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using OpenTelemetry; | ||
using OpenTelemetry.Metrics; | ||
|
||
namespace Azure.Monitor.OpenTelemetry.LiveMetrics | ||
{ | ||
internal sealed class LiveMetricsExporter : BaseExporter<Metric> | ||
{ | ||
private readonly string _instrumentationKey; | ||
private LiveMetricsResource? _resource; | ||
private bool _disposed; | ||
|
||
public LiveMetricsExporter(LiveMetricsExporterOptions options) | ||
{ | ||
_instrumentationKey = ""; | ||
} | ||
|
||
internal LiveMetricsResource? MetricResource => _resource ??= ParentProvider?.GetResource().CreateAzureMonitorResource(_instrumentationKey); | ||
|
||
public override ExportResult Export(in Batch<Metric> batch) | ||
{ | ||
return ExportResult.Success; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (!_disposed) | ||
{ | ||
if (disposing) | ||
{ | ||
} | ||
|
||
_disposed = true; | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/LiveMetricsExporterOptions.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,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
|
||
using Azure.Core; | ||
|
||
namespace Azure.Monitor.OpenTelemetry.LiveMetrics; | ||
|
||
/// <summary> | ||
/// Options that allow users to configure the Live Metrics. | ||
/// </summary> | ||
internal class LiveMetricsExporterOptions : ClientOptions | ||
{ | ||
/// <summary> | ||
/// The Connection String provides users with a single configuration setting to identify the Azure Monitor resource and endpoint. | ||
/// </summary> | ||
/// <remarks> | ||
/// <see href="https://docs.microsoft.com/azure/azure-monitor/app/sdk-connection-string"/>. | ||
/// </remarks> | ||
public string ConnectionString { get; set; } | ||
|
||
/// <summary> | ||
/// Enables or disables the Live Metrics feature. | ||
/// </summary> | ||
public bool EnableLiveMetrics { get; set; } | ||
} |
70 changes: 70 additions & 0 deletions
70
sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/LiveMetricsExtensions.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,70 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace Azure.Monitor.OpenTelemetry.LiveMetrics | ||
{ | ||
/// <summary> | ||
/// Extension methods to register Live Metrics. | ||
/// </summary> | ||
internal static class LiveMetricsExtensions | ||
{ | ||
/// <summary> | ||
/// Adds Live Metrics to the TracerProvider. | ||
/// </summary> | ||
/// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param> | ||
/// <param name="configure">Callback action for configuring <see cref="LiveMetricsExporterOptions"/>.</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 AddLiveMetrics( | ||
this TracerProviderBuilder builder, | ||
Action<LiveMetricsExporterOptions> configure = null, | ||
string name = null) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
var finalOptionsName = name ?? Options.DefaultName; | ||
|
||
builder.ConfigureServices(services => | ||
{ | ||
if (name != null && configure != null) | ||
{ | ||
// If we are using named options we register the | ||
// configuration delegate into options pipeline. | ||
services.Configure(finalOptionsName, configure); | ||
} | ||
}); | ||
|
||
return builder.AddProcessor(sp => | ||
{ | ||
LiveMetricsExporterOptions exporterOptions; | ||
|
||
if (name == null) | ||
{ | ||
exporterOptions = sp.GetRequiredService<IOptionsFactory<LiveMetricsExporterOptions>>().Create(finalOptionsName); | ||
|
||
// Configuration delegate is executed inline on the fresh instance. | ||
configure?.Invoke(exporterOptions); | ||
} | ||
else | ||
{ | ||
// When using named options we can properly utilize Options | ||
// API to create or reuse an instance. | ||
exporterOptions = sp.GetRequiredService<IOptionsMonitor<LiveMetricsExporterOptions>>().Get(finalOptionsName); | ||
} | ||
|
||
return new LiveMetricsExtractionProcessor(new LiveMetricsExporter(exporterOptions)); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.