Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AzureMonitorLiveMetrics] [PoC] Add Live Metrics Extraction Processor #39750

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="OpenTelemetry" />
<PackageReference Include="OpenTelemetry.Exporter.Console" VersionOverride="1.6.0" />
</ItemGroup>

<!-- Shared sorce from Azure.Monitor.OpenTelemetry.Exporter -->
<ItemGroup>
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\ConnectionString\*.cs" LinkBase="Internals\ConnectionString" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\Platform\*.cs" LinkBase="Internals\Platform" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\AksResourceProcessor.cs" Link="AksResourceProcessor.cs" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\NullableAttributes.cs" LinkBase="Internals" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\ExceptionExtensions.cs" LinkBase="Internals" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\SchemaConstants.cs" Link="SchemaConstants.cs" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\SemanticConventions.cs" Link="SemanticConventions.cs" />
rajkumar-rangaraj marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<!-- Shared source from Azure.Core -->
Expand Down
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";
}
}
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);
}
}
}
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; }
}
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));
});
}
}
}
Loading
Loading