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] reenable logging features #44511

Merged
merged 4 commits into from
Jun 11, 2024
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
20 changes: 20 additions & 0 deletions sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Release History

## 1.3.0-beta.1 (Unreleased)
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes

* Enabled support for log collection from Azure SDKs via `Microsoft.Extensions.Logging`.
See [Logging with the Azure SDK for .NET](https://learn.microsoft.com/dotnet/azure/sdk/logging) for the details.
(This feature was originally introduced in 1.2.0-beta.2)
([#44511](https:/Azure/azure-sdk-for-net/pull/44511))

* Added an experimental feature for logs emitted within an active tracing context to follow the Activity's sampling decision.
The feature can be enabled by setting `OTEL_DOTNET_AZURE_MONITOR_EXPERIMENTAL_ENABLE_LOG_SAMPLING` environment variable to `true`.
(This feature was originally introduced in 1.2.0-beta.1)
([#44511](https:/Azure/azure-sdk-for-net/pull/44511))

## 1.2.0 (2024-06-11)

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
<PropertyGroup>
<Description>An OpenTelemetry .NET distro that exports to Azure Monitor</Description>
<AssemblyTitle>AzureMonitor OpenTelemetry ASP.NET Core Distro</AssemblyTitle>
<Version>1.2.0</Version>
<Version>1.3.0-beta.1</Version>
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
<!-- TODO: Remove this condition from ApiCompatVersion after we release our next stable. Need to disable this because added new target framwork. -->
<ApiCompatVersion Condition="'$(TargetFramework)' != 'net6.0'">1.1.0</ApiCompatVersion>
<ApiCompatVersion>1.2.0</ApiCompatVersion>
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
<PackageTags>Azure Monitor OpenTelemetry Exporter Distro ApplicationInsights</PackageTags>
<TargetFrameworks>net6.0;$(RequiredTargetFrameworks)</TargetFrameworks>
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
Expand All @@ -24,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>
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved

<!-- Shared sources from Azure.Core -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
.Configure<IOptionsMonitor<AzureMonitorOptions>>((loggingOptions, azureOptions) =>
{
var azureMonitorOptions = azureOptions.Get(Options.DefaultName);
loggingOptions.AddAzureMonitorLogExporter(o => azureMonitorOptions.SetValueToExporterOptions(o));

// TODO:WILL RE-ENABLE IN NEXT BETA
/*
bool enableLogSampling = false;
try
{
Expand All @@ -182,7 +179,6 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
{
loggingOptions.AddAzureMonitorLogExporter(o => azureMonitorOptions.SetValueToExporterOptions(o));
}
*/

if (azureMonitorOptions.EnableLiveMetrics)
{
Expand All @@ -204,21 +200,20 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
azureMonitorOptions.Get(Options.DefaultName).SetValueToExporterOptions(exporterOptions);
});

// TODO: WILL RE-ENABLE IN NEXT BETA
// Register Azure SDK log forwarder in the case it was not registered by the user application.
//builder.Services.AddHostedService(sp =>
//{
// var logForwarderType = Type.GetType("Microsoft.Extensions.Azure.AzureEventSourceLogForwarder, Microsoft.Extensions.Azure", false);
builder.Services.AddHostedService(sp =>
{
var logForwarderType = Type.GetType("Microsoft.Extensions.Azure.AzureEventSourceLogForwarder, Microsoft.Extensions.Azure", false);

// if (logForwarderType != null && sp.GetService(logForwarderType) != null)
// {
// AzureMonitorAspNetCoreEventSource.Log.LogForwarderIsAlreadyRegistered();
// return AzureEventSourceLogForwarder.Noop;
// }
if (logForwarderType != null && sp.GetService(logForwarderType) != null)
{
AzureMonitorAspNetCoreEventSource.Log.LogForwarderIsAlreadyRegistered();
return AzureEventSourceLogForwarder.Noop;
}

// var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
// return new AzureEventSourceLogForwarder(loggerFactory);
//});
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
return new AzureEventSourceLogForwarder(loggerFactory);
});

// Register Manager as a singleton
builder.Services.AddSingleton<Manager>(sp =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ namespace Azure.Monitor.OpenTelemetry.AspNetCore.Tests
{
public class AzureSdkLoggingTests
{
[Theory(Skip = "Temporary skip for stable release")]
//#if NET6_0
// [ConditionallySkipOSTheory(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
//#else
// [Theory]
//#endif
#if NET6_0
[ConditionallySkipOSTheory(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
#else
[Theory]
#endif
[InlineData(LogLevel.Information, "TestInfoEvent: hello")]
[InlineData(LogLevel.Warning, "TestWarningEvent: hello")]
[InlineData(LogLevel.Debug, null)]
Expand Down Expand Up @@ -55,12 +54,11 @@ public async Task DistroLogForwarderIsAdded(LogLevel eventLevel, string expected
}
}

[Theory(Skip = "Temporary skip for stable release")]
//#if NET6_0
// [ConditionallySkipOSTheory(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
//#else
// [Theory]
//#endif
#if NET6_0
[ConditionallySkipOSTheory(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
#else
[Theory]
#endif
[InlineData(LogLevel.Information, "TestInfoEvent: hello")]
[InlineData(LogLevel.Warning, "TestWarningEvent: hello")]
[InlineData(LogLevel.Debug, null)]
Expand Down Expand Up @@ -97,12 +95,11 @@ public async Task PublicLogForwarderIsAdded(LogLevel eventLevel, string expected
}
}

[Fact(Skip = "Temporary skip for stable release")]
//#if NET6_0
// [ConditionallySkipOSFact(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
//#else
// [Fact]
//#endif
#if NET6_0
[ConditionallySkipOSFact(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
#else
[Fact]
#endif
public async Task SelfDiagnosticsIsDisabled()
{
var enableLevel = LogLevel.Debug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

### Other Changes

* Changed `AzureMonitorLogExporter` to be public.
This will allow users to write custom processors for filtering logs.
(This feature was originally introduced in 1.3.0-beta.1)
([#44511](https:/Azure/azure-sdk-for-net/pull/44511))

## 1.3.0 (2024-06-07)

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public enum ServiceVersion
v2_1 = 1,
}
}
public sealed partial class AzureMonitorLogExporter : OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord>
{
public AzureMonitorLogExporter(Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions options) { }
protected override void Dispose(bool disposing) { }
public override OpenTelemetry.ExportResult Export(in OpenTelemetry.Batch<OpenTelemetry.Logs.LogRecord> batch) { throw null; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public enum ServiceVersion
v2_1 = 1,
}
}
public sealed partial class AzureMonitorLogExporter : OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord>
{
public AzureMonitorLogExporter(Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorExporterOptions options) { }
protected override void Dispose(bool disposing) { }
public override OpenTelemetry.ExportResult Export(in OpenTelemetry.Batch<OpenTelemetry.Logs.LogRecord> batch) { throw null; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Azure.Monitor.OpenTelemetry.Exporter
/// <summary>
/// Azure Monitor Log Exporter.
/// </summary>
internal sealed class AzureMonitorLogExporter : BaseExporter<LogRecord>
public sealed class AzureMonitorLogExporter : BaseExporter<LogRecord>
{
private readonly ITransmitter _transmitter;
private readonly string _instrumentationKey;
Expand Down