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

Skip serialization of field Span.error if equals to 0 #500

Merged
merged 4 commits into from
Jun 24, 2024

Conversation

iamluc
Copy link
Contributor

@iamluc iamluc commented Jun 24, 2024

What does this PR do?

It skips the serialization of the field Span.error if the value is 0 as it's done by tracers (at least .net and PHP)

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

How to test the change?

Describe here in detail how the change can be validated.

Copy link
Contributor

@pierotibou pierotibou left a comment

Choose a reason for hiding this comment

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

Thank you!
Can we easily add a utest?

@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@88cb232). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #500   +/-   ##
=======================================
  Coverage        ?   69.39%           
=======================================
  Files           ?      201           
  Lines           ?    26745           
  Branches        ?        0           
=======================================
  Hits            ?    18560           
  Misses          ?     8185           
  Partials        ?        0           
Components Coverage Δ
crashtracker 16.70% <ø> (?)
datadog-alloc 98.76% <ø> (?)
data-pipeline 51.30% <ø> (?)
data-pipeline-ffi 0.00% <ø> (?)
ddcommon 85.97% <ø> (?)
ddcommon-ffi 74.15% <ø> (?)
ddtelemetry 56.37% <ø> (?)
ipc 84.66% <ø> (?)
profiling 78.63% <ø> (?)
profiling-ffi 58.19% <ø> (?)
serverless 0.00% <ø> (?)
sidecar 36.26% <ø> (?)
sidecar-ffi 0.00% <ø> (?)
spawn-worker 54.98% <ø> (?)
trace-mini-agent 69.36% <ø> (?)
trace-normalization 97.79% <ø> (?)
trace-obfuscation 95.75% <ø> (?)
trace-protobuf 48.71% <100.00%> (?)
trace-utils 90.79% <ø> (?)

@iamluc iamluc force-pushed the luc/skip-span-error-serialization-if-default branch from 0a23b17 to 75db04e Compare June 24, 2024 09:08
@iamluc iamluc changed the base branch from julio/sidecar-switch-to-v04 to main June 24, 2024 09:08
@iamluc
Copy link
Contributor Author

iamluc commented Jun 24, 2024

Can we easily add a utest?

Done!

@iamluc iamluc force-pushed the luc/skip-span-error-serialization-if-default branch from 75db04e to 2fd168a Compare June 24, 2024 09:25
trace-protobuf/Cargo.toml Show resolved Hide resolved
@@ -63,6 +63,10 @@ fn generate_protobuf() {
".pb.Span.spanLinks",
"#[serde(skip_serializing_if = \"::prost::alloc::vec::Vec::is_empty\")]",
);
config.field_attribute(
".pb.Span.error",
"#[serde(skip_serializing_if = \"is_default\")]",
Copy link
Contributor

@bwoebi bwoebi Jun 24, 2024

Choose a reason for hiding this comment

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

You can use ::std::i32::is_zero instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It fails with

error[E0425]: cannot find function `is_zero` in module `std::i32`
   --> libdatadog/trace-protobuf/src/pb.rs:115:35
    |
115 |     #[serde(skip_serializing_if = "::std::i32::is_zero")]
    |      

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. Well, try i32::is_zero without the std stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same.

At first try, I used is_negative (https://moshg.github.io/rust-std-ja/std/primitive.i32.html#method.is_negative), but it gave me an other error:

error[E0308]: mismatched types
   --> trace-protobuf/src/pb.rs:57:23
    |
57  | #[derive(Deserialize, Serialize)]
    |                       ^^^^^^^^^ expected `i32`, found `&i32`
...
114 |     #[serde(skip_serializing_if = "i32::is_negative")]
    |                                   ------------------ arguments to this function are incorrect

@iamluc iamluc force-pushed the luc/skip-span-error-serialization-if-default branch from 2fd168a to 934db37 Compare June 24, 2024 10:09
@iamluc iamluc force-pushed the luc/skip-span-error-serialization-if-default branch from dd150af to aa7241c Compare June 24, 2024 10:18
@iamluc iamluc force-pushed the luc/skip-span-error-serialization-if-default branch from 021a3bc to 2f33ff5 Compare June 24, 2024 10:31
@iamluc iamluc marked this pull request as ready for review June 24, 2024 11:26
@iamluc iamluc requested review from a team as code owners June 24, 2024 11:26
@iamluc iamluc merged commit 7aeb446 into main Jun 24, 2024
31 checks passed
@iamluc iamluc deleted the luc/skip-span-error-serialization-if-default branch June 24, 2024 11:43
duncanpharvey pushed a commit that referenced this pull request Jul 1, 2024
* Skip serialization of field Span.error if equals to 0

* Add tests

* Move serde_json in dev-dependencies

* Fix clippy
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.

6 participants