Skip to content

Commit aa02025

Browse files
author
Timothy Mothra
authored
[AzureMonitor] refactor EventSource after LiveMetrics move (Azure#48640)
* LiveMetrics refactor EventSource * update guid
1 parent b772af8 commit aa02025

File tree

12 files changed

+17
-292
lines changed

12 files changed

+17
-292
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/AzureMonitorAspNetCoreEventSource.cs

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Diagnostics.Tracing;
55
using System.Runtime.CompilerServices;
66
using Azure.Monitor.OpenTelemetry.Exporter.Internals;
7-
using Azure.Monitor.OpenTelemetry.LiveMetrics.Models;
87

98
namespace Azure.Monitor.OpenTelemetry.AspNetCore
109
{
@@ -102,18 +101,6 @@ public void FailedToReadEnvironmentVariables(System.Exception ex)
102101
[Event(9, Message = "Failed to read environment variables due to an exception. This may prevent the Exporter from initializing. {0}", Level = EventLevel.Warning)]
103102
public void FailedToReadEnvironmentVariables(string errorMessage) => WriteEvent(9, errorMessage);
104103

105-
[NonEvent]
106-
public void AccessingEnvironmentVariableFailedWarning(string environmentVariable, System.Exception ex)
107-
{
108-
if (IsEnabled(EventLevel.Warning))
109-
{
110-
AccessingEnvironmentVariableFailedWarning(environmentVariable, ex.FlattenException().ToInvariantString());
111-
}
112-
}
113-
114-
[Event(10, Message = "Accessing environment variable - {0} failed with exception: {1}.", Level = EventLevel.Warning)]
115-
public void AccessingEnvironmentVariableFailedWarning(string environmentVariable, string exceptionMessage) => WriteEvent(10, environmentVariable, exceptionMessage);
116-
117104
[NonEvent]
118105
public void SdkVersionCreateFailed(System.Exception ex)
119106
{
@@ -140,122 +127,5 @@ public void ErrorInitializingPartOfSdkVersion(string typeName, System.Exception
140127

141128
[Event(13, Message = "Failed to get Type version while initialize SDK version due to an exception. Not user actionable. Type: {0}. {1}", Level = EventLevel.Warning)]
142129
public void ErrorInitializingPartOfSdkVersion(string typeName, string exceptionMessage) => WriteEvent(13, typeName, exceptionMessage);
143-
144-
[Event(14, Message = "HttpPipelineBuilder is built with AAD Credentials. TokenCredential: {0} Scope: {1}", Level = EventLevel.Informational)]
145-
public void SetAADCredentialsToPipeline(string credentialTypeName, string scope) => WriteEvent(14, credentialTypeName, scope);
146-
147-
[NonEvent]
148-
public void PingFailed(Response response, string configuredEndpoint, string actualEndpoint)
149-
{
150-
if (IsEnabled(EventLevel.Error))
151-
{
152-
ServiceCallFailed(name: "Ping", response.Status, response.ReasonPhrase, configuredEndpoint, actualEndpoint);
153-
}
154-
}
155-
156-
[NonEvent]
157-
public void PostFailed(Response response, string configuredEndpoint, string actualEndpoint)
158-
{
159-
if (IsEnabled(EventLevel.Error))
160-
{
161-
ServiceCallFailed(name: "Post", response.Status, response.ReasonPhrase, configuredEndpoint, actualEndpoint);
162-
}
163-
}
164-
165-
[NonEvent]
166-
public void PingFailedWithUnknownException(System.Exception ex)
167-
{
168-
if (IsEnabled(EventLevel.Error))
169-
{
170-
ServiceCallFailedWithUnknownException(name: "Ping", ex.ToInvariantString());
171-
}
172-
}
173-
174-
[NonEvent]
175-
public void PostFailedWithUnknownException(System.Exception ex)
176-
{
177-
if (IsEnabled(EventLevel.Error))
178-
{
179-
ServiceCallFailedWithUnknownException(name: "Post", ex.ToInvariantString());
180-
}
181-
}
182-
183-
//[NonEvent]
184-
//public void PingFailedWithServiceError(int statusCode, ServiceError serviceError)
185-
//{
186-
// if (IsEnabled(EventLevel.Error))
187-
// {
188-
// ServiceCallFailedWithServiceError(name: "Ping", statusCode, serviceError.Code, serviceError.Exception, serviceError.Message);
189-
// }
190-
//}
191-
192-
//[NonEvent]
193-
//public void PostFailedWithServiceError(int statusCode, ServiceError serviceError)
194-
//{
195-
// if (IsEnabled(EventLevel.Error))
196-
// {
197-
// ServiceCallFailedWithServiceError(name: "Post", statusCode, serviceError.Code, serviceError.Exception, serviceError.Message);
198-
// }
199-
//}
200-
201-
[Event(15, Message = "Service call failed. Name: {0}. Status Code: {1} Reason: {2} Configured Endpoint: {3} Actual Endpoint: {4}", Level = EventLevel.Error)]
202-
public void ServiceCallFailed(string name, int statusCode, string reasonPhrase, string configuredEndpoint, string actualEndpoint) => WriteEvent(15, name, statusCode, reasonPhrase, configuredEndpoint, actualEndpoint);
203-
204-
[Event(16, Message = "Service call failed with exception. Name: {0}. Exception: {1}", Level = EventLevel.Error)]
205-
public void ServiceCallFailedWithUnknownException(string name, string exceptionMessage) => WriteEvent(16, name, exceptionMessage);
206-
207-
[Event(17, Message = "Service call failed. Name: {0}. Status Code: {1}. Code: {2}. Message: {3}. Exception: {4}.", Level = EventLevel.Error)]
208-
public void ServiceCallFailedWithServiceError(string name, int statusCode, string code, string message, string exception) => WriteEvent(17, name, statusCode, code, message, exception);
209-
210-
[NonEvent]
211-
public void StateMachineFailedWithUnknownException(System.Exception ex)
212-
{
213-
if (IsEnabled(EventLevel.Error))
214-
{
215-
StateMachineFailedWithUnknownException(ex.ToInvariantString());
216-
}
217-
}
218-
219-
[Event(18, Message = "LiveMetrics State Machine failed with exception: {0}", Level = EventLevel.Error)]
220-
public void StateMachineFailedWithUnknownException(string exceptionMessage) => WriteEvent(18, exceptionMessage);
221-
222-
//[NonEvent]
223-
//public void DroppedDocument(DocumentType documentType)
224-
//{
225-
// if (IsEnabled(EventLevel.Warning))
226-
// {
227-
// DroppedDocument(documentType.ToString());
228-
// }
229-
//}
230-
231-
[Event(19, Message = "Document was dropped. DocumentType: {0}. Not user actionable.", Level = EventLevel.Warning)]
232-
public void DroppedDocument(string documentType) => WriteEvent(19, documentType);
233-
234-
[Event(20, Message = "Failure to calculate CPU Counter. Unexpected negative timespan: PreviousCollectedTime: {0}. RecentCollectedTime: {0}. Not user actionable.", Level = EventLevel.Error)]
235-
public void ProcessCountersUnexpectedNegativeTimeSpan(long previousCollectedTime, long recentCollectedTime) => WriteEvent(20, previousCollectedTime, recentCollectedTime);
236-
237-
[Event(21, Message = "Failure to calculate CPU Counter. Unexpected negative value: PreviousCollectedValue: {0}. RecentCollectedValue: {0}. Not user actionable.", Level = EventLevel.Error)]
238-
public void ProcessCountersUnexpectedNegativeValue(long previousCollectedValue, long recentCollectedValue) => WriteEvent(21, previousCollectedValue, recentCollectedValue);
239-
240-
[Event(22, Message = "Calculated Cpu Counter: Period: {0}. DiffValue: {1}. CalculatedValue: {2}. ProcessorCount: {3}. NormalizedValue: {4}", Level = EventLevel.Verbose)]
241-
public void ProcessCountersCpuCounter(long period, long diffValue, double calculatedValue, int processorCount, double normalizedValue) => WriteEvent(22, period, diffValue, calculatedValue, processorCount, normalizedValue);
242-
243-
[NonEvent]
244-
public void FailedToCreateTelemetryDocument(string documentTypeName, System.Exception ex)
245-
{
246-
if (IsEnabled(EventLevel.Error))
247-
{
248-
FailedToCreateTelemetryDocument(documentTypeName, ex.ToInvariantString());
249-
}
250-
}
251-
252-
[Event(23, Message = "Failed to create telemetry document due to an exception. DocumentType: {0}. Exception: {1}", Level = EventLevel.Error)]
253-
public void FailedToCreateTelemetryDocument(string documentTypeName, string exceptionMessage) => WriteEvent(23, documentTypeName, exceptionMessage);
254-
255-
[Event(24, Message = "Redirect received from LiveMetrics service: {0}", Level = EventLevel.Informational)]
256-
public void LiveMetricsRedirectReceived(string redirectUri) => WriteEvent(24, redirectUri);
257-
258-
[Event(25, Message = "Polling Interval received from LiveMetrics service: {0}", Level = EventLevel.Informational)]
259-
public void LiveMetricsPolingIntervalReceived(int pollingInterval) => WriteEvent(25, pollingInterval);
260130
}
261131
}

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ConnectionString/ConnectionStringParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public static ConnectionVars GetValues(string connectionString)
5454
AzureMonitorExporterEventSource.Log.FailedToParseConnectionString(ex);
5555
#elif ASP_NET_CORE_DISTRO
5656
AzureMonitorAspNetCoreEventSource.Log.FailedToParseConnectionString(ex);
57-
#else
58-
System.Diagnostics.Debug.Write(ex.ToString());
57+
#elif LIVE_METRICS_PROJECT
58+
LiveMetrics.AzureMonitorLiveMetricsEventSource.Log.FailedToParseConnectionString(ex);
5959
#endif
6060
throw new InvalidOperationException("Connection String Error: " + ex.Message, ex);
6161
}

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Platform/DefaultPlatform.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public DefaultPlatform()
5555
AzureMonitorExporterEventSource.Log.FailedToReadEnvironmentVariables(ex);
5656
#elif ASP_NET_CORE_DISTRO
5757
AzureMonitorAspNetCoreEventSource.Log.FailedToReadEnvironmentVariables(ex);
58-
#else
59-
System.Diagnostics.Debug.Write(ex.ToString());
58+
#elif LIVE_METRICS_PROJECT
59+
LiveMetrics.AzureMonitorLiveMetricsEventSource.Log.FailedToReadEnvironmentVariables(ex);
6060
#endif
6161
_environmentVariables = new Dictionary<string, object>();
6262
}

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ internal static bool IsDistro
6161
AzureMonitorExporterEventSource.Log.VersionStringUnexpectedLength(type.Name, versionString);
6262
#elif ASP_NET_CORE_DISTRO
6363
AzureMonitorAspNetCoreEventSource.Log.VersionStringUnexpectedLength(type.Name, versionString);
64+
#elif LIVE_METRICS_PROJECT
65+
LiveMetrics.AzureMonitorLiveMetricsEventSource.Log.VersionStringUnexpectedLength(type.Name, versionString);
6466
#endif
6567
return shortVersion.Substring(0, 20);
6668
}
@@ -73,8 +75,8 @@ internal static bool IsDistro
7375
AzureMonitorExporterEventSource.Log.ErrorInitializingPartOfSdkVersion(type.Name, ex);
7476
#elif ASP_NET_CORE_DISTRO
7577
AzureMonitorAspNetCoreEventSource.Log.ErrorInitializingPartOfSdkVersion(type.Name, ex);
76-
#else
77-
System.Diagnostics.Debug.Write(ex.ToString());
78+
#elif LIVE_METRICS_PROJECT
79+
LiveMetrics.AzureMonitorLiveMetricsEventSource.Log.ErrorInitializingPartOfSdkVersion(type.Name, ex);
7880
#endif
7981
return null;
8082
}
@@ -91,8 +93,8 @@ private static string GetSdkVersion()
9193
string? extensionVersion = GetVersion(typeof(AzureMonitorTraceExporter));
9294
#elif ASP_NET_CORE_DISTRO
9395
string? extensionVersion = GetVersion(typeof(AzureMonitorAspNetCoreEventSource));
94-
#else
95-
string extensionVersion = "Undefined";
96+
#elif LIVE_METRICS_PROJECT
97+
string? extensionVersion = GetVersion(typeof(LiveMetrics.AzureMonitorLiveMetricsEventSource));
9698
#endif
9799

98100
if (IsDistro)
@@ -108,8 +110,8 @@ private static string GetSdkVersion()
108110
AzureMonitorExporterEventSource.Log.SdkVersionCreateFailed(ex);
109111
#elif ASP_NET_CORE_DISTRO
110112
AzureMonitorAspNetCoreEventSource.Log.SdkVersionCreateFailed(ex);
111-
#else
112-
System.Diagnostics.Debug.Write(ex.ToString());
113+
#elif LIVE_METRICS_PROJECT
114+
LiveMetrics.AzureMonitorLiveMetricsEventSource.Log.SdkVersionCreateFailed(ex);
113115
#endif
114116

115117
// Return a default value in case of failure.

sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/AzureMonitorLiveMetricsEventSource.cs

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
namespace Azure.Monitor.OpenTelemetry.LiveMetrics
1010
{
11-
// TODO: NEXT PR WILL REFACTOR EVENTSOURCE CLASSES
12-
13-
//#if LIVE_METRICS_PROJECT
1411
/// <summary>
1512
/// EventSource for the AzureMonitor LiveMetrics Client.
16-
/// EventSource Guid at Runtime: TODO.
13+
/// EventSource Guid at Runtime: 72f5588f-fa1c-502e-0627-e13dd2bd67c9.
1714
/// (This guid can be found by debugging this class and inspecting the "Log" singleton and reading the "Guid" property).
1815
/// </summary>
1916
/// <remarks>
@@ -29,7 +26,7 @@ namespace Azure.Monitor.OpenTelemetry.LiveMetrics
2926
/// </list>
3027
/// Logman Instructions:
3128
/// <list type="number">
32-
/// <item>Create a text file containing providers: <code>echo "{TODO}" > providers.txt</code></item>
29+
/// <item>Create a text file containing providers: <code>echo "{72f5588f-fa1c-502e-0627-e13dd2bd67c9}" > providers.txt</code></item>
3330
/// <item>Start collecting: <code>logman -start exporter -pf providers.txt -ets -bs 1024 -nb 100 256</code></item>
3431
/// <item>Stop collecting: <code>logman -stop exporter -ets</code></item>
3532
/// </list>
@@ -45,42 +42,6 @@ internal sealed class AzureMonitorLiveMetricsEventSource : EventSource
4542
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4643
private bool IsEnabled(EventLevel eventLevel) => IsEnabled(eventLevel, EventKeywords.All);
4744

48-
[NonEvent]
49-
public void MapLogLevelFailed(EventLevel level)
50-
{
51-
if (IsEnabled(EventLevel.Warning))
52-
{
53-
MapLogLevelFailed(level.ToString());
54-
}
55-
}
56-
57-
[NonEvent]
58-
public void ConfigureFailed(System.Exception ex)
59-
{
60-
if (IsEnabled(EventLevel.Error))
61-
{
62-
ConfigureFailed(ex.FlattenException().ToInvariantString());
63-
}
64-
}
65-
66-
[Event(1, Message = "Failed to configure AzureMonitorOptions using the connection string from environment variables due to an exception: {0}", Level = EventLevel.Error)]
67-
public void ConfigureFailed(string exceptionMessage) => WriteEvent(1, exceptionMessage);
68-
69-
[Event(2, Message = "Package reference for {0} found. Backing off from default included instrumentation. Action Required: You must manually configure this instrumentation.", Level = EventLevel.Warning)]
70-
public void FoundInstrumentationPackageReference(string packageName) => WriteEvent(2, packageName);
71-
72-
[Event(3, Message = "No instrumentation package found with name: {0}.", Level = EventLevel.Verbose)]
73-
public void NoInstrumentationPackageReference(string packageName) => WriteEvent(3, packageName);
74-
75-
[Event(4, Message = "Vendor instrumentation added for: {0}.", Level = EventLevel.Verbose)]
76-
public void VendorInstrumentationAdded(string packageName) => WriteEvent(4, packageName);
77-
78-
[Event(5, Message = "Failed to map unknown EventSource log level in AzureEventSourceLogForwarder {0}", Level = EventLevel.Warning)]
79-
public void MapLogLevelFailed(string level) => WriteEvent(5, level);
80-
81-
[Event(6, Message = "Found existing Microsoft.Extensions.Azure.AzureEventSourceLogForwarder registration.", Level = EventLevel.Informational)]
82-
public void LogForwarderIsAlreadyRegistered() => WriteEvent(6);
83-
8445
[NonEvent]
8546
public void FailedToParseConnectionString(System.Exception ex)
8647
{
@@ -105,18 +66,6 @@ public void FailedToReadEnvironmentVariables(System.Exception ex)
10566
[Event(9, Message = "Failed to read environment variables due to an exception. This may prevent the Exporter from initializing. {0}", Level = EventLevel.Warning)]
10667
public void FailedToReadEnvironmentVariables(string errorMessage) => WriteEvent(9, errorMessage);
10768

108-
[NonEvent]
109-
public void AccessingEnvironmentVariableFailedWarning(string environmentVariable, System.Exception ex)
110-
{
111-
if (IsEnabled(EventLevel.Warning))
112-
{
113-
AccessingEnvironmentVariableFailedWarning(environmentVariable, ex.FlattenException().ToInvariantString());
114-
}
115-
}
116-
117-
[Event(10, Message = "Accessing environment variable - {0} failed with exception: {1}.", Level = EventLevel.Warning)]
118-
public void AccessingEnvironmentVariableFailedWarning(string environmentVariable, string exceptionMessage) => WriteEvent(10, environmentVariable, exceptionMessage);
119-
12069
[NonEvent]
12170
public void SdkVersionCreateFailed(System.Exception ex)
12271
{
@@ -143,7 +92,6 @@ public void ErrorInitializingPartOfSdkVersion(string typeName, System.Exception
14392

14493
[Event(13, Message = "Failed to get Type version while initialize SDK version due to an exception. Not user actionable. Type: {0}. {1}", Level = EventLevel.Warning)]
14594
public void ErrorInitializingPartOfSdkVersion(string typeName, string exceptionMessage) => WriteEvent(13, typeName, exceptionMessage);
146-
14795
[Event(14, Message = "HttpPipelineBuilder is built with AAD Credentials. TokenCredential: {0} Scope: {1}", Level = EventLevel.Informational)]
14896
public void SetAADCredentialsToPipeline(string credentialTypeName, string scope) => WriteEvent(14, credentialTypeName, scope);
14997

@@ -222,18 +170,6 @@ public void StateMachineFailedWithUnknownException(System.Exception ex)
222170
[Event(18, Message = "LiveMetrics State Machine failed with exception: {0}", Level = EventLevel.Error)]
223171
public void StateMachineFailedWithUnknownException(string exceptionMessage) => WriteEvent(18, exceptionMessage);
224172

225-
[NonEvent]
226-
public void DroppedDocument(DocumentType documentType)
227-
{
228-
if (IsEnabled(EventLevel.Warning))
229-
{
230-
DroppedDocument(documentType.ToString());
231-
}
232-
}
233-
234-
[Event(19, Message = "Document was dropped. DocumentType: {0}. Not user actionable.", Level = EventLevel.Warning)]
235-
public void DroppedDocument(string documentType) => WriteEvent(19, documentType);
236-
237173
[Event(20, Message = "Failure to calculate CPU Counter. Unexpected negative timespan: PreviousCollectedTime: {0}. RecentCollectedTime: {0}. Not user actionable.", Level = EventLevel.Error)]
238174
public void ProcessCountersUnexpectedNegativeTimeSpan(long previousCollectedTime, long recentCollectedTime) => WriteEvent(20, previousCollectedTime, recentCollectedTime);
239175

@@ -261,5 +197,4 @@ public void FailedToCreateTelemetryDocument(string documentTypeName, System.Exce
261197
[Event(25, Message = "Polling Interval received from LiveMetrics service: {0}", Level = EventLevel.Informational)]
262198
public void LiveMetricsPolingIntervalReceived(int pollingInterval) => WriteEvent(25, pollingInterval);
263199
}
264-
//#endif
265200
}

0 commit comments

Comments
 (0)