Skip to content

Commit 6c3bcc0

Browse files
author
Timothy Mothra
authored
[AzureMonitorExporter] refactor logging (part6) (Azure#37224)
* messages * remove IsEnabled check when not necessary * added more information to SDK Version * pr feedback
1 parent dcd6306 commit 6c3bcc0

File tree

6 files changed

+76
-24
lines changed

6 files changed

+76
-24
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.New.cs

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ public void TransmissionFailed(bool fromStorage, int statusCode, ConnectionVars
5151
public void TransmissionFailed(string message, string retryDetails, string metaData) => WriteEvent(8, message, retryDetails, metaData);
5252

5353
[Event(9, Message = "{0} has been disposed.", Level = EventLevel.Informational)]
54-
public void DisposedObject(string name)
55-
{
56-
if (IsEnabled(EventLevel.Informational))
57-
{
58-
WriteEvent(9, name);
59-
}
60-
}
54+
public void DisposedObject(string name) => WriteEvent(9, name);
6155

6256
[NonEvent]
6357
public void VmMetadataFailed(Exception ex)
@@ -96,13 +90,7 @@ public void FailedToParseConnectionString(Exception ex)
9690
public void FailedToParseConnectionString(string exceptionMessage) => WriteEvent(12, exceptionMessage);
9791

9892
[Event(13, Message = "Unsupported Metric Type '{0}' cannot be exported.", Level = EventLevel.Warning)]
99-
public void UnsupportedMetricType(string metricTypeName)
100-
{
101-
if (IsEnabled(EventLevel.Warning))
102-
{
103-
WriteEvent(13, metricTypeName);
104-
}
105-
}
93+
public void UnsupportedMetricType(string metricTypeName) => WriteEvent(13, metricTypeName);
10694

10795
[NonEvent]
10896
public void FailedToConvertLogRecord(Exception ex)
@@ -153,12 +141,75 @@ public void FailedToExtractActivityEvent(string activitySourceName, string activ
153141
public void FailedToExtractActivityEvent(string activitySourceName, string activityDisplayName, string exceptionMessage) => WriteEvent(17, activitySourceName, activityDisplayName, exceptionMessage);
154142

155143
[Event(18, Message = "Maximum count of {0} Activity Links reached. Excess Links are dropped. ActivitySource: {1}. Activity: {2}.", Level = EventLevel.Warning)]
156-
public void ActivityLinksIgnored(int maxLinksAllowed, string activitySourceName, string activityDisplayName)
144+
public void ActivityLinksIgnored(int maxLinksAllowed, string activitySourceName, string activityDisplayName) => WriteEvent(18, maxLinksAllowed, activitySourceName, activityDisplayName);
145+
146+
[Event(19, Message = "Failed to parse redirect headers. Not user actionable.", Level = EventLevel.Warning)]
147+
public void RedirectHeaderParseFailed() => WriteEvent(19);
148+
149+
[Event(20, Message = "Failed to parse redirect cache, using default. Not user actionable.", Level = EventLevel.Warning)]
150+
public void ParseRedirectCacheFailed() => WriteEvent(20);
151+
152+
[NonEvent]
153+
public void ErrorCreatingStorageFolder(string path, Exception ex)
154+
{
155+
if (IsEnabled(EventLevel.Error))
156+
{
157+
ErrorCreatingStorageFolder(path, ex.FlattenException().ToInvariantString());
158+
}
159+
}
160+
161+
[Event(21, Message = "Failed to create a storage directory at path '{0}' due to an exception. If a storage directory cannot be created, telemetry may be lost. {1}", Level = EventLevel.Error)]
162+
public void ErrorCreatingStorageFolder(string path, string exceptionMessage) => WriteEvent(21, path, exceptionMessage);
163+
164+
[NonEvent]
165+
public void ErrorInitializingRoleInstanceToHostName(Exception ex)
166+
{
167+
if (IsEnabled(EventLevel.Error))
168+
{
169+
ErrorInitializingRoleInstanceToHostName(ex.FlattenException().ToInvariantString());
170+
}
171+
}
172+
173+
[Event(22, Message = "Failed to initialize Role Instance due to an exception. Role Instance will be missing from telemetry. {0}", Level = EventLevel.Error)]
174+
public void ErrorInitializingRoleInstanceToHostName(string exceptionMessage) => WriteEvent(22, exceptionMessage);
175+
176+
[NonEvent]
177+
public void ErrorInitializingPartOfSdkVersion(string typeName, Exception ex)
178+
{
179+
if (IsEnabled(EventLevel.Warning))
180+
{
181+
ErrorInitializingPartOfSdkVersion(typeName, ex.FlattenException().ToInvariantString());
182+
}
183+
}
184+
185+
[Event(23, Message = "Failed to get Type version while initialize SDK version due to an exception. Not user actionable. Type: {0}. {1}", Level = EventLevel.Warning)]
186+
public void ErrorInitializingPartOfSdkVersion(string typeName, string exceptionMessage) => WriteEvent(23, typeName, exceptionMessage);
187+
188+
[NonEvent]
189+
public void SdkVersionCreateFailed(Exception ex)
157190
{
158191
if (IsEnabled(EventLevel.Warning))
159192
{
160-
WriteEvent(18, maxLinksAllowed, activitySourceName, activityDisplayName);
193+
SdkVersionCreateFailed(ex.FlattenException().ToInvariantString());
194+
}
195+
}
196+
197+
[Event(24, Message = "Failed to create an SDK version due to an exception. Not user actionable. {0}", Level = EventLevel.Warning)]
198+
public void SdkVersionCreateFailed(string exceptionMessage) => WriteEvent(24, exceptionMessage);
199+
200+
[NonEvent]
201+
public void FailedToTransmitFromStorage(Exception ex)
202+
{
203+
if (IsEnabled(EventLevel.Error))
204+
{
205+
FailedToTransmitFromStorage(ex.FlattenException().ToInvariantString());
161206
}
162207
}
208+
209+
[Event(25, Message = "Failed to transmit from storage due to an exception: {0}", Level = EventLevel.Error)]
210+
public void FailedToTransmitFromStorage(string exceptionMessage) => WriteEvent(25, exceptionMessage);
211+
212+
[Event(26, Message = "Successfully transmitted a blob from storage.", Level = EventLevel.Informational)]
213+
public void TransmitFromStorageSuccess() => WriteEvent(26);
163214
}
164215
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPi
5353
{
5454
if (!TryGetRedirectUri(response, out redirectUri))
5555
{
56-
AzureMonitorExporterEventSource.Log.WriteInformational("RedirectHeaderParseFailed", "Failed to parse redirect headers.");
56+
AzureMonitorExporterEventSource.Log.RedirectHeaderParseFailed();
5757
break;
5858
}
5959

@@ -77,7 +77,7 @@ internal async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPi
7777
if (!TryGetRedirectCacheTimeSpan(response, out TimeSpan cacheExpirationDuration))
7878
{
7979
// if failed to read cache, use default
80-
AzureMonitorExporterEventSource.Log.WriteWarning("ParseRedirectCacheFailed", "Failed to parse redirect cache, using default.");
80+
AzureMonitorExporterEventSource.Log.ParseRedirectCacheFailed();
8181
cacheExpirationDuration = _defaultCacheExpirationDuration;
8282
}
8383

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public bool CreateDirectory(string path)
4545
}
4646
catch (Exception ex)
4747
{
48-
AzureMonitorExporterEventSource.Log.WriteError("ErrorCreatingStorageFolder", ex);
48+
AzureMonitorExporterEventSource.Log.ErrorCreatingStorageFolder(path, ex);
4949
return false;
5050
}
5151
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ internal static class ResourceExtensions
9292
}
9393
catch (Exception ex)
9494
{
95-
AzureMonitorExporterEventSource.Log.WriteError("ErrorInitializingRoleInstanceToHostName", ex);
95+
AzureMonitorExporterEventSource.Log.ErrorInitializingRoleInstanceToHostName(ex);
9696
}
9797

9898
if (aksResourceProcessor != null)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal static string? SdkVersionPrefix
4343
}
4444
catch (Exception ex)
4545
{
46-
AzureMonitorExporterEventSource.Log.WriteError("ErrorInitializingPartOfSdkVersion", ex);
46+
AzureMonitorExporterEventSource.Log.ErrorInitializingPartOfSdkVersion(type.Name, ex);
4747
return null;
4848
}
4949
}
@@ -61,7 +61,7 @@ internal static string? SdkVersionPrefix
6161
}
6262
catch (Exception ex)
6363
{
64-
AzureMonitorExporterEventSource.Log.WriteWarning("SdkVersionCreateFailed", ex);
64+
AzureMonitorExporterEventSource.Log.SdkVersionCreateFailed(ex);
6565
return null;
6666
}
6767
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ internal void TransmitFromStorage(object? sender, ElapsedEventArgs? e)
5454
_transmissionStateManager.ResetConsecutiveErrors();
5555
_transmissionStateManager.CloseTransmission();
5656

57-
AzureMonitorExporterEventSource.Log.WriteInformational("TransmitFromStorageSuccess", "Successfully transmitted a blob from storage.");
57+
AzureMonitorExporterEventSource.Log.TransmitFromStorageSuccess();
5858

5959
// In case if the delete fails, there is a possibility
6060
// that the current batch will be transmitted more than once resulting in duplicates.
61+
// TODO: TryDelete returns a boolean, should we log when this occurs?
6162
blob.TryDelete();
6263
}
6364
else
@@ -69,7 +70,7 @@ internal void TransmitFromStorage(object? sender, ElapsedEventArgs? e)
6970
}
7071
catch (Exception ex)
7172
{
72-
AzureMonitorExporterEventSource.Log.WriteError("FailedToTransmitFromStorage", ex);
73+
AzureMonitorExporterEventSource.Log.FailedToTransmitFromStorage(ex);
7374
}
7475
}
7576
else

0 commit comments

Comments
 (0)