Skip to content

Commit fdde571

Browse files
committed
More progress on the tests
1 parent 57a6a7f commit fdde571

3 files changed

Lines changed: 32 additions & 16 deletions

File tree

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLoggerProvider.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
using System;
88
using System.Collections.Concurrent;
9-
using System.Threading.Tasks;
109
using Datadog.Trace.DuckTyping;
1110
using Datadog.Trace.Logging.DirectSubmission;
1211
using Datadog.Trace.Logging.DirectSubmission.Formatting;
@@ -75,18 +74,6 @@ private DirectSubmissionLogger CreateLoggerImplementation(string name)
7574
[DuckReverseMethod]
7675
public void Dispose()
7776
{
78-
// Flush the shared log sink on a best-effort basis so pending batches drain when
79-
// the ILoggerFactory is disposed deterministically (host shutdown, test teardown)
80-
// rather than waiting for the process-exit hook. The sink is a global singleton
81-
// owned by TracerManager, so this does not dispose it.
82-
try
83-
{
84-
_sink.FlushAsync().Wait(TimeSpan.FromSeconds(10));
85-
}
86-
catch
87-
{
88-
// Never throw from Dispose. Final flush still runs via the process-exit hook.
89-
}
9077
}
9178

9279
/// <summary>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ public async Task SubmitsOtlpTraces(string packageVersion, string datadogTracesE
279279

280280
var applicationStartTimeUnixNano = DateTimeOffset.UtcNow.ToUnixTimeNanoseconds();
281281
using var agent = EnvironmentHelper.GetMockAgent();
282+
// When DD_AGENT_HOST=test-agent is set above, it also redirects the APM trace agent
283+
// URL via the DD_TRACE_AGENT_HOSTNAME alias (the primary key wins). That points APM
284+
// traces at test-agent:<mock-agent-port>, which does not exist, so AgentWriter
285+
// retries fill the tracer's shutdown window and can starve the DirectLogSubmission
286+
// final flush. Pin the APM URL back to the in-process MockAgent.
287+
if (useAgentHostBackup && agent is MockTracerAgent.TcpUdpAgent tcpAgent)
288+
{
289+
SetEnvironmentVariable("DD_TRACE_AGENT_URL", $"http://127.0.0.1:{tcpAgent.Port}");
290+
}
291+
282292
using (await RunSampleAndWaitForExit(agent, packageVersion: packageVersion ?? "1.13.1"))
283293
{
284294
using var httpClient = new System.Net.Http.HttpClient();
@@ -539,6 +549,13 @@ public async Task SubmitsOtlpMetrics(string packageVersion, string datadogMetric
539549
SetEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE", runtimeMajor >= 9 ? "delta" : "cumulative");
540550

541551
using var agent = EnvironmentHelper.GetMockAgent();
552+
// See comment in SubmitsOtlpTraces. DD_AGENT_HOST=test-agent also redirects the APM
553+
// trace agent URL; pin it back to the in-process MockAgent.
554+
if (useAgentHostBackup && agent is MockTracerAgent.TcpUdpAgent tcpAgent)
555+
{
556+
SetEnvironmentVariable("DD_TRACE_AGENT_URL", $"http://127.0.0.1:{tcpAgent.Port}");
557+
}
558+
542559
using (await RunSampleAndWaitForExit(agent, packageVersion: packageVersion ?? "1.13.1"))
543560
{
544561
var metricsData = await WaitForTestAgentData($"http://{testAgentHost}:4318/test/session/metrics");
@@ -626,6 +643,14 @@ public async Task SubmitsOtlpLogs(string packageVersion, string datadogLogsEnabl
626643
var startTimeNanoseconds = DateTimeOffset.UtcNow.ToUnixTimeNanoseconds();
627644

628645
using var agent = EnvironmentHelper.GetMockAgent();
646+
// See comment in SubmitsOtlpTraces. DD_AGENT_HOST=test-agent also redirects the APM
647+
// trace agent URL; pin it back to the in-process MockAgent so AgentWriter retries
648+
// don't starve the DirectLogSubmission final flush during shutdown.
649+
if (useAgentHostBackup && agent is MockTracerAgent.TcpUdpAgent tcpAgent)
650+
{
651+
SetEnvironmentVariable("DD_TRACE_AGENT_URL", $"http://127.0.0.1:{tcpAgent.Port}");
652+
}
653+
629654
using (await RunSampleAndWaitForExit(agent, packageVersion: packageVersion ?? "1.13.1"))
630655
{
631656
var endTimeNanoseconds = DateTimeOffset.UtcNow.ToUnixTimeNanoseconds();

tracer/test/test-applications/integrations/Samples.OpenTelemetrySdk/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public static async Task Main(string[] args)
4545
.Build();
4646

4747
#if OTEL_1_2
48-
using var meterProvider = Sdk.CreateMeterProviderBuilder()
48+
// Not `using var`: we call Shutdown explicitly below, and OTel SDK <= 1.3.2 re-collects
49+
// on a second Shutdown/Dispose which produces a duplicate cumulative batch the test
50+
// snapshot doesn't expect. Process exit handles cleanup.
51+
var meterProvider = Sdk.CreateMeterProviderBuilder()
4952
.AddOtlpExporterIfEnvironmentVariablePresent()
5053
.Build();
5154
#endif
@@ -149,8 +152,9 @@ public static async Task Main(string[] args)
149152
// when the first gRPC export has to negotiate TCP+HTTP/2+TLS. We avoid ForceFlush-then-
150153
// Dispose because two Collects on cumulative-temporality observable instruments re-emit
151154
// the same cumulative values and produce duplicate resource_metrics batches. Shutdown
152-
// performs exactly one Collect; the `using var` Dispose at end-of-scope no-ops via the
153-
// SDK's internal shutdown-count guard.
155+
// performs exactly one Collect; `meterProvider` is deliberately not `using var` so the
156+
// runtime doesn't re-invoke Dispose->Shutdown after this (older OTel SDKs like 1.3.2
157+
// re-collect in that second call).
154158
meterProvider?.Shutdown(timeoutMilliseconds: 30_000);
155159
#endif
156160
#if OTEL_1_9

0 commit comments

Comments
 (0)