Skip to content

Commit

Permalink
Remove unnecessary try catch for SecurityException
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Oct 27, 2021
1 parent 6350288 commit 806a90f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
6 changes: 0 additions & 6 deletions src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,6 @@ public void SelfDiagnosticsFileCreateException(string logDirectory, string excep
this.WriteEvent(26, logDirectory, exception);
}

[Event(27, Message = "Failed to create resource from ResourceDetector: '{0}' due to '{1}'.", Level = EventLevel.Warning)]
public void ResourceDetectorFailed(string resourceDetector, string issue)
{
this.WriteEvent(27, resourceDetector, issue);
}

[Event(28, Message = "Unknown error in TracerProvider '{0}': '{1}'.", Level = EventLevel.Error)]
public void TracerProviderException(string evnt, string ex)
{
Expand Down
14 changes: 3 additions & 11 deletions src/OpenTelemetry/Resources/OtelEnvResourceDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System.Collections.Generic;
using System.Security;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Resources
Expand All @@ -30,17 +29,10 @@ public Resource Detect()
{
var resource = Resource.Empty;

try
if (EnvironmentVariableHelper.LoadString(EnvVarKey, out string envResourceAttributeValue))
{
if (EnvironmentVariableHelper.LoadString(EnvVarKey, out string envResourceAttributeValue))
{
var attributes = ParseResourceAttributes(envResourceAttributeValue);
resource = new Resource(attributes);
}
}
catch (SecurityException ex)
{
OpenTelemetrySdkEventSource.Log.ResourceDetectorFailed(nameof(OtelEnvResourceDetector), ex.Message);
var attributes = ParseResourceAttributes(envResourceAttributeValue);
resource = new Resource(attributes);
}

return resource;
Expand Down
16 changes: 4 additions & 12 deletions src/OpenTelemetry/Resources/OtelServiceNameEnvVarDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System.Collections.Generic;
using System.Security;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Resources
Expand All @@ -28,19 +27,12 @@ public Resource Detect()
{
var resource = Resource.Empty;

try
if (EnvironmentVariableHelper.LoadString(EnvVarKey, out string envResourceAttributeValue))
{
if (EnvironmentVariableHelper.LoadString(EnvVarKey, out string envResourceAttributeValue))
resource = new Resource(new Dictionary<string, object>
{
resource = new Resource(new Dictionary<string, object>
{
[ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue,
});
}
}
catch (SecurityException ex)
{
OpenTelemetrySdkEventSource.Log.ResourceDetectorFailed(nameof(OtelServiceNameEnvVarDetector), ex.Message);
[ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue,
});
}

return resource;
Expand Down

0 comments on commit 806a90f

Please sign in to comment.