Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dynamic Instrumentation] Support legacy endpoint for diagnostics uploading #5456

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
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
33 changes: 21 additions & 12 deletions tracer/src/Datadog.Trace/Debugger/Upload/DiagnosticsUploadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,13 @@ public static DiagnosticsUploadApi Create(
public override async Task<bool> SendBatchAsync(ArraySegment<byte> data)
{
var uri = BuildUri();
if (string.IsNullOrEmpty(uri))
if (uri == null)
{
Log.Warning("Failed to upload diagnostics: debugger endpoint not yet retrieved from discovery service");
return false;
}

var request = _apiRequestFactory.Create(new Uri(uri));
var multipartRequest = (IMultipartApiRequest)request;

using var response =
await multipartRequest
.PostAsync(new MultipartFormItem[]
{
new("event", MimeTypes.Json, "event.json", data)
})
.ConfigureAwait(false);

using var response = await PostAsync(uri, data).ConfigureAwait(false);
if (response.StatusCode is >= 200 and <= 299)
{
return true;
Expand All @@ -67,5 +57,24 @@ await multipartRequest
Log.Warning<int, string>("Failed to upload diagnostics with status code {StatusCode} and message: {ResponseContent}", response.StatusCode, content);
return false;
}

private Task<IApiResponse> PostAsync(string uri, ArraySegment<byte> data)
{
if (uri.Contains("diagnostics"))
Copy link
Member

@andrewlock andrewlock Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit broad, are you sure you don't want to test for a specific path here 🤔 Given this is the "legacy" behaviour (I believe?) it might be a better option, as we don't expect it to change, and if the new url does change, we don't want to unexpectedly revert to the old behaviour?

(If so, obviously don't have to do in this PR, for speed purposes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thinks it's a good idea, I will add a work item for this.

{
var multipart = _apiRequestFactory.Create(new Uri(uri));
var multipartRequest = (IMultipartApiRequest)multipart;

return
multipartRequest
.PostAsync(new MultipartFormItem[]
{
new("event", MimeTypes.Json, "event.json", data)
});
}

var request = _apiRequestFactory.Create(new Uri(uri));
return request.PostAsync(data, MimeTypes.Json);
}
}
}
Loading