Skip to content

Commit 6e67a5d

Browse files
committed
Renaming other stuff as per comments
1 parent b6752f5 commit 6e67a5d

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

tracer/src/Datadog.Trace.SourceGenerators/Configuration/ConfigurationKeysGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private static string KeyToConstName(string key, string[]? productNames = null,
469469
foreach (var productName in productNames)
470470
{
471471
if (pascalName.Length > productName.Length &&
472-
pascalName.StartsWith(productName, StringComparison.InvariantCulture))
472+
pascalName.StartsWith(productName, StringComparison.Ordinal))
473473
{
474474
pascalName = pascalName.Substring(productName.Length);
475475
break;

tracer/src/Datadog.Trace/Util/EnvironmentHelpers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static void SetEnvironmentVariable(string key, string? value)
5959

6060
/// <summary>
6161
/// Safe wrapper around Environment.GetEnvironmentVariable
62+
/// -> Don't rename unless you adapt EnvironmentGetEnvironmentVariableAnalyzer
6263
/// </summary>
6364
/// <param name="key">Name of the environment variable to fetch</param>
6465
/// <param name="defaultValue">Value to return in case of error</param>

tracer/src/Datadog.Trace/Util/EnvironmentHelpersNoLogging.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#nullable enable
77

88
using System;
9+
using System.Runtime.CompilerServices;
910
using Datadog.Trace.ClrProfiler;
10-
using Datadog.Trace.ClrProfiler.ServerlessInstrumentation;
1111
using Datadog.Trace.Configuration;
1212

1313
namespace Datadog.Trace.Util;
@@ -22,18 +22,18 @@ internal static bool IsServerlessEnvironment(out Exception? exceptionInReading)
2222
// Track the first exception encountered while reading env vars
2323
Exception? firstException = null;
2424

25-
var isServerless = TryCheckEnvVar(PlatformKeys.Aws.FunctionName, ref firstException)
26-
|| (TryCheckEnvVar(PlatformKeys.AzureAppService.SiteNameKey, ref firstException)
27-
&& !TryCheckEnvVar(ConfigurationKeys.AzureAppService.AzureAppServicesContextKey, ref firstException))
28-
|| (TryCheckEnvVar(PlatformKeys.GcpFunction.FunctionNameKey, ref firstException)
29-
&& TryCheckEnvVar(PlatformKeys.GcpFunction.FunctionTargetKey, ref firstException))
30-
|| (TryCheckEnvVar(PlatformKeys.GcpFunction.DeprecatedFunctionNameKey, ref firstException)
31-
&& TryCheckEnvVar(PlatformKeys.GcpFunction.DeprecatedProjectKey, ref firstException));
25+
var isServerless = EnvironmentVariableExists(PlatformKeys.Aws.FunctionName, ref firstException)
26+
|| (EnvironmentVariableExists(PlatformKeys.AzureAppService.SiteNameKey, ref firstException)
27+
&& !EnvironmentVariableExists(ConfigurationKeys.AzureAppService.AzureAppServicesContextKey, ref firstException))
28+
|| (EnvironmentVariableExists(PlatformKeys.GcpFunction.FunctionNameKey, ref firstException)
29+
&& EnvironmentVariableExists(PlatformKeys.GcpFunction.FunctionTargetKey, ref firstException))
30+
|| (EnvironmentVariableExists(PlatformKeys.GcpFunction.DeprecatedFunctionNameKey, ref firstException)
31+
&& EnvironmentVariableExists(PlatformKeys.GcpFunction.DeprecatedProjectKey, ref firstException));
3232
exceptionInReading = firstException;
3333
return isServerless;
3434
}
3535

36-
private static bool TryCheckEnvVar(string key, ref Exception? storedException)
36+
private static bool EnvironmentVariableExists(string key, ref Exception? storedException)
3737
{
3838
try
3939
{
@@ -63,11 +63,13 @@ public static bool IsClrProfilerAttachedSafe()
6363
}
6464
}
6565

66-
public static string? InjectionEnabled() => GetEnvironmentVariable(ConfigurationKeys.SsiDeployed);
66+
public static string? SsiDeployedEnvVar() => GetEnvironmentVariable(ConfigurationKeys.SsiDeployed);
6767

6868
public static string? ProgramData() => GetEnvironmentVariable(PlatformKeys.ProgramData);
6969

7070
#pragma warning disable RS0030
71+
// this access is allowed here as it's controlled by analyzer EnvironmentGetEnvironmentVariableAnalyzer making sure it's using a key from ConfigurationKeys/PlatformKeys
72+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7173
private static string? GetEnvironmentVariable(string key) => Environment.GetEnvironmentVariable(key);
7274
#pragma warning restore RS0030
7375
}

tracer/test/Datadog.Trace.TestHelpers/PlatformHelpers/AzureAppServiceHelper.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Specialized;
1010
using System.Runtime.InteropServices;
1111
using Datadog.Trace.Configuration;
12+
using Datadog.Trace.Util;
1213

1314
namespace Datadog.Trace.TestHelpers.PlatformHelpers;
1415

@@ -18,19 +19,7 @@ public static IConfigurationSource CreateMinimalAzureAppServiceConfiguration(str
1819
{
1920
var dict = new Dictionary<string, string>
2021
{
21-
{ "WEBSITE_SITE_NAME", siteName }
22-
};
23-
24-
return new DictionaryConfigurationSource(dict);
25-
}
26-
27-
public static IConfigurationSource CreateMinimalAzureFunctionsConfiguration(string siteName, string functionsWorkerRuntime, string functionsExtensionVersion)
28-
{
29-
var dict = new Dictionary<string, string>
30-
{
31-
{ "WEBSITE_SITE_NAME", siteName },
32-
{ "FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated" },
33-
{ "FUNCTIONS_EXTENSION_VERSION", "dotnet-isolated" }
22+
{ PlatformKeys.AzureAppService.SiteNameKey, siteName }
3423
};
3524

3625
return new DictionaryConfigurationSource(dict);
@@ -48,7 +37,7 @@ public static IConfigurationSource GetRequiredAasConfigurationValues(
4837
string enableCustomMetrics = null,
4938
bool addContextKey = true)
5039
{
51-
var vars = Environment.GetEnvironmentVariables();
40+
var vars = EnvironmentHelpers.GetEnvironmentVariables();
5241

5342
if (vars.Contains(PlatformKeys.AzureAppService.InstanceNameKey))
5443
{

0 commit comments

Comments
 (0)