Skip to content

Commit 65fbbec

Browse files
committed
Adapt platform keys where it's called
1 parent acd50ee commit 65fbbec

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

tracer/src/Datadog.Trace/ClrProfiler/Instrumentation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ private static void StartDiagnosticManager()
473473
var observers = new List<DiagnosticObserver>();
474474

475475
// get environment variables directly so we don't access Trace.Instance yet
476-
var functionsExtensionVersion = EnvironmentHelpers.GetEnvironmentVariable(Datadog.Trace.Configuration.ConfigurationKeys.AzureFunctions.FunctionsExtensionVersion);
477-
var functionsWorkerRuntime = EnvironmentHelpers.GetEnvironmentVariable(Datadog.Trace.Configuration.ConfigurationKeys.AzureFunctions.FunctionsWorkerRuntime);
476+
var functionsExtensionVersion = EnvironmentHelpers.GetEnvironmentVariable(PlatformKeys.AzureFunctions.FunctionsExtensionVersion);
477+
var functionsWorkerRuntime = EnvironmentHelpers.GetEnvironmentVariable(PlatformKeys.AzureFunctions.FunctionsWorkerRuntime);
478478

479479
if (!string.IsNullOrEmpty(functionsExtensionVersion) && !string.IsNullOrEmpty(functionsWorkerRuntime))
480480
{

tracer/src/Datadog.Trace/Configuration/ImmutableAzureAppServiceSettings.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ public ImmutableAzureAppServiceSettings(IConfigurationSource? source, IConfigura
6161
}
6262

6363
SubscriptionId = GetSubscriptionId(source, telemetry);
64-
ResourceGroup = config.WithKeys(ConfigurationKeys.AzureAppService.ResourceGroupKey).AsString();
65-
SiteName = config.WithKeys(ConfigurationKeys.AzureAppService.SiteNameKey).AsString();
64+
ResourceGroup = config.WithKeys(PlatformKeys.AzureAppService.ResourceGroupKey).AsString();
65+
SiteName = config.WithKeys(PlatformKeys.AzureAppService.SiteNameKey).AsString();
6666
ResourceId = CompileResourceId(subscriptionId: SubscriptionId, siteName: SiteName, resourceGroup: ResourceGroup);
67-
InstanceId = config.WithKeys(ConfigurationKeys.AzureAppService.InstanceIdKey).AsString("unknown");
68-
InstanceName = config.WithKeys(ConfigurationKeys.AzureAppService.InstanceNameKey).AsString("unknown");
69-
OperatingSystem = config.WithKeys(ConfigurationKeys.AzureAppService.OperatingSystemKey).AsString("unknown");
67+
InstanceId = config.WithKeys(PlatformKeys.AzureAppService.InstanceIdKey).AsString("unknown");
68+
InstanceName = config.WithKeys(PlatformKeys.AzureAppService.InstanceNameKey).AsString("unknown");
69+
OperatingSystem = config.WithKeys(PlatformKeys.AzureAppService.OperatingSystemKey).AsString("unknown");
7070
SiteExtensionVersion = config.WithKeys(ConfigurationKeys.AzureAppService.SiteExtensionVersionKey).AsString("unknown");
71-
WebsiteSKU = config.WithKeys(ConfigurationKeys.AzureAppService.WebsiteSKU).AsString();
71+
WebsiteSKU = config.WithKeys(PlatformKeys.AzureAppService.WebsiteSKU).AsString();
7272

73-
FunctionsWorkerRuntime = config.WithKeys(ConfigurationKeys.AzureFunctions.FunctionsWorkerRuntime).AsString();
74-
FunctionsExtensionVersion = config.WithKeys(ConfigurationKeys.AzureFunctions.FunctionsExtensionVersion).AsString();
73+
FunctionsWorkerRuntime = config.WithKeys(PlatformKeys.AzureFunctions.FunctionsWorkerRuntime).AsString();
74+
FunctionsExtensionVersion = config.WithKeys(PlatformKeys.AzureFunctions.FunctionsExtensionVersion).AsString();
7575

7676
if (FunctionsWorkerRuntime is not null && FunctionsExtensionVersion is not null)
7777
{
@@ -142,19 +142,19 @@ private static bool ShouldSkipClientSpanWithinFunctions(Scope? scope)
142142
{
143143
if (subscriptionId == null)
144144
{
145-
Log.Warning("Could not successfully retrieve the subscription ID from variable: {Variable}", ConfigurationKeys.AzureAppService.WebsiteOwnerNameKey);
145+
Log.Warning("Could not successfully retrieve the subscription ID from variable: {Variable}", PlatformKeys.AzureAppService.WebsiteOwnerNameKey);
146146
return null;
147147
}
148148

149149
if (siteName == null)
150150
{
151-
Log.Warning("Could not successfully retrieve the deployment ID from variable: {Variable}", ConfigurationKeys.AzureAppService.SiteNameKey);
151+
Log.Warning("Could not successfully retrieve the deployment ID from variable: {Variable}", PlatformKeys.AzureAppService.SiteNameKey);
152152
return null;
153153
}
154154

155155
if (resourceGroup == null)
156156
{
157-
Log.Warning("Could not successfully retrieve the resource group name from variable: {Variable}", ConfigurationKeys.AzureAppService.ResourceGroupKey);
157+
Log.Warning("Could not successfully retrieve the resource group name from variable: {Variable}", PlatformKeys.AzureAppService.ResourceGroupKey);
158158
return null;
159159
}
160160

@@ -164,7 +164,7 @@ private static bool ShouldSkipClientSpanWithinFunctions(Scope? scope)
164164
private static string? GetSubscriptionId(IConfigurationSource source, IConfigurationTelemetry telemetry)
165165
{
166166
var websiteOwner = new ConfigurationBuilder(source, telemetry)
167-
.WithKeys(ConfigurationKeys.AzureAppService.WebsiteOwnerNameKey)
167+
.WithKeys(PlatformKeys.AzureAppService.WebsiteOwnerNameKey)
168168
.AsString(websiteOwner => !string.IsNullOrWhiteSpace(websiteOwner));
169169

170170
if (!string.IsNullOrWhiteSpace(websiteOwner))
@@ -186,7 +186,7 @@ private static bool ShouldSkipClientSpanWithinFunctions(Scope? scope)
186186
public static bool IsRunningInAzureAppServices(IConfigurationSource source, IConfigurationTelemetry telemetry)
187187
{
188188
var siteName = new ConfigurationBuilder(source, telemetry)
189-
.WithKeys(ConfigurationKeys.AzureAppService.SiteNameKey)
189+
.WithKeys(PlatformKeys.AzureAppService.SiteNameKey)
190190
.AsString();
191191

192192
return !string.IsNullOrEmpty(siteName);
@@ -200,17 +200,17 @@ public static bool IsRunningInAzureAppServices(IConfigurationSource source, ICon
200200
public static bool IsRunningInAzureFunctions(IConfigurationSource source, IConfigurationTelemetry telemetry)
201201
{
202202
var siteName = new ConfigurationBuilder(source, telemetry)
203-
.WithKeys(ConfigurationKeys.AzureAppService.SiteNameKey)
203+
.WithKeys(PlatformKeys.AzureAppService.SiteNameKey)
204204
.AsString();
205205

206206
// "dotnet", "dotnet-isolated"
207207
var workerRuntime = new ConfigurationBuilder(source, telemetry)
208-
.WithKeys(ConfigurationKeys.AzureFunctions.FunctionsWorkerRuntime)
208+
.WithKeys(PlatformKeys.AzureFunctions.FunctionsWorkerRuntime)
209209
.AsString();
210210

211211
// "~4", "~1"
212212
var extensionVersion = new ConfigurationBuilder(source, telemetry)
213-
.WithKeys(ConfigurationKeys.AzureFunctions.FunctionsExtensionVersion)
213+
.WithKeys(PlatformKeys.AzureFunctions.FunctionsExtensionVersion)
214214
.AsString();
215215

216216
return !string.IsNullOrEmpty(siteName) &&

tracer/src/Datadog.Trace/Configuration/ImmutableGCPFunctionSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public ImmutableGCPFunctionSettings(IConfigurationSource? source, IConfiguration
2222
source ??= NullConfigurationSource.Instance;
2323
var config = new ConfigurationBuilder(source, telemetry);
2424

25-
var deprecatedFunctionKey = config.WithKeys(ConfigurationKeys.GCPFunction.DeprecatedFunctionNameKey).AsString();
26-
var deprecatedProjectKey = config.WithKeys(ConfigurationKeys.GCPFunction.DeprecatedProjectKey).AsString();
25+
var deprecatedFunctionKey = config.WithKeys(PlatformKeys.GCPFunction.DeprecatedFunctionNameKey).AsString();
26+
var deprecatedProjectKey = config.WithKeys(PlatformKeys.GCPFunction.DeprecatedProjectKey).AsString();
2727
IsDeprecatedFunction = deprecatedFunctionKey != null && deprecatedProjectKey != null;
2828

29-
var functionNameKey = config.WithKeys(ConfigurationKeys.GCPFunction.FunctionNameKey).AsString();
30-
var functionTargetKey = config.WithKeys(ConfigurationKeys.GCPFunction.FunctionTargetKey).AsString();
29+
var functionNameKey = config.WithKeys(PlatformKeys.GCPFunction.FunctionNameKey).AsString();
30+
var functionTargetKey = config.WithKeys(PlatformKeys.GCPFunction.FunctionTargetKey).AsString();
3131
IsNewerFunction = functionNameKey != null && functionTargetKey != null;
3232

3333
IsGCPFunction = IsDeprecatedFunction || IsNewerFunction;

tracer/src/Datadog.Trace/Configuration/IntegrationSettings.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,28 @@ internal IntegrationSettings(string integrationName, IConfigurationSource? sourc
3535
// We don't record these in telemetry, because they're blocked anyway
3636
var config = new ConfigurationBuilder(source ?? NullConfigurationSource.Instance, NullConfigurationTelemetry.Instance);
3737
var upperName = integrationName.ToUpperInvariant();
38-
Enabled = isExplicitlyDisabled ? false : (config
39-
.WithKeys(
40-
string.Format(ConfigurationKeys.Integrations.Enabled, upperName),
41-
string.Format(ConfigurationKeys.Integrations.Enabled, integrationName),
42-
$"DD_{integrationName}_ENABLED")
43-
.AsBool()
44-
?? fallback?.Enabled);
38+
Enabled = isExplicitlyDisabled ? false : config
39+
.WithKeys(
40+
$"DD_TRACE_{upperName}_ENABLED",
41+
$"DD_TRACE_{integrationName}_ENABLED",
42+
$"DD_{integrationName}_ENABLED")
43+
.AsBool()
44+
?? fallback?.Enabled;
4545

4646
#pragma warning disable 618 // App analytics is deprecated, but still used
4747
AnalyticsEnabled = config
4848
.WithKeys(
49-
string.Format(ConfigurationKeys.Integrations.AnalyticsEnabled, upperName),
50-
string.Format(ConfigurationKeys.Integrations.AnalyticsEnabled, integrationName),
49+
$"DD_TRACE_{upperName}_ANALYTICS_ENABLED",
50+
$"DD_TRACE_{integrationName}_ANALYTICS_ENABLED",
5151
$"DD_{integrationName}_ANALYTICS_ENABLED")
5252
.AsBool()
5353
?? fallback?.AnalyticsEnabled;
5454

55+
const string analyticsSampleRateKey = "DD_TRACE_{0}_ANALYTICS_SAMPLE_RATE";
5556
AnalyticsSampleRate = config
5657
.WithKeys(
57-
string.Format(ConfigurationKeys.Integrations.AnalyticsSampleRate, upperName),
58-
string.Format(ConfigurationKeys.Integrations.AnalyticsSampleRate, integrationName),
58+
string.Format(analyticsSampleRateKey, upperName),
59+
string.Format(analyticsSampleRateKey, integrationName),
5960
$"DD_{integrationName}_ANALYTICS_SAMPLE_RATE")
6061
.AsDouble(fallback?.AnalyticsSampleRate ?? 1.0);
6162
#pragma warning restore 618

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static IDictionary GetEnvironmentVariables()
104104
/// </summary>
105105
public static bool IsAzureAppServices()
106106
{
107-
return EnvironmentVariableExists(ConfigurationKeys.AzureAppService.SiteNameKey);
107+
return EnvironmentVariableExists(PlatformKeys.AzureAppService.SiteNameKey);
108108
}
109109

110110
/// <summary>
@@ -116,8 +116,8 @@ public static bool IsAzureAppServices()
116116
public static bool IsAzureFunctions()
117117
{
118118
return IsAzureAppServices() &&
119-
EnvironmentVariableExists(ConfigurationKeys.AzureFunctions.FunctionsWorkerRuntime) &&
120-
EnvironmentVariableExists(ConfigurationKeys.AzureFunctions.FunctionsExtensionVersion);
119+
EnvironmentVariableExists(PlatformKeys.AzureFunctions.FunctionsWorkerRuntime) &&
120+
EnvironmentVariableExists(PlatformKeys.AzureFunctions.FunctionsExtensionVersion);
121121
}
122122

123123
/// <summary>
@@ -148,10 +148,10 @@ public static bool IsAwsLambda()
148148
/// </summary>
149149
public static bool IsGoogleCloudFunctions()
150150
{
151-
return (EnvironmentVariableExists(ConfigurationKeys.GCPFunction.FunctionNameKey) &&
152-
EnvironmentVariableExists(ConfigurationKeys.GCPFunction.FunctionTargetKey)) ||
153-
(EnvironmentVariableExists(ConfigurationKeys.GCPFunction.DeprecatedFunctionNameKey) &&
154-
EnvironmentVariableExists(ConfigurationKeys.GCPFunction.DeprecatedProjectKey));
151+
return (EnvironmentVariableExists(PlatformKeys.GCPFunction.FunctionNameKey) &&
152+
EnvironmentVariableExists(PlatformKeys.GCPFunction.FunctionTargetKey)) ||
153+
(EnvironmentVariableExists(PlatformKeys.GCPFunction.DeprecatedFunctionNameKey) &&
154+
EnvironmentVariableExists(PlatformKeys.GCPFunction.DeprecatedProjectKey));
155155
}
156156

157157
/// <summary>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ internal static bool IsServerlessEnvironment(out Exception? exceptionInReading)
2424
Exception? firstException = null;
2525

2626
var isServerless = CheckEnvVar(LambdaMetadata.FunctionNameEnvVar, ref firstException)
27-
|| (CheckEnvVar(ConfigurationKeys.AzureAppService.SiteNameKey, ref firstException)
27+
|| (CheckEnvVar(PlatformKeys.AzureAppService.SiteNameKey, ref firstException)
2828
&& !CheckEnvVar(ConfigurationKeys.AzureAppService.AzureAppServicesContextKey, ref firstException))
29-
|| (CheckEnvVar(ConfigurationKeys.GCPFunction.FunctionNameKey, ref firstException)
30-
&& CheckEnvVar(ConfigurationKeys.GCPFunction.FunctionTargetKey, ref firstException))
31-
|| (CheckEnvVar(ConfigurationKeys.GCPFunction.DeprecatedFunctionNameKey, ref firstException)
32-
&& CheckEnvVar(ConfigurationKeys.GCPFunction.DeprecatedProjectKey, ref firstException));
29+
|| (CheckEnvVar(PlatformKeys.GCPFunction.FunctionNameKey, ref firstException)
30+
&& CheckEnvVar(PlatformKeys.GCPFunction.FunctionTargetKey, ref firstException))
31+
|| (CheckEnvVar(PlatformKeys.GCPFunction.DeprecatedFunctionNameKey, ref firstException)
32+
&& CheckEnvVar(PlatformKeys.GCPFunction.DeprecatedProjectKey, ref firstException));
3333

3434
exceptionInReading = firstException;
3535
return isServerless;

0 commit comments

Comments
 (0)