Skip to content

Commit 802c07b

Browse files
committed
Mute CA1031
1 parent 588fb4c commit 802c07b

File tree

8 files changed

+41
-5
lines changed

8 files changed

+41
-5
lines changed

src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/ApplicationInExcludeListRule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ private static string GetProcessModuleName()
4545
{
4646
return Process.GetCurrentProcess().MainModule.ModuleName;
4747
}
48+
#pragma warning disable CA1031 // Do not catch general exception
4849
catch (Exception ex)
50+
#pragma warning restore CA1031 // Do not catch general exception
4951
{
5052
Logger.Error($"Error getting Process.MainModule.ModuleName: {ex}");
5153
return string.Empty;
@@ -58,7 +60,9 @@ private static string GetAppDomainName()
5860
{
5961
return AppDomain.CurrentDomain.FriendlyName;
6062
}
63+
#pragma warning disable CA1031 // Do not catch general exception
6164
catch (Exception ex)
65+
#pragma warning restore CA1031 // Do not catch general exception
6266
{
6367
Logger.Error($"Error getting AppDomain.CurrentDomain.FriendlyName: {ex}");
6468
return string.Empty;

src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/AssemblyFileVersionRule.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ internal override bool Evaluate()
5959
}
6060
}
6161
}
62+
#pragma warning disable CA1031 // Do not catch general exception
6263
catch (Exception ex)
64+
#pragma warning restore CA1031 // Do not catch general exception
6365
{
64-
// Exception in rule evaluation should not impact the result of the rule.
66+
// An exception in rule evaluation should not impact the result of the rule.
6567
Logger.Warning($"Rule Engine: Couldn't evaluate assembly reference file version. Exception: {ex}");
6668
}
6769

src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/NativeProfilerDiagnosticsRule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ internal override bool Evaluate()
4949

5050
Logger.Error("IsProfilerAttached returned false, the native log should describe the root cause.");
5151
}
52+
#pragma warning disable CA1031 // Do not catch general exception
5253
catch (Exception ex)
54+
#pragma warning restore CA1031 // Do not catch general exception
5355
{
5456
/* Native profiler is not attached. Continue with diagnosis */
5557
Logger.Debug(ex, "Error checking if native profiler is attached.");

src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/OpenTelemetrySdkMinimumVersionRule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ internal override bool Evaluate()
4040
}
4141
}
4242
}
43+
#pragma warning disable CA1031 // Do not catch general exception
4344
catch (Exception ex)
45+
#pragma warning restore CA1031 // Do not catch general exception
4446
{
4547
// Exception in evaluation should not throw or crash the process.
4648
logger.Information($"Rule Engine: Couldn't evaluate reference to OpenTelemetry Sdk in an app. Exception: {ex}");

src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private static bool EvaluateRule(Rule rule)
7070
return false;
7171
}
7272
}
73+
#pragma warning disable CA1031 // Do not catch general exception
7374
catch (Exception ex)
75+
#pragma warning restore CA1031 // Do not catch general exception
7476
{
7577
Logger.Warning($"Error evaluating rule '{rule.Name}': {ex.Message}");
7678
}

src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuntimeStoreDiagnosticRule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ internal override bool Evaluate()
4949
{
5050
appInstrumentationAssembly = Assembly.Load(assemblyName);
5151
}
52+
#pragma warning disable CA1031 // Do not catch general exception
5253
catch (Exception ex)
54+
#pragma warning restore CA1031 // Do not catch general exception
5355
{
5456
Logger.Warning(ex, $"Rule Engine: Assembly load failed. Skipping rule evaluation for assembly - {assemblyName}");
5557
continue;
@@ -84,7 +86,9 @@ internal override bool Evaluate()
8486
}
8587
}
8688
}
89+
#pragma warning disable CA1031 // Do not catch general exception
8790
catch (Exception ex)
91+
#pragma warning restore CA1031 // Do not catch general exception
8892
{
8993
// Exception in rule evaluation should not impact the result of the rule.
9094
Logger.Warning(ex, "Rule Engine: Couldn't evaluate reference to runtime store assemblies in an app.");

src/OpenTelemetry.AutoInstrumentation/Logging/InternalLogger.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ private void WriteImpl(LogLevel level, Exception? exception, string messageTempl
228228
WriteEventSourceLog(level, rawMessage);
229229
}
230230
}
231+
#pragma warning disable CA1031 // Do not catch general exception
231232
catch (Exception)
233+
#pragma warning restore CA1031 // Do not catch general exception
232234
{
233235
try
234236
{
@@ -238,7 +240,9 @@ private void WriteImpl(LogLevel level, Exception? exception, string messageTempl
238240
: "; " + string.Join(", ", args);
239241
Console.Error.WriteLine($"{messageTemplate}{properties}{ex}");
240242
}
241-
catch
243+
#pragma warning disable CA1031 // Do not catch general exception
244+
catch (Exception)
245+
#pragma warning restore CA1031 // Do not catch general exception
242246
{
243247
// ignore
244248
}

src/OpenTelemetry.AutoInstrumentation/Logging/OtelLogging.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public static void CloseLogger(string suffix, IOtelLogger otelLogger)
5454
otelLogger.Close();
5555
}
5656
}
57+
#pragma warning disable CA1031 // Do not catch general exception
5758
catch (Exception)
59+
#pragma warning restore CA1031 // Do not catch general exception
5860
{
5961
// intentionally empty
6062
}
@@ -85,7 +87,9 @@ internal static void Reset()
8587
_ => logLevel
8688
};
8789
}
90+
#pragma warning disable CA1031 // Do not catch general exception
8891
catch (Exception)
92+
#pragma warning restore CA1031 // Do not catch general exception
8993
{
9094
// theoretically, can happen when process has no privileges to check env
9195
}
@@ -110,7 +114,9 @@ internal static LogSink GetConfiguredLogSink()
110114
_ => logSink
111115
};
112116
}
117+
#pragma warning disable CA1031 // Do not catch general exception
113118
catch (Exception)
119+
#pragma warning restore CA1031 // Do not catch general exception
114120
{
115121
// theoretically, can happen when process has no privileges to check env
116122
}
@@ -132,7 +138,9 @@ internal static long GetConfiguredFileSizeLimitBytes()
132138

133139
return long.TryParse(configuredFileSizeLimit, out var limit) && limit > 0 ? limit : defaultFileSizeLimitBytes;
134140
}
141+
#pragma warning disable CA1031 // Do not catch general exception
135142
catch (Exception)
143+
#pragma warning restore CA1031 // Do not catch general exception
136144
{
137145
// theoretically, can happen when process has no privileges to check env
138146
return defaultFileSizeLimitBytes;
@@ -188,7 +196,9 @@ private static ISink CreateSink(string suffix)
188196
return new PeriodicFlushToDiskSink(rollingFileSink, TimeSpan.FromSeconds(5));
189197
}
190198
}
199+
#pragma warning disable CA1031 // Do not catch general exception
191200
catch (Exception)
201+
#pragma warning restore CA1031 // Do not catch general exception
192202
{
193203
// unable to configure logging to a file
194204
}
@@ -208,7 +218,9 @@ private static string GetLogFileName(string suffix)
208218
? $"otel-dotnet-auto-{process.Id}-{appDomainName}-.log"
209219
: $"otel-dotnet-auto-{process.Id}-{appDomainName}-{suffix}-.log";
210220
}
211-
catch
221+
#pragma warning disable CA1031 // Do not catch general exception
222+
catch (Exception)
223+
#pragma warning restore CA1031 // Do not catch general exception
212224
{
213225
// We can't get the process info
214226
return string.IsNullOrEmpty(suffix)
@@ -250,7 +262,9 @@ private static string GetEncodedAppDomainName()
250262

251263
logDirectory = CreateDirectoryIfMissing(logDirectory) ?? Path.GetTempPath();
252264
}
253-
catch
265+
#pragma warning disable CA1031 // Do not catch general exception
266+
catch (Exception)
267+
#pragma warning restore CA1031 // Do not catch general exception
254268
{
255269
// The try block may throw a SecurityException if not granted the System.Security.Permissions.FileIOPermission
256270
// because of the following API calls
@@ -272,7 +286,9 @@ private static string GetEncodedAppDomainName()
272286
Directory.CreateDirectory(pathToCreate);
273287
return pathToCreate;
274288
}
275-
catch
289+
#pragma warning disable CA1031 // Do not catch general exception
290+
catch (Exception)
291+
#pragma warning restore CA1031 // Do not catch general exception
276292
{
277293
// Unable to create the directory meaning that the user will have to create it on their own.
278294
// It is unsafe to log here, so return null to defer deciding what the path is

0 commit comments

Comments
 (0)