Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f311ff2
feat: cross-process test log correlation via OTLP receiver (#4818)
thomhurst Apr 13, 2026
a32e2ad
fix: address code review findings on OTLP correlation PR
thomhurst Apr 13, 2026
13ee150
refactor: simplify after code review
thomhurst Apr 13, 2026
e3109a9
fix: gate CreateHttpClient override on EnableTelemetryCollection
thomhurst Apr 13, 2026
c3f804a
fix: address third-round review findings
thomhurst Apr 13, 2026
1f9ee36
docs: add telemetry correlation docs, enable by default
thomhurst Apr 13, 2026
8959f79
docs: note field ordering assumption in ParseResourceLogs
thomhurst Apr 13, 2026
b373da4
test: add thorough tests for OTLP log-to-test correlation
thomhurst Apr 13, 2026
ab164b9
fix: update public API snapshots for new InternalsVisibleTo entry
thomhurst Apr 14, 2026
4a9231d
feat: add OTLP integration tests and auto-inject telemetry env vars
thomhurst Apr 14, 2026
3aed4c2
refactor: simplify integration tests per code review
thomhurst Apr 14, 2026
dc20e0c
docs: address review feedback on shared handler and TraceId scope
thomhurst Apr 14, 2026
28d44bb
fix: generate unique TraceId per HTTP request for reliable correlation
thomhurst Apr 14, 2026
c40e230
feat: give each test its own TraceId via root activity with class link
thomhurst Apr 14, 2026
4359189
test: add engine activity tests, fix test body parent chain
thomhurst Apr 14, 2026
0587668
fix: restore parent-child activity hierarchy, move correlation to han…
thomhurst Apr 14, 2026
3e6575c
refactor: replace raw tag key strings with TUnitActivitySource constants
thomhurst Apr 14, 2026
3221c82
fix: replace fixed Task.Delay with polling in OtlpReceiverTests
thomhurst Apr 14, 2026
3ddbf74
fix: address review round 4 findings
thomhurst Apr 14, 2026
477a319
fix: remove mutually exclusive RunOnLinuxOnly/RunOnWindowsOnly attrs
thomhurst Apr 14, 2026
870a6c5
fix: add missing HangDump package to Aspire and ASP.NET test projects
thomhurst Apr 14, 2026
e911de2
fix: skip Aspire, ASP.NET, and RPC test modules on macOS
thomhurst Apr 14, 2026
3dd2b20
fix: enable Docker setup on macOS CI runners
thomhurst Apr 14, 2026
0874d0e
fix: skip Docker-dependent test modules on macOS
thomhurst Apr 14, 2026
87cfffa
fix: skip RPC tests globally until fixed (#5540)
thomhurst Apr 14, 2026
98fc40f
fix: restrict Docker-dependent CI modules to Linux, add missing ApiSe…
thomhurst Apr 14, 2026
08b62fb
fix: fix PublicAPI snapshot ordering and flaky severity test
thomhurst Apr 14, 2026
8c5e115
fix: move mock tests AOT publish into pipeline module
thomhurst Apr 14, 2026
068cdb0
Refactor code structure for improved readability and maintainability
thomhurst Apr 14, 2026
8034a5b
fix: share IntegrationTestFixture in WaitForHealthy tests
thomhurst Apr 14, 2026
f55d181
fix: restart Docker after setup to initialize iptables chains
thomhurst Apr 14, 2026
97178be
fix: remove docker/setup-docker-action
thomhurst Apr 14, 2026
4c3b872
fix: correct ASP.NET execution order assertions
thomhurst Apr 14, 2026
9145da5
fix: use CreateTablesAsync to avoid EnsureCreatedAsync race in parall…
thomhurst Apr 14, 2026
cad9f86
fix: use absolute path for AOT mock test publish output
thomhurst Apr 14, 2026
db8c9f9
merge: resolve conflict with main (NuGet.Protocol 7.3.1)
thomhurst Apr 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: address third-round review findings
- OtlpReceiver: enforce body size limit during read (handles chunked
  transfer where ContentLength64 is -1); pass CancellationToken to
  stream reads; fix class doc to clarify /v1/traces is forwarded only
- ProtobufReader: add varint overflow guard (shift >= 64); add bounds
  checks for Fixed64/Fixed32 in Skip; reuse ReadLengthDelimited in
  Skip for LengthDelimited case; remove dead ReadBytes method
- OtlpLogParser: remove unused System.Buffers.Binary import
- TUnitBaggagePropagationHandler: guard against duplicate baggage header
  when OTel SDK's BaggagePropagator has already injected one
  • Loading branch information
thomhurst committed Apr 13, 2026
commit c3f804ab2cde67f5616e5b371faf2cc122dfc1d9
41 changes: 23 additions & 18 deletions TUnit.Aspire/Http/TUnitBaggagePropagationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,36 @@ protected override Task<HttpResponseMessage> SendAsync(
}
});

// Inject baggage header (not handled by the default propagator)
var first = true;
var sb = new System.Text.StringBuilder();

foreach (var (key, value) in activity.Baggage)
// Inject baggage header if the propagator hasn't already done so.
// When OTel SDK is configured with BaggagePropagator, the Inject call
// above may have already added a baggage header — avoid duplicates.
if (!request.Headers.Contains("baggage"))
{
if (key is null)
var first = true;
var sb = new System.Text.StringBuilder();

foreach (var (key, value) in activity.Baggage)
{
continue;
if (key is null)
{
continue;
}

if (!first)
{
sb.Append(',');
}

sb.Append(Uri.EscapeDataString(key));
sb.Append('=');
sb.Append(Uri.EscapeDataString(value ?? string.Empty));
first = false;
}

if (!first)
{
sb.Append(',');
request.Headers.TryAddWithoutValidation("baggage", sb.ToString());
}

sb.Append(Uri.EscapeDataString(key));
sb.Append('=');
sb.Append(Uri.EscapeDataString(value ?? string.Empty));
first = false;
}

if (!first)
{
request.Headers.TryAddWithoutValidation("baggage", sb.ToString());
}
}

Expand Down
26 changes: 18 additions & 8 deletions TUnit.Aspire/Telemetry/OtlpLogParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Buffers.Binary;
using System.Text;

namespace TUnit.Aspire.Telemetry;
Expand Down Expand Up @@ -270,6 +269,11 @@ public ulong ReadVarint()

while (!_data.IsEmpty)
{
if (shift >= 64)
{
throw new InvalidOperationException("Malformed varint: exceeds 64 bits.");
}

var b = _data[0];
_data = _data[1..];
result |= (ulong)(b & 0x7F) << shift;
Expand All @@ -290,11 +294,6 @@ public ReadOnlySpan<byte> ReadBytesAsSpan()
return ReadLengthDelimited();
}

public byte[] ReadBytes()
{
return ReadLengthDelimited().ToArray();
}

public string ReadString()
{
return Encoding.UTF8.GetString(ReadLengthDelimited());
Expand Down Expand Up @@ -328,13 +327,24 @@ public void Skip(WireType wireType)
ReadVarint();
break;
case WireType.Fixed64:
if (_data.Length < 8)
{
throw new InvalidOperationException(
$"Truncated fixed64 field: need 8 bytes but only {_data.Length} remain.");
}

_data = _data[8..];
break;
case WireType.LengthDelimited:
var length = (int)ReadVarint();
_data = _data[length..];
ReadLengthDelimited();
break;
case WireType.Fixed32:
if (_data.Length < 4)
{
throw new InvalidOperationException(
$"Truncated fixed32 field: need 4 bytes but only {_data.Length} remain.");
}

_data = _data[4..];
break;
default:
Expand Down
26 changes: 21 additions & 5 deletions TUnit.Aspire/Telemetry/OtlpReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ namespace TUnit.Aspire.Telemetry;
/// <remarks>
/// <para>
/// The receiver listens on a dynamic localhost port and accepts OTLP/HTTP protobuf
/// exports at <c>/v1/logs</c> and <c>/v1/traces</c>. It extracts TraceId from
/// incoming log records and looks up the corresponding test in
/// <see cref="TraceRegistry"/> to route logs to the correct test output.
/// exports at <c>/v1/logs</c> (parsed for correlation) and <c>/v1/traces</c>
/// (accepted but only forwarded, not parsed). It extracts TraceId from incoming
/// log records and looks up the corresponding test in <see cref="TraceRegistry"/>
/// to route logs to the correct test output.
/// </para>
/// <para>
/// Optionally forwards received telemetry to an upstream OTLP endpoint (e.g., the
Expand Down Expand Up @@ -124,11 +125,26 @@ private async Task ProcessRequestAsync(HttpListenerContext context)
return;
}

// Read the request body
// Read the request body with size enforcement (ContentLength64 is -1 for chunked)
byte[] body;
using (var ms = new MemoryStream())
{
await request.InputStream.CopyToAsync(ms).ConfigureAwait(false);
var buffer = new byte[8192];
long totalRead = 0;
int bytesRead;
while ((bytesRead = await request.InputStream.ReadAsync(buffer, _cts.Token).ConfigureAwait(false)) > 0)
{
totalRead += bytesRead;
if (totalRead > MaxBodyBytes)
{
response.StatusCode = 413;
response.Close();
return;
}

ms.Write(buffer, 0, bytesRead);
}

body = ms.ToArray();
}

Expand Down
Loading