Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary try catch for SecurityException #2531

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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