Skip to content

Commit edb4121

Browse files
Lewis-Eclaude
andcommitted
Fix typos, apply code standards, and deduplicate tests
- Fix "Compatability" → "Compatibility" typo (3 occurrences) - Use `is null` / `is not null` instead of `== null` / `!= null` - Use `StringUtil.IsNullOrEmpty()` instead of `string.IsNullOrEmpty()` - Remove duplicate test file in Datadog.Trace.Tests - Remove tests already covered by ServerlessCompatPipeNameHelperTests - Fix SA1508 blank line before closing brace in PlatformKeys Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0a437e5 commit edb4121

5 files changed

Lines changed: 14 additions & 165 deletions

File tree

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Serverless/CompatibilityLayer_CalculateDogStatsDPipeName_Integration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal static CallTargetReturn<string> OnMethodEnd<TTarget>(
5555
Exception exception,
5656
in CallTargetState state)
5757
{
58-
if (exception != null)
58+
if (exception is not null)
5959
{
6060
// If there was an exception, pass it through
6161
return new CallTargetReturn<string>(returnValue);
@@ -65,11 +65,11 @@ internal static CallTargetReturn<string> OnMethodEnd<TTarget>(
6565
{
6666
// Get the tracer's pipe name (generated in ExporterSettings if on Windows with no explicit config)
6767
// Use lazy caching to avoid repeated lookups
68-
if (_cachedDogStatsDPipeName == null)
68+
if (_cachedDogStatsDPipeName is null)
6969
{
7070
lock (_lock)
7171
{
72-
if (_cachedDogStatsDPipeName == null)
72+
if (_cachedDogStatsDPipeName is null)
7373
{
7474
// Use the pipe name pre-generated by ExporterSettings if available (Azure Functions scenario)
7575
// If no pre-generated name exists (e.g. explicit config or compat check failed),

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Serverless/CompatibilityLayer_CalculateTracePipeName_Integration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal static CallTargetReturn<string> OnMethodEnd<TTarget>(
5555
Exception exception,
5656
in CallTargetState state)
5757
{
58-
if (exception != null)
58+
if (exception is not null)
5959
{
6060
// If there was an exception, pass it through
6161
return new CallTargetReturn<string>(returnValue);
@@ -65,11 +65,11 @@ internal static CallTargetReturn<string> OnMethodEnd<TTarget>(
6565
{
6666
// Get the tracer's pipe name (generated in ExporterSettings if on Windows with no explicit config)
6767
// Use lazy caching to avoid repeated lookups
68-
if (_cachedTracePipeName == null)
68+
if (_cachedTracePipeName is null)
6969
{
7070
lock (_lock)
7171
{
72-
if (_cachedTracePipeName == null)
72+
if (_cachedTracePipeName is null)
7373
{
7474
// Use the pipe name pre-generated by ExporterSettings if available (Azure Functions scenario)
7575
// If no pre-generated name exists (e.g. explicit config or compat check failed),

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ internal ExporterSettings(Raw rawSettings, Func<string, bool> fileExists, IConfi
110110

111111
// Use statically-generated pipe names for Azure Functions if no explicit config was provided.
112112
// The static fields are initialized once at type-load time via InitAzureFunctions*PipeName().
113-
var tracesPipeName = !string.IsNullOrEmpty(rawSettings.TracesPipeName) ? rawSettings.TracesPipeName : _azureFunctionsGeneratedTracesPipeName;
114-
var metricsPipeName = !string.IsNullOrEmpty(rawSettings.MetricsPipeName) ? rawSettings.MetricsPipeName : _azureFunctionsGeneratedMetricsPipeName;
113+
var tracesPipeName = !StringUtil.IsNullOrEmpty(rawSettings.TracesPipeName) ? rawSettings.TracesPipeName : _azureFunctionsGeneratedTracesPipeName;
114+
var metricsPipeName = !StringUtil.IsNullOrEmpty(rawSettings.MetricsPipeName) ? rawSettings.MetricsPipeName : _azureFunctionsGeneratedMetricsPipeName;
115115

116116
var traceSettings = GetTraceTransport(
117117
agentUri: rawSettings.TraceAgentUri,
@@ -261,7 +261,7 @@ private static string GetMetricsHostNameFromAgentUri(Uri agentUri)
261261
{
262262
if (Util.EnvironmentHelpers.IsAzureFunctions()
263263
&& !Util.EnvironmentHelpers.IsUsingAzureAppServicesSiteExtension()
264-
&& string.IsNullOrEmpty(Util.EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.TracesPipeName))
264+
&& StringUtil.IsNullOrEmpty(Util.EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.TracesPipeName))
265265
&& IsCompatLayerAvailableWithPipeSupport())
266266
{
267267
var name = GenerateUniquePipeName("dd_trace");
@@ -276,7 +276,7 @@ private static string GetMetricsHostNameFromAgentUri(Uri agentUri)
276276
{
277277
if (Util.EnvironmentHelpers.IsAzureFunctions()
278278
&& !Util.EnvironmentHelpers.IsUsingAzureAppServicesSiteExtension()
279-
&& string.IsNullOrEmpty(Util.EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.MetricsPipeName))
279+
&& StringUtil.IsNullOrEmpty(Util.EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.MetricsPipeName))
280280
&& IsCompatLayerAvailableWithPipeSupport())
281281
{
282282
var name = GenerateUniquePipeName("dd_dogstatsd");
@@ -312,16 +312,16 @@ private static bool IsCompatLayerAvailableWithPipeSupport()
312312
var compatDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory ?? string.Empty, "Datadog.Serverless.Compat.dll");
313313
if (!File.Exists(compatBinaryPath) || !File.Exists(compatDllPath))
314314
{
315-
Log.Debug("Did not find Serverless Compatability Layer or related DLLs.");
315+
Log.Debug("Did not find Serverless Compatibility Layer or related DLLs.");
316316
return false;
317317
}
318318

319319
var assemblyName = AssemblyName.GetAssemblyName(compatDllPath);
320320
var version = assemblyName.Version;
321321

322-
if (version == null)
322+
if (version is null)
323323
{
324-
Log.Warning("Could not read Serverless Compatability Layer details at {Path}, using fallback agent communication methods. (No Named Pipes)", compatDllPath);
324+
Log.Warning("Could not read Serverless Compatibility Layer details at {Path}, using fallback agent communication methods. (No Named Pipes)", compatDllPath);
325325
return false;
326326
}
327327

@@ -340,7 +340,7 @@ private static bool IsCompatLayerAvailableWithPipeSupport()
340340
}
341341
catch (Exception ex)
342342
{
343-
Log.Warning(ex, "Failed to determine Serverless Compatability layer availability or Named Pipe Support.");
343+
Log.Warning(ex, "Failed to determine Serverless Compatibility layer availability or Named Pipe Support.");
344344
return false;
345345
}
346346
}

tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Serverless/ServerlessCompatIntegrationTests.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,35 +168,6 @@ public void OnMethodEnd_WithException_PassesThroughOriginalValue(string pipeType
168168
result.GetReturnValue().Should().Be(originalValue);
169169
}
170170

171-
[Theory]
172-
[InlineData("dd_trace", "trace")]
173-
[InlineData("dd_dogstatsd", "DogStatsD")]
174-
public void GeneratedPipeName_HasCorrectFormat(string baseName, string pipeType)
175-
{
176-
// Act
177-
var pipeName = ServerlessCompatPipeNameHelper.GenerateUniquePipeName(baseName, pipeType);
178-
179-
// Assert
180-
pipeName.Should().StartWith($"{baseName}_");
181-
pipeName.Should().MatchRegex($@"^{baseName}_[a-f0-9]{{32}}$"); // base_guid with 32 hex chars
182-
pipeName.Length.Should().BeLessOrEqualTo(247); // 214 base + 1 underscore + 32 guid = 247 max
183-
}
184-
185-
[Fact]
186-
public void GeneratedPipeName_WithLongBaseName_Truncates()
187-
{
188-
// Arrange - create a base name longer than 214 characters
189-
var longBaseName = new string('a', 220);
190-
191-
// Act
192-
var pipeName = ServerlessCompatPipeNameHelper.GenerateUniquePipeName(longBaseName, "test");
193-
194-
// Assert
195-
// Should be truncated to 214 + 1 underscore + 32 guid = 247 total
196-
pipeName.Length.Should().Be(247);
197-
pipeName.Should().MatchRegex(@"^a{214}_[a-f0-9]{32}$");
198-
}
199-
200171
// Clear cached values between tests using reflection.
201172
// The integration classes cache their resolved pipe name in a static field;
202173
// resetting these allows each test to start fresh.

tracer/test/Datadog.Trace.Tests/ClrProfiler/AutoInstrumentation/Serverless/ServerlessCompatIntegrationTests.cs

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)