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

Fix error_status_codes options #3344

Merged
merged 3 commits into from
Jan 8, 2024
Merged

Conversation

TonyCTHsu
Copy link
Contributor

@TonyCTHsu TonyCTHsu commented Dec 20, 2023

2.0 Upgrade Guide notes

What does this PR do?

Fix and standardize the way to configure an array of ranges for error_status_codes from environment variables.

@TonyCTHsu TonyCTHsu changed the base branch from master to 2.0 December 20, 2023 19:43
@github-actions github-actions bot added integrations Involves tracing integrations tracing labels Dec 20, 2023
@ranges.any? do |e|
case e
when Range
e.include? status
Copy link
Member

Choose a reason for hiding this comment

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

How about using === for both integer and range? I think it works for both.

Copy link
Contributor

Choose a reason for hiding this comment

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

Compared to current code I feel like it kind of obscures the reading though: personally I prefer reading the current version which is immediately obvious, whereas I had to check that 2 === 2 and (2..4) === 2 both worked.

values.compact!
values
o.setter do |v|
Tracing::Contrib::StatusRangeMatcher.new(v) if v
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a runtime type check here, to enforce that either one of these is true:

  • v is an Integer
  • v is a Range with .first (and last, but that's internally checked by Range) being Integer

Comment on lines +21 to +23
Datadog.logger.debug(
"Invalid error_status_codes configuration: Unable to parse #{value}, containing #{v}."
)
Copy link
Contributor

@lloeki lloeki Dec 27, 2023

Choose a reason for hiding this comment

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

Somehow I feel like this logging should happen in o.env_parser. That, or this class should at least be in Datadog::Tracing::Contrib::Configuration::Settings::StatusRangeEnvParser.

Also, I think we might be inconsistent and in some places env parse fails / conf type checks raise and in others they log but IIRC we mostly raise? I might be wrong on that one but I'd rather be consistent.

If we chose to always log, I feel like we should raise EnvValueError / ParseError / TypeError / whatever exceptions in such pieces of code, and then the caller (the config system) of o.env_parser / o.setter / ... should handle that kind of exception uniformly and log.

@TonyCTHsu TonyCTHsu marked this pull request as ready for review January 4, 2024 15:49
@TonyCTHsu TonyCTHsu requested a review from a team as a code owner January 4, 2024 15:49
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/fix-error-status-codes branch from 3326f26 to 4c68809 Compare January 8, 2024 15:23
@TonyCTHsu TonyCTHsu requested a review from a team as a code owner January 8, 2024 15:23
@TonyCTHsu
Copy link
Contributor Author

Going to refactor later

@TonyCTHsu TonyCTHsu merged commit 6ea3035 into 2.0 Jan 8, 2024
121 of 129 checks passed
@TonyCTHsu TonyCTHsu deleted the tonycthsu/fix-error-status-codes branch January 8, 2024 15:29
@TonyCTHsu TonyCTHsu added this to the 2.0 milestone Feb 20, 2024
@ivoanjo ivoanjo added the 2.0 label Mar 14, 2024
@TonyCTHsu TonyCTHsu modified the milestones: 2.0, 2.0.0.beta1 Mar 22, 2024
@TonyCTHsu TonyCTHsu mentioned this pull request Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants