Skip to content

Commit

Permalink
[Azure.Monitor.LiveMetrics] add project scaffolding (#39719)
Browse files Browse the repository at this point in the history
* scaffolding

* fix merge conflict

* update comment

* fix subdirectory
  • Loading branch information
TimothyMothra authored Nov 2, 2023
1 parent 17a12b5 commit 27af7cf
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Linq;
#if AZURE_MONITOR_EXPORTER
using Azure.Monitor.OpenTelemetry.Exporter.Internals.Diagnostics;
#elif LIVE_METRICS_EXPORTER
using Azure.Monitor.OpenTelemetry.LiveMetrics.Internals.Diagnostics;
#endif

// This alias is necessary because it will otherwise try to default to "Microsoft.Azure.Core" which doesn't exist.
Expand Down Expand Up @@ -50,6 +52,8 @@ public static ConnectionVars GetValues(string connectionString)
{
#if AZURE_MONITOR_EXPORTER
AzureMonitorExporterEventSource.Log.FailedToParseConnectionString(ex);
#elif LIVE_METRICS_EXPORTER
LiveMetricsExporterEventSource.Log.FailedToParseConnectionString(ex);
#endif
throw new InvalidOperationException("Connection String Error: " + ex.Message, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#if AZURE_MONITOR_EXPORTER
using Azure.Monitor.OpenTelemetry.Exporter.Internals.Diagnostics;
#elif LIVE_METRICS_EXPORTER
using Azure.Monitor.OpenTelemetry.LiveMetrics.Internals.Diagnostics;
#endif

namespace Azure.Monitor.OpenTelemetry.Exporter.Internals.Platform
Expand All @@ -28,6 +30,8 @@ public DefaultPlatform()
{
#if AZURE_MONITOR_EXPORTER
AzureMonitorExporterEventSource.Log.FailedToReadEnvironmentVariables(ex);
#elif LIVE_METRICS_EXPORTER
LiveMetricsExporterEventSource.Log.FailedToReadEnvironmentVariables(ex);
#endif
_environmentVariables = new Dictionary<string, object>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>An OpenTelemetry .NET AzureMonitor OpenTelemetry Live Metrics</Description>
<AssemblyTitle>AzureMonitor OpenTelemetry Live Metrics</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Azure Monitor OpenTelemetry live Metrics ApplicationInsights</PackageTags>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
<Nullable>enable</Nullable>
<DefineConstants>$(DefineConstants);LIVE_METRICS_EXPORTER;</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="OpenTelemetry" />
</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\NullableAttributes.cs" LinkBase="Internals" />
<Compile Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Internals\ExceptionExtensions.cs" LinkBase="Internals" />
</ItemGroup>

<!-- Shared source from Azure.Core -->
<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)ConnectionString.cs" LinkBase="Shared" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.LiveMetrics.Internals.Diagnostics
{
/// <summary>
/// EventSource for the AzureMonitorExporter.
/// EventSource Guid at Runtime: 72f5588f-fa1c-502e-0627-e13dd2bd67c9.
/// (This guid can be found by debugging this class and inspecting the "Log" singleton and reading the "Guid" property).
/// </summary>
/// <remarks>
/// PerfView Instructions:
/// <list type="bullet">
/// <item>To collect all events: <code>PerfView.exe collect -MaxCollectSec:300 -NoGui /onlyProviders=*OpenTelemetry-AzureMonitor-LiveMetrics</code></item>
/// <item>To collect events based on LogLevel: <code>PerfView.exe collect -MaxCollectSec:300 -NoGui /onlyProviders:OpenTelemetry-AzureMonitor-LiveMetrics::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-LiveMetrics</code></item>
/// <item>To collect events based on LogLevel: <code>dotnet-trace collect --process-id PID --providers OpenTelemetry-AzureMonitor-LiveMetrics::Verbose</code></item>
/// </list>
/// Logman Instructions:
/// <list type="number">
/// <item>Create a text file containing providers: <code>echo "{72f5588f-fa1c-502e-0627-e13dd2bd67c9}" > 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 LiveMetricsExporterEventSource : EventSource
{
internal const string EventSourceName = "OpenTelemetry-AzureMonitor-LiveMetrics";

internal static readonly LiveMetricsExporterEventSource Log = new LiveMetricsExporterEventSource();

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

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

[Event(1, Message = "Failed to parse ConnectionString due to an exception: {0}", Level = EventLevel.Error)]
public void FailedToParseConnectionString(string exceptionMessage) => WriteEvent(1, exceptionMessage);

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

[Event(2, Message = "Failed to read environment variables due to an exception. This may prevent the Exporter from initializing. {0}", Level = EventLevel.Warning)]
public void FailedToReadEnvironmentVariables(string errorMessage) => WriteEvent(2, errorMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.LiveMetrics.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]

// Moq
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(AzureCoreTestFramework)" />
<ProjectReference Include="..\..\src\Azure.Monitor.OpenTelemetry.LiveMetrics.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>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Monitor.OpenTelemetry.Exporter.Tests.CommonTestFramework;
using Azure.Monitor.OpenTelemetry.LiveMetrics.Internals.Diagnostics;
using Xunit;

namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Tests
{
public class LiveMetricsExporterEventSourceTests
{
/// <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_LiveMetricsExporterEventSource()
{
EventSourceTestHelper.MethodsAreImplementedConsistentlyWithTheirAttributes(LiveMetricsExporterEventSource.Log);
}
}
}
8 changes: 7 additions & 1 deletion sdk/monitor/Azure.Monitor.OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core", "..\core\Azure
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp", "Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp.csproj", "{D2174A00-93CF-4337-8600-4CE758C7D4AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Monitor.OpenTelemetry.LiveMetrics", "Azure.Monitor.OpenTelemetry.LiveMetrics\src\Azure.Monitor.OpenTelemetry.LiveMetrics.csproj", "{C13C8648-2B37-4334-97DC-322344E8EE8C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Monitor.OpenTelemetry.LiveMetrics", "Azure.Monitor.OpenTelemetry.LiveMetrics\src\Azure.Monitor.OpenTelemetry.LiveMetrics.csproj", "{C13C8648-2B37-4334-97DC-322344E8EE8C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Monitor.OpenTelemetry.LiveMetrics.Tests", "Azure.Monitor.OpenTelemetry.LiveMetrics\tests\Azure.Monitor.OpenTelemetry.LiveMetrics.Tests\Azure.Monitor.OpenTelemetry.LiveMetrics.Tests.csproj", "{EA90D06D-D272-4A65-8DDA-6412B3F14572}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -120,6 +122,10 @@ Global
{C13C8648-2B37-4334-97DC-322344E8EE8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C13C8648-2B37-4334-97DC-322344E8EE8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C13C8648-2B37-4334-97DC-322344E8EE8C}.Release|Any CPU.Build.0 = Release|Any CPU
{EA90D06D-D272-4A65-8DDA-6412B3F14572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA90D06D-D272-4A65-8DDA-6412B3F14572}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA90D06D-D272-4A65-8DDA-6412B3F14572}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA90D06D-D272-4A65-8DDA-6412B3F14572}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 27af7cf

Please sign in to comment.