Skip to content

Commit e35949b

Browse files
committed
Add tests for disabling host logging
1 parent cb0122e commit e35949b

File tree

10 files changed

+712
-33
lines changed

10 files changed

+712
-33
lines changed

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AzureFunctionsTests.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ public IsolatedRuntimeV4(ITestOutputHelper output)
278278
[Trait("RunOnWindows", "True")]
279279
public async Task SubmitsTraces()
280280
{
281+
// by default host logs are enabled e.g.,
282+
// DD_LOGS_DIRECT_SUBMISSION_AZURE_FUNCTIONS_HOST_ENABLED=true
283+
// but we do just want a lot of logging, so still bump up the level to VERBOSE
284+
SetEnvironmentVariable("DD_LOGS_DIRECT_SUBMISSION_MINIMUM_LEVEL", "VERBOSE");
285+
var hostName = "integration_ilogger_az_tests";
286+
using var logsIntake = new MockLogsIntake();
287+
EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.ILogger), hostName);
281288
using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
282289
using (await RunAzureFunctionAndWaitForExit(agent, expectedExitCode: -1))
283290
{
@@ -286,10 +293,61 @@ public async Task SubmitsTraces()
286293
var filteredSpans = spans.Where(s => !s.Resource.Equals("Timer ExitApp", StringComparison.OrdinalIgnoreCase)).ToImmutableList();
287294

288295
using var s = new AssertionScope();
289-
290296
await AssertIsolatedSpans(filteredSpans);
291297

292298
filteredSpans.Count.Should().Be(expectedSpanCount);
299+
300+
var logs = logsIntake.Logs;
301+
302+
// ~327 (ish) logs but we kill func.exe so some logs are lost
303+
// and since sometimes the batch of logs can be 100+ it can be a LOT of logs that we lose
304+
// so just check that we have more than the 13 that we get when host logs are disabled
305+
logs.Should().HaveCountGreaterThanOrEqualTo(200);
306+
}
307+
}
308+
}
309+
310+
// The reason why we have a separate application here is because we run into a Singleton locking issue when
311+
// we re-run the same function application in the same test session.
312+
// I couldn't find a way to reset the state between test runs, so the easiest solution was to
313+
// just create a separate function app.
314+
[UsesVerify]
315+
[Collection(nameof(AzureFunctionsTestsCollection))]
316+
public class IsolatedRuntimeV4HostLogsDisabled : AzureFunctionsTests
317+
{
318+
public IsolatedRuntimeV4HostLogsDisabled(ITestOutputHelper output)
319+
: base("AzureFunctions.V4Isolated.HostLogsDisabled", output)
320+
{
321+
SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated");
322+
SetEnvironmentVariable("FUNCTIONS_EXTENSION_VERSION", "~4");
323+
}
324+
325+
[SkippableFact]
326+
[Trait("Category", "EndToEnd")]
327+
[Trait("Category", "AzureFunctions")]
328+
[Trait("RunOnWindows", "True")]
329+
public async Task SubmitsTraces()
330+
{
331+
SetEnvironmentVariable("DD_LOGS_DIRECT_SUBMISSION_AZURE_FUNCTIONS_HOST_ENABLED", "false");
332+
SetEnvironmentVariable("DD_LOGS_DIRECT_SUBMISSION_MINIMUM_LEVEL", "VERBOSE");
333+
var hostName = "integration_ilogger_az_tests";
334+
using var logsIntake = new MockLogsIntake();
335+
EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.ILogger), hostName);
336+
337+
using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
338+
using (await RunAzureFunctionAndWaitForExit(agent, expectedExitCode: -1))
339+
{
340+
const int expectedSpanCount = 21;
341+
var spans = await agent.WaitForSpansAsync(expectedSpanCount);
342+
343+
var filteredSpans = spans.Where(s => !s.Resource.Equals("Timer ExitApp", StringComparison.OrdinalIgnoreCase)).ToImmutableList();
344+
345+
await AssertIsolatedSpans(filteredSpans, filename: $"{nameof(AzureFunctionsTests)}.Isolated.V4.HostLogsDisabled");
346+
filteredSpans.Count.Should().Be(expectedSpanCount);
347+
348+
var logs = logsIntake.Logs;
349+
// we expect some logs still from the worker process
350+
logs.Should().HaveCount(13);
293351
}
294352
}
295353
}
@@ -325,6 +383,8 @@ public async Task SubmitsTraces()
325383
// value so they may be removed from being traced.
326384
var filteredSpans = FilterOutSocketsHttpHandler(spans);
327385

386+
filteredSpans = filteredSpans.Where(s => !s.Resource.Equals("Timer ExitApp", StringComparison.OrdinalIgnoreCase)).ToImmutableList();
387+
328388
using var s = new AssertionScope();
329389

330390
await AssertIsolatedSpans(filteredSpans.ToImmutableList(), $"{nameof(AzureFunctionsTests)}.Isolated.V4.AspNetCore");

tracer/test/snapshots/AzureFunctionsTests.Isolated.V4.AspNetCore.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.Exception
318318
---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
319319
Exception: Task failed successfully.
320-
Stack: at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req, ILogger log)
320+
Stack: at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req)
321321
at Samples.AzureFunctions.V4Isolated.AspNetCore.DirectFunctionExecutor.ExecuteAsync(FunctionContext context),
322322
error.type: Microsoft.Azure.WebJobs.Host.FunctionInvocationException,
323323
http.method: GET,
@@ -470,7 +470,7 @@ at Samples.AzureFunctions.V4Isolated.AspNetCore.DirectFunctionExecutor.ExecuteAs
470470
error.msg: Task failed successfully.,
471471
error.stack:
472472
System.InvalidOperationException: Task failed successfully.
473-
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req, ILogger log),
473+
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req),
474474
error.type: System.InvalidOperationException,
475475
language: dotnet,
476476
runtime-id: Guid_1,

tracer/test/snapshots/AzureFunctionsTests.Isolated.V4.AspNetCore1.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.Exception
318318
---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
319319
Exception: System.InvalidOperationException: Task failed successfully.
320-
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req, ILogger log),
320+
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req),
321321
error.type: Microsoft.Azure.WebJobs.Host.FunctionInvocationException,
322322
http.method: GET,
323323
http.request.headers.host: localhost:00000,
@@ -469,7 +469,7 @@ at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req,
469469
error.msg: Task failed successfully.,
470470
error.stack:
471471
System.InvalidOperationException: Task failed successfully.
472-
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req, ILogger log),
472+
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req),
473473
error.type: System.InvalidOperationException,
474474
language: dotnet,
475475
runtime-id: Guid_1,

0 commit comments

Comments
 (0)