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

[AzureMonitor] include LiveMetrics in Exporter project #48633

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<!-- Depending on monthly deliverables, we may switch between PackageReference or ProjectReference. Keeping both here to make the switch easier. -->

<!-- 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.Exporter" />-->

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

<!-- Shared sources from Azure.Core -->
Expand Down Expand Up @@ -54,10 +54,5 @@
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\SemanticConventions.cs" LinkBase="Shared\Exporter" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\StringExtensions.cs" LinkBase="Shared\Exporter" />
</ItemGroup>

<!-- Shared sources from Azure.Monitor.OpenTelemetry.LiveMetrics -->
<ItemGroup>
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.LiveMetrics\src\**\*.cs" LinkBase="Shared\LiveMetrics" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,23 @@ public void PostFailedWithUnknownException(System.Exception ex)
}
}

[NonEvent]
public void PingFailedWithServiceError(int statusCode, ServiceError serviceError)
{
if (IsEnabled(EventLevel.Error))
{
ServiceCallFailedWithServiceError(name: "Ping", statusCode, serviceError.Code, serviceError.Exception, serviceError.Message);
}
}

[NonEvent]
public void PostFailedWithServiceError(int statusCode, ServiceError serviceError)
{
if (IsEnabled(EventLevel.Error))
{
ServiceCallFailedWithServiceError(name: "Post", statusCode, serviceError.Code, serviceError.Exception, serviceError.Message);
}
}
//[NonEvent]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are public APIs commented out? Is this a breaking change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmolkova could you review the PR please - thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 public apis are affected here. We're moving the LiveMetrics feature from one package to the other. While juggling references, it's been easier to comment out blocks and address in a follow up PR.

The line you commented on is the EventSource class, used for internal logging inside our package. I have another PR already created to refactor and resolve misc issues with these classes.

//public void PingFailedWithServiceError(int statusCode, ServiceError serviceError)
//{
// if (IsEnabled(EventLevel.Error))
// {
// ServiceCallFailedWithServiceError(name: "Ping", statusCode, serviceError.Code, serviceError.Exception, serviceError.Message);
// }
//}

//[NonEvent]
//public void PostFailedWithServiceError(int statusCode, ServiceError serviceError)
//{
// if (IsEnabled(EventLevel.Error))
// {
// ServiceCallFailedWithServiceError(name: "Post", statusCode, serviceError.Code, serviceError.Exception, serviceError.Message);
// }
//}

[Event(15, Message = "Service call failed. Name: {0}. Status Code: {1} Reason: {2} Configured Endpoint: {3} Actual Endpoint: {4}", Level = EventLevel.Error)]
public void ServiceCallFailed(string name, int statusCode, string reasonPhrase, string configuredEndpoint, string actualEndpoint) => WriteEvent(15, name, statusCode, reasonPhrase, configuredEndpoint, actualEndpoint);
Expand All @@ -219,14 +219,14 @@ public void StateMachineFailedWithUnknownException(System.Exception ex)
[Event(18, Message = "LiveMetrics State Machine failed with exception: {0}", Level = EventLevel.Error)]
public void StateMachineFailedWithUnknownException(string exceptionMessage) => WriteEvent(18, exceptionMessage);

[NonEvent]
public void DroppedDocument(DocumentType documentType)
{
if (IsEnabled(EventLevel.Warning))
{
DroppedDocument(documentType.ToString());
}
}
//[NonEvent]
//public void DroppedDocument(DocumentType documentType)
//{
// if (IsEnabled(EventLevel.Warning))
// {
// DroppedDocument(documentType.ToString());
// }
//}

[Event(19, Message = "Document was dropped. DocumentType: {0}. Not user actionable.", Level = EventLevel.Warning)]
public void DroppedDocument(string documentType) => WriteEvent(19, documentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ internal void SetValueToExporterOptions(AzureMonitorExporterOptions exporterOpti
exporterOptions.Diagnostics.IsLoggingEnabled = Diagnostics.IsLoggingEnabled;
}

internal void SetValueToLiveMetricsOptions(AzureMonitorLiveMetricsOptions liveMetricsOptions)
{
liveMetricsOptions.ConnectionString = ConnectionString;
liveMetricsOptions.Credential = Credential;
liveMetricsOptions.EnableLiveMetrics = EnableLiveMetrics;
//internal void SetValueToLiveMetricsOptions(AzureMonitorLiveMetricsOptions liveMetricsOptions)
//{
// liveMetricsOptions.ConnectionString = ConnectionString;
// liveMetricsOptions.Credential = Credential;
// liveMetricsOptions.EnableLiveMetrics = EnableLiveMetrics;

if (Transport != null)
{
liveMetricsOptions.Transport = Transport;
}
// if (Transport != null)
// {
// liveMetricsOptions.Transport = Transport;
// }

liveMetricsOptions.Diagnostics.IsDistributedTracingEnabled = Diagnostics.IsDistributedTracingEnabled;
liveMetricsOptions.Diagnostics.IsLoggingEnabled = Diagnostics.IsLoggingEnabled;
}
// liveMetricsOptions.Diagnostics.IsDistributedTracingEnabled = Diagnostics.IsDistributedTracingEnabled;
// liveMetricsOptions.Diagnostics.IsLoggingEnabled = Diagnostics.IsLoggingEnabled;
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
var azureMonitorOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorOptions>>().Get(Options.DefaultName);
if (azureMonitorOptions.EnableLiveMetrics)
{
var manager = sp.GetRequiredService<LiveMetricsClientManager>();
builder.AddProcessor(new LiveMetricsActivityProcessor(manager));
// TODO: THIS WILL COME FROM THE EXPORTER

//var manager = sp.GetRequiredService<LiveMetricsClientManager>();
//builder.AddProcessor(new LiveMetricsActivityProcessor(manager));
}
});

Expand All @@ -141,13 +143,15 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui

if (azureMonitorOptions.EnableLiveMetrics)
{
var manager = sp.GetRequiredService<LiveMetricsClientManager>();
// TODO: THIS WILL COME FROM THE EXPORTER

return new CompositeProcessor<LogRecord>(new BaseProcessor<LogRecord>[]
{
new LiveMetricsLogProcessor(manager),
new BatchLogRecordExportProcessor(exporter)
});
//var manager = sp.GetRequiredService<LiveMetricsClientManager>();

//return new CompositeProcessor<LogRecord>(new BaseProcessor<LogRecord>[]
//{
// new LiveMetricsLogProcessor(manager),
// new BatchLogRecordExportProcessor(exporter)
//});
}

return new BatchLogRecordExportProcessor(exporter);
Expand Down Expand Up @@ -181,14 +185,17 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
});

// Register Manager as a singleton
builder.Services.AddSingleton<LiveMetricsClientManager>(sp =>
{
AzureMonitorOptions azureMonitorOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorOptions>>().Get(Options.DefaultName);
var azureMonitorLiveMetricsOptions = new AzureMonitorLiveMetricsOptions();
azureMonitorOptions.SetValueToLiveMetricsOptions(azureMonitorLiveMetricsOptions);

return new LiveMetricsClientManager(azureMonitorLiveMetricsOptions, new DefaultPlatformDistro());
});
// TODO: THIS WILL COME FROM THE EXPORTER

//builder.Services.AddSingleton<LiveMetricsClientManager>(sp =>
//{
// AzureMonitorOptions azureMonitorOptions = sp.GetRequiredService<IOptionsMonitor<AzureMonitorOptions>>().Get(Options.DefaultName);
// var azureMonitorLiveMetricsOptions = new AzureMonitorLiveMetricsOptions();
// azureMonitorOptions.SetValueToLiveMetricsOptions(azureMonitorLiveMetricsOptions);

// return new LiveMetricsClientManager(azureMonitorLiveMetricsOptions, new DefaultPlatformDistro());
//});

builder.Services.AddOptions<AzureMonitorOptions>()
.Configure<IConfiguration>((options, config) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ namespace Azure.Monitor.OpenTelemetry.AspNetCore.Tests.LiveMetrics
{
public class LiveMetricsPolingIntervalTests
{
[Fact]
public void VerifyLiveMetricsReadsPolingIntervalHeader()
{
var mockTransport = new MockTransport(_ => new MockResponse(200).AddHeader("x-ms-qps-service-polling-interval-hint", "123"));
// TODO: THIS TEST IS HAVING TYPE CONFLICTS. NEEDS TO BE MIGRATED TO A LIVEMETRICS SPECIFIC TEST PROJECT

AzureMonitorLiveMetricsOptions options = new AzureMonitorLiveMetricsOptions
{
ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000",
EnableLiveMetrics = false, // set to false to prevent the manager from starting.
Transport = mockTransport
};
//[Fact]
//public void VerifyLiveMetricsReadsPolingIntervalHeader()
//{
// var mockTransport = new MockTransport(_ => new MockResponse(200).AddHeader("x-ms-qps-service-polling-interval-hint", "123"));

var manager = new LiveMetricsClientManager(options, new DefaultPlatformDistro());
// AzureMonitorLiveMetricsOptions options = new AzureMonitorLiveMetricsOptions
// {
// ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000",
// EnableLiveMetrics = false, // set to false to prevent the manager from starting.
// Transport = mockTransport
// };

Assert.Empty(mockTransport.Requests);
Assert.Null(manager._pingPeriodFromService);
// var manager = new LiveMetricsClientManager(options, new DefaultPlatformDistro());

manager.OnPing();
// Assert.Empty(mockTransport.Requests);
// Assert.Null(manager._pingPeriodFromService);

Assert.Single(mockTransport.Requests);
Assert.Equal(123, manager._pingPeriodFromService!.Value.TotalMilliseconds);
}
// manager.OnPing();

// Assert.Single(mockTransport.Requests);
// Assert.Equal(123, manager._pingPeriodFromService!.Value.TotalMilliseconds);
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
<Compile Include="$(AzureCoreSharedSources)EventSourceEventFormatting.cs" LinkBase="Shared" />
</ItemGroup>

<!-- Shared sources from Azure.Monitor.OpenTelemetry.LiveMetrics -->
<ItemGroup>
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.LiveMetrics\src\**\*.cs" LinkBase="Shared\LiveMetrics" />
<Compile Remove="..\..\Azure.Monitor.OpenTelemetry.LiveMetrics\src\Properties\AssemblyInfo.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static string GetSdkVersion()
#if AZURE_MONITOR_EXPORTER
string? extensionVersion = GetVersion(typeof(AzureMonitorTraceExporter));
#elif ASP_NET_CORE_DISTRO
string? extensionVersion = GetVersion(typeof(LiveMetrics.LiveMetricsActivityProcessor));
string? extensionVersion = GetVersion(typeof(AzureMonitorAspNetCoreEventSource));
#else
string extensionVersion = "Undefined";
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.AspNetCore.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.AspNetCore.Benchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.E2E.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.Benchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
Expand Down
Loading