Skip to content

Add round tripper option to have custom status check#3422

Closed
barp wants to merge 1 commit into
DataDog:release-v1.72.xfrom
barp:patch-1
Closed

Add round tripper option to have custom status check#3422
barp wants to merge 1 commit into
DataDog:release-v1.72.xfrom
barp:patch-1

Conversation

@barp

@barp barp commented Apr 14, 2025

Copy link
Copy Markdown

What does this PR do?

Allow a user of http client to specify what http status codes should be considered errors on a specific http client.

Motivation

I have an http client where I want to have a specific handling for all http status codes and they are never considered an error in my client.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running golangci-lint run locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@barp
barp requested review from a team as code owners April 14, 2025 04:14
@mtoffl01

Copy link
Copy Markdown
Contributor

Hi there,

Thanks for reaching out!

We support configurable error codes for the http client globally via an env var: DD_TRACE_HTTP_CLIENT_ERROR_STATUSES, where specified values are considered errors, and any unspecified values are considered OK. Individual and range values are supported, e.g: DD_TRACE_HTTP_CLIENT_ERROR_STATUSES=400,402,404-410.

Can you use this option, or do you specifically need a way to configure error codes per client?

Thanks!

@mtoffl01 mtoffl01 self-assigned this Apr 15, 2025
@barp

barp commented Apr 15, 2025 via email

Copy link
Copy Markdown
Author

@mtoffl01

Copy link
Copy Markdown
Contributor

Hi @barp ,

In v1, we already provide this functionality via the the RTWithErrorCheck option.

Is there a specific reason this doesn’t address your use case? I’m trying to determine whether there’s a gap in the existing support or if this option might have just been overlooked.

@barp

barp commented Apr 16, 2025

Copy link
Copy Markdown
Author

Error check (of return value) and status checks are 2 seperate things, since error status is not considered an error the code will go to the status check in which it will always mark it as an error if it's anything between 400-500.

In shortRTWithErrorCheck doesn't work in this case as can be seen in

span.SetTag(ext.HTTPCode, strconv.Itoa(res.StatusCode))
.

as can be seen that the default status check for clients is

func isClientError(statusCode int) bool {

@mtoffl01

Copy link
Copy Markdown
Contributor

Hi @barp ,

Thanks for the clarification, though I’m still not entirely sure I understand the issue. Are you looking to treat certain HTTP status codes (e.g., some 4xx responses) not as errors? If so, you can just exclude those codes from your error check logic.

Or, maybe you'd like the status evaluation to rely on different criteria entirely—perhaps looking at another part of the response rather than just the HTTP status?

I appreciate your patience as we sort this out. Thanks!

@barp

barp commented Apr 18, 2025

Copy link
Copy Markdown
Author

I'm looking to not treat all http status codes and all possible errors from a client as not errors (as in I don't want an error reported to data dog error tracking) for every single issue with a specific client I know will have errors.
I have my own custom error handling on the returned error from the client and in the current state datadog will get an error report regardless of what I do and I cannot change that no matter what I do.

this is because datadog does the error checks in the instrumentated code which I don't have control over and reports those errors no matter if I actually handle those errors. At the current state datadog will report an error even if the code that called the http.Get (for example) function handles the errors correctly.

My personal opinion is that error reporting should only happen if the calling user code (not the library code) didn't handle the error. But at the current state getting an error in Error Tracking is unavoidable in go.

@barp

barp commented Apr 25, 2025

Copy link
Copy Markdown
Author

I don't want to spam you guys too much, is there an update on this?
Was there any issue with my previous message?

@darccio

darccio commented Apr 29, 2025

Copy link
Copy Markdown
Member

@barp It's ok. We've decided to accept this PR in our in-progress v1.73.0 release. Please, consider rebasing this PR against the branch release-v1.73.x after adding at least a test for showing that your change is working.

@darccio

darccio commented May 2, 2025

Copy link
Copy Markdown
Member

@barp As we want to include this to the last v1 release, v1.73.0, and we need to dogfood it ASAP, we've created a PR based in yours against the right release branch and adding test coverage. I'm closing your PR in favour of ours #3479.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants