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

[AzureMonitorExporter] cleanup Todos (part2): add EventSource to AspNetCore #37914

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -19,4 +19,9 @@
<ItemGroup>
<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />
</ItemGroup>

<!-- Shared source from Exporter -->
<ItemGroup>
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\ExceptionExtensions.cs" LinkBase="Shared" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;
using Azure.Monitor.OpenTelemetry.Exporter.Internals;

namespace Azure.Monitor.OpenTelemetry.AspNetCore
{
/// <summary>
/// EventSource for the AzureMonitor AspNetCore Distro.
/// EventSource Guid at Runtime: ????.
/// </summary>
/// <remarks>
/// PerfView Instructions:
/// <list type="bullet">
/// <item>To collect all events: <code>PerfView.exe collect -MaxCollectSec:300 -NoGui /onlyProviders=*OpenTelemetry-AzureMonitor-AspNetCore</code></item>
/// <item>To collect events based on LogLevel: <code>PerfView.exe collect -MaxCollectSec:300 -NoGui /onlyProviders:OpenTelemetry-AzureMonitor-AspNetCore::Verbose</code></item>
/// </list>
/// Dotnet-Trace Instructions:
/// <list type="bullet">
/// <item>To collect all events: <code>dotnet-trace collect --process-id PID --providers OpenTelemetry-AzureMonitor-AspNetCore</code></item>
/// <item>To collect events based on LogLevel: <code>dotnet-trace collect --process-id PID --providers OpenTelemetry-AzureMonitor-AspNetCore::Verbose</code></item>
/// </list>
/// Logman Instructions:
/// <list type="number">
/// <item>Create a text file containing providers: <code>echo "{????}" > providers.txt</code></item>
/// <item>Start collecting: <code>logman -start exporter -pf providers.txt -ets -bs 1024 -nb 100 256</code></item>
/// <item>Stop collecting: <code>logman -stop exporter -ets</code></item>
/// </list>
/// </remarks>
[EventSource(Name = EventSourceName)]
internal sealed class AzureMonitorAspNetCoreEventSource : EventSource
{
internal const string EventSourceName = "OpenTelemetry-AzureMonitor-AspNetCore";

internal static readonly AzureMonitorAspNetCoreEventSource Log = new AzureMonitorAspNetCoreEventSource();

[NonEvent]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool IsEnabled(EventLevel eventLevel) => IsEnabled(eventLevel, EventKeywords.All);

[NonEvent]
public void ConfigureFailed(Exception ex)
{
if (IsEnabled(EventLevel.Error))
{
ConfigureFailed(ex.FlattenException().ToInvariantString());
}
}

[Event(1, Message = "Failed to configure to an exception: {0}", Level = EventLevel.Error)]
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
public void ConfigureFailed(string exceptionMessage) => WriteEvent(1, exceptionMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void Configure(AzureMonitorOptions options)
options.ConnectionString = connectionString;
}
}
catch
catch (Exception ex)
{
// TODO: Log Error.
AzureMonitorAspNetCoreEventSource.Log.ConfigureFailed(ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<ProjectReference Include="..\..\src\Azure.Monitor.OpenTelemetry.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\..\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\EventSourceTestHelper.cs" LinkBase="CommonTestFramework" />
<Compile Include="..\..\..\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\TestEventListener.cs" LinkBase="CommonTestFramework" />
</ItemGroup>

<ItemGroup>
<!-- Workaround to fix CI build failure in macOS. This package is being used indirectly by Azure analyzers. -->
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" VersionOverride="7.0.0" />
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.

using Xunit;
using Azure.Monitor.OpenTelemetry.Exporter.Tests.CommonTestFramework;

namespace Azure.Monitor.OpenTelemetry.AspNetCore.Tests
{
public class AzureMonitorAspNetCoreEventSourceTests
{
/// <summary>
/// This test uses reflection to invoke every Event method in our EventSource class.
/// This validates that parameters are logged and helps to confirm that EventIds are correct.
/// </summary>
[Fact]
public void EventSourceTest_AzureMonitorExporterEventSource()
{
EventSourceTestHelper.MethodsAreImplementedConsistentlyWithTheirAttributes(AzureMonitorAspNetCoreEventSource.Log);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

namespace Azure.Monitor.OpenTelemetry.Exporter.Tests
{
/// <summary>
/// These tests depend on the <see cref="AzureMonitorExporterEventListener"/> to subscribe to the <see cref="AzureMonitorExporterEventSource"/> and write events to the <see cref="TelemetryDebugWriter"/>.
/// </summary>
public class AzureMonitorExporterEventSourceTests
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\**" Link="CommonTestFramework\%(Filename)%(Extension)" />
<Compile Include="..\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\**" LinkBase="CommonTestFramework" />
</ItemGroup>

</Project>