Skip to content

Commit

Permalink
OtelServiceNameEnvVarDetector handles SecurityException
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Jul 30, 2021
1 parent 3268d71 commit e0a9aa4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Resources/OtelEnvResourceDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Resource Detect()
}
catch (Exception ex)
{
OpenTelemetrySdkEventSource.Log.ResourceDetectorFailed("OtelEnvResourceDetector", ex.Message);
OpenTelemetrySdkEventSource.Log.ResourceDetectorFailed(nameof(OtelEnvResourceDetector), ex.Message);
}

return resource;
Expand Down
19 changes: 14 additions & 5 deletions src/OpenTelemetry/Resources/OtelServiceNameEnvVarDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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

namespace OpenTelemetry.Resources
{
Expand All @@ -27,13 +29,20 @@ public Resource Detect()
{
var resource = Resource.Empty;

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

return resource;
Expand Down

0 comments on commit e0a9aa4

Please sign in to comment.