Remove unnecessary try catch for SecurityException (#2531)

This commit is contained in:
Robert Pająk 2021-10-27 16:39:13 +02:00 committed by GitHub
parent 635028834c
commit d026232c15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 29 deletions

View File

@ -314,12 +314,6 @@ namespace OpenTelemetry.Internal
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)
{

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using System.Security;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Resources
@ -30,17 +29,10 @@ namespace OpenTelemetry.Resources
{
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;

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using System.Security;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Resources
@ -28,19 +27,12 @@ namespace OpenTelemetry.Resources
{
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;