Skip to content

Commit

Permalink
Ignore v1 telemetry sent by version conflict packages
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Oct 26, 2023
1 parent 2f17375 commit dee34cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tracer/test/Datadog.Trace.TestHelpers/MockTelemetryAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ internal static TelemetryWrapper DeserializeResponse(Stream inputStream, string
{
return apiVersion switch
{
"v1" => null, // In version conflict, we may still send v1 telemetry. Just ignore it
TelemetryConstants.ApiVersionV2 => DeserializeV2(inputStream, requestType),
_ => throw new Exception($"Unknown telemetry api version: {apiVersion}"),
_ => throw new Exception($"Unknown telemetry api version: {apiVersion}, {Deserialize(inputStream)}"),
};

static TelemetryWrapper DeserializeV2(Stream inputStream, string requestType)
Expand All @@ -152,6 +153,12 @@ static TelemetryWrapper DeserializeV2(Stream inputStream, string requestType)

return new TelemetryWrapper.V2(telemetry);
}

static string Deserialize(Stream inputStream)
{
using var sr = new StreamReader(inputStream);
return sr.ReadToEnd();
}
}

protected virtual void OnRequestReceived(HttpListenerContext context)
Expand All @@ -167,11 +174,14 @@ protected virtual void HandleHttpRequest(HttpListenerContext ctx)
var requestType = ctx.Request.Headers[TelemetryConstants.RequestTypeHeader];

var telemetry = DeserializeResponse(ctx.Request.InputStream, apiVersion, requestType);
Telemetry.Push(telemetry);

lock (this)
if (telemetry is not null)
{
RequestHeaders = RequestHeaders.Add(new NameValueCollection(ctx.Request.Headers));
Telemetry.Push(telemetry);

lock (this)
{
RequestHeaders = RequestHeaders.Add(new NameValueCollection(ctx.Request.Headers));
}
}

// NOTE: HttpStreamRequest doesn't support Transfer-Encoding: Chunked
Expand Down
5 changes: 5 additions & 0 deletions tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ private void HandlePotentialTelemetryData(MockHttpParser.MockHttpRequest request
using var stream = new MemoryStream(body);

var telemetry = MockTelemetryAgent.DeserializeResponse(stream, apiVersion, requestType);
if (telemetry is null)
{
return;
}

Telemetry.Push(telemetry);

lock (this)
Expand Down

0 comments on commit dee34cb

Please sign in to comment.