Skip to content

Commit

Permalink
[AzureMonitorDistro] Add LiveMetrics (#41872)
Browse files Browse the repository at this point in the history
* Add LiveMetrics to Distro.

* Update package

* Api + Changelog

* Update API comments and changelog

* Skip TraceProcessorIsAddedViaUseAzureMonitor tests

* Fix CI issue on links
  • Loading branch information
rajkumar-rangaraj authored Feb 9, 2024
1 parent 8ef74f5 commit e72e285
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
<PackageReference Update="Azure.Messaging.EventGrid" Version="4.21.0" />
<PackageReference Update="Azure.Messaging.ServiceBus" Version="7.17.1" />
<PackageReference Update="Azure.Messaging.WebPubSub" Version="1.2.0" />
<PackageReference Update="Azure.Monitor.OpenTelemetry.Exporter" Version="1.2.0" />
<PackageReference Update="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0-beta.1" />
<PackageReference Update="Azure.Monitor.OpenTelemetry.LiveMetrics" Version="1.0.0-beta.1" />
<PackageReference Update="Azure.Monitor.Query" Version="1.1.0" />
<PackageReference Update="Azure.Identity" Version="1.10.4" />
<PackageReference Update="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

* Added Azure Container Apps resource detector.
([#41803](https://github.com/Azure/azure-sdk-for-net/pull/41803))
* Added `Azure.Monitor.OpenTelemetry.LiveMetrics`, enabling the sending of [live
metrics
data](https://learn.microsoft.com/azure/azure-monitor/app/live-stream).
The newly added `EnableLiveMetrics` property is set to `true` by default. This
property can be set to `false` to disable live metrics.
([#41872](https://github.com/Azure/azure-sdk-for-net/pull/41872))

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 EnableLiveMetrics { get { throw null; } set { } }
public float SamplingRatio { get { throw null; } set { } }
public string StorageDirectory { get { throw null; } set { } }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>An OpenTelemetry .NET distro that exports to Azure Monitor</Description>
<AssemblyTitle>AzureMonitor OpenTelemetry ASP.NET Core Distro</AssemblyTitle>
Expand All @@ -24,9 +24,11 @@

<!-- FOR PUBLIC RELEASES, MUST USE PackageReference. THIS REQUIRES A STAGGERED RELEASE IF SHIPPING A NEW EXPORTER. -->
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.LiveMetrics" />

<!-- FOR LOCAL DEV, ProjectReference IS PREFERRED. -->
<!--<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />-->
<!--<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.LiveMetrics\src\Azure.Monitor.OpenTelemetry.LiveMetrics.csproj" />-->
</ItemGroup>

<!-- Shared source from Exporter -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

namespace Azure.Monitor.OpenTelemetry.AspNetCore
{
Expand Down Expand Up @@ -36,6 +37,16 @@ public class AzureMonitorOptions : ClientOptions
/// </summary>
public bool DisableOfflineStorage { get; set; }

/// <summary>
/// Enables or disables the Live Metrics feature. This property is enabled by default.
/// Note: Enabling Live Metrics incurs no additional billing or costs. However, it does introduce
/// a performance overhead due to extra data collection, processing, and networking calls. This overhead
/// is only significant when the LiveMetrics portal is actively used in the UI. Once the portal is closed,
/// LiveMetrics reverts to a 'silent' mode with minimal to no overhead.
/// <see href="https://learn.microsoft.com/azure/azure-monitor/app/live-stream?tabs=dotnet6"/>.
/// </summary>
public bool EnableLiveMetrics { get; set; } = true;

/// <summary>
/// Gets or sets the ratio of telemetry items to be sampled. The value must be between 0.0F and 1.0F, inclusive.
/// For example, specifying 0.4 means that 40% of traces are sampled and 60% are dropped.
Expand All @@ -60,5 +71,16 @@ internal void SetValueToExporterOptions(AzureMonitorExporterOptions exporterOpti
exporterOptions.Transport = Transport;
}
}

internal void SetValueToLiveMetricsExporterOptions(LiveMetricsExporterOptions liveMetricsExporterOptions)
{
liveMetricsExporterOptions.ConnectionString = ConnectionString;
liveMetricsExporterOptions.Credential = Credential;
liveMetricsExporterOptions.EnableLiveMetrics = EnableLiveMetrics;
if (Transport != null)
{
liveMetricsExporterOptions.Transport = Transport;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

#nullable enable

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using Azure.Monitor.OpenTelemetry.AspNetCore.Internals.Profiling;
using Azure.Monitor.OpenTelemetry.Exporter;
using Azure.Monitor.OpenTelemetry.LiveMetrics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -114,6 +112,7 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
return true;
})
.AddProcessor<ProfilingSessionTraceProcessor>()
.AddLiveMetrics()
.AddAzureMonitorTraceExporter());

builder.WithMetrics(b => b
Expand Down Expand Up @@ -151,6 +150,16 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
azureMonitorOptions.Get(Options.DefaultName).SetValueToExporterOptions(exporterOptions);
});

// Register a configuration action so that when
// LiveMetricsExporterOptions is requested it is populated from
// AzureMonitorOptions.
builder.Services
.AddOptions<LiveMetricsExporterOptions>()
.Configure<IOptionsMonitor<AzureMonitorOptions>>((exporterOptions, azureMonitorOptions) =>
{
azureMonitorOptions.Get(Options.DefaultName).SetValueToLiveMetricsExporterOptions(exporterOptions);
});

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void SessionIdIsAddedToActivityTags()
Assert.Equal(_profiler.SessionId, activity.GetTagItem(ProfilingSessionTraceProcessor.TagName));
}

[Fact]
[Fact(Skip = "In Linux, it attempts to load performance counters. This will be enabled once we remove the dependency on them.")]
public void TraceProcessorIsAddedViaUseAzureMonitor()
{
// Configure DI services
Expand Down

0 comments on commit e72e285

Please sign in to comment.