Skip to content

Commit 61d3bd9

Browse files
committed
Mute CA1031 on the project level
1 parent 4fa5574 commit 61d3bd9

File tree

8 files changed

+2
-18
lines changed

8 files changed

+2
-18
lines changed

src/OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper/BootstrapperHostingStartup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ private static string GetApplicationName()
7575
{
7676
return AppDomain.CurrentDomain.FriendlyName;
7777
}
78-
#pragma warning disable CA1031 // Do not catch general exception
7978
catch (Exception ex)
80-
#pragma warning restore CA1031 // Do not catch general exception
8179
{
8280
Logger.Error($"Error getting AppDomain.CurrentDomain.FriendlyName: {ex}");
8381
return string.Empty;

src/OpenTelemetry.AutoInstrumentation.StartupHook/OpenTelemetry.AutoInstrumentation.StartupHook.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Reference: https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/1644 -->
77
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
88
<Description>StartupHook used by the OpenTelemetry.AutoInstrumentation project.</Description>
9+
<!-- Suppress CA1031 warnings about catching general exception types. In this project we need to catch all exceptions to prevent the application from crashing. -->
10+
<NoWarn>$(NoWarn);CA1031</NoWarn>
911
<AnalysisLevel>latest-All</AnalysisLevel>
1012
</PropertyGroup>
1113

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ private static string GetProcessModuleName()
4545
{
4646
return Process.GetCurrentProcess().MainModule.ModuleName;
4747
}
48-
#pragma warning disable CA1031 // Do not catch general exception
4948
catch (Exception ex)
50-
#pragma warning restore CA1031 // Do not catch general exception
5149
{
5250
Logger.Error($"Error getting Process.MainModule.ModuleName: {ex}");
5351
return string.Empty;
@@ -60,9 +58,7 @@ private static string GetAppDomainName()
6058
{
6159
return AppDomain.CurrentDomain.FriendlyName;
6260
}
63-
#pragma warning disable CA1031 // Do not catch general exception
6461
catch (Exception ex)
65-
#pragma warning restore CA1031 // Do not catch general exception
6662
{
6763
Logger.Error($"Error getting AppDomain.CurrentDomain.FriendlyName: {ex}");
6864
return string.Empty;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ internal override bool Evaluate()
5959
}
6060
}
6161
}
62-
#pragma warning disable CA1031 // Do not catch general exception
6362
catch (Exception ex)
64-
#pragma warning restore CA1031 // Do not catch general exception
6563
{
6664
// An exception in rule evaluation should not impact the result of the rule.
6765
Logger.Warning($"Rule Engine: Couldn't evaluate assembly reference file version. Exception: {ex}");

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ 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
5352
catch (Exception ex)
54-
#pragma warning restore CA1031 // Do not catch general exception
5553
{
5654
/* Native profiler is not attached. Continue with diagnosis */
5755
Logger.Debug(ex, "Error checking if native profiler is attached.");

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ internal override bool Evaluate()
4040
}
4141
}
4242
}
43-
#pragma warning disable CA1031 // Do not catch general exception
4443
catch (Exception ex)
45-
#pragma warning restore CA1031 // Do not catch general exception
4644
{
4745
// Exception in evaluation should not throw or crash the process.
4846
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ private static bool EvaluateRule(Rule rule)
7070
return false;
7171
}
7272
}
73-
#pragma warning disable CA1031 // Do not catch general exception
7473
catch (Exception ex)
75-
#pragma warning restore CA1031 // Do not catch general exception
7674
{
7775
Logger.Warning($"Error evaluating rule '{rule.Name}': {ex.Message}");
7876
}

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

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

0 commit comments

Comments
 (0)