Skip to content

Change UserDetails to a struct#2682

Merged
robertpi merged 4 commits into
masterfrom
appsec/robert/user-details-api-change-request
Apr 19, 2022
Merged

Change UserDetails to a struct#2682
robertpi merged 4 commits into
masterfrom
appsec/robert/user-details-api-change-request

Conversation

@robertpi

Copy link
Copy Markdown
Member

As requested by @lucaspimentel .

@robertpi
robertpi requested a review from a team as a code owner April 13, 2022 13:33
@github-actions github-actions Bot added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Apr 13, 2022

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't notice the requirement that Id is non null before. Given this, I wonder if we should add a constructor like UserDetails(string id), as it's a more idiomatic way to indicate a required value. Obviously, with the switch to a struct, this is not quite as nice, as you can still do new UserDetails(), but I think it's still preferable.

Related: is string.Empty a valid Id? I guess it's a valid tag value, but does it make any sense in this API, given you presumably require an ID value if they're setting other values?

Also, given UserDetails is a new public API, I think we should enable nullable in UserDetails, and mark all the non-Id parameters as string? instead of string. That further hammers home the requirement

@lucaspimentel
lucaspimentel self-requested a review April 13, 2022 14:36
@andrewlock

This comment has been minimized.

@robertpi

Copy link
Copy Markdown
Member Author

I didn't notice the requirement that Id is non null before. Given this, I wonder if we should add a constructor like UserDetails(string id), as it's a more idiomatic way to indicate a required value. Obviously, with the switch to a struct, this is not quite as nice, as you can still do new UserDetails(), but I think it's still preferable.

I added the UserDetails(string id), but still allow the setting of the Id property, as I think many users would prefer to set all properties the same way, even if the requirements vary slightly.

Related: is string.Empty a valid Id? I guess it's a valid tag value, but does it make any sense in this API, given you presumably require an ID value if they're setting other values?

To be honest, not checking for the empty string was an oversight, but I've added a check for it. I do wonder if we might come across some clients who are using the empty string for a special user id, but I think adding the check is okay, since it's easier to relax restrictions than increase them.

Also, given UserDetails is a new public API, I think we should enable nullable in UserDetails, and mark all the non-Id parameters as string? instead of string. That further hammers home the requirement

Yes, I have added this now.

@andrewlock

This comment has been minimized.

@andrewlock

This comment has been minimized.

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍 Thanks for the update

Comment on lines +28 to +31
Email = null;
Name = null;
SessionId = null;
Role = null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Roll-on C#11 where this is implicit 😄

Comment thread tracer/src/Datadog.Trace/SpanExtensions.cs
@andrewlock

Copy link
Copy Markdown
Member

Code Coverage Report 📊

✔️ Merging #2682 into master will not change line coverage
✔️ Merging #2682 into master will not change branch coverage
✔️ Merging #2682 into master will will decrease complexity by 2

master #2682 Change
Lines 13537 / 18627 13525 / 18642
Lines % 73% 73% 0% ✔️
Branches 7815 / 11125 7836 / 11139
Branches % 70% 70% 0% ✔️
Complexity 12431 12429 -2 ✔️

View the full report for further details:

Datadog.Trace Breakdown ✔️

master #2682 Change
Lines % 73% 73% 0% ✔️
Branches % 70% 70% 0% ✔️
Complexity 12431 12429 -2 ✔️

The following classes have significant coverage changes.

File Line coverage change Branch coverage change Complexity change
Datadog.Trace.SpanExtensions -23% -35% -4 ✔️
Datadog.Trace.Ci.GitInfo -17% -11% 0 ✔️
Datadog.Trace.DiagnosticListeners.AspNetCoreDiagnosticObserver 4% ✔️ 6% ✔️ 0 ✔️
Datadog.Trace.Ci.CIVisibility 7% ✔️ 7% ✔️ 0 ✔️
Datadog.Trace.Telemetry.JsonHttpClientTelemetryTransport 26% ✔️ 38% ✔️ 0 ✔️
Datadog.Trace.Telemetry.JsonWebRequestTelemetryTransport 27% ✔️ 57% ✔️ 0 ✔️

The following classes were added in #2682:

File Line coverage Branch coverage Complexity
Datadog.Trace.UserDetails 0% 0% 2

View the full reports for further details:

@andrewlock

Copy link
Copy Markdown
Member

Benchmarks Report 🐌

Benchmarks for #2682 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.162
  • All benchmarks have the same allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net472 923μs 4.08μs 16.8μs 0 0 0 3.16 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 692μs 2.79μs 10.4μs 0 0 0 2.57 KB
#2682 WriteAndFlushEnrichedTraces net472 941μs 4.46μs 17.8μs 0 0 0 3.16 KB
#2682 WriteAndFlushEnrichedTraces netcoreapp3.1 717μs 3.83μs 20.2μs 0 0 0 2.57 KB
Benchmarks.Trace.AppSecBodyBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master AllCycleSimpleBody net472 288ns 1.35ns 5.21ns 0.0519 0 0 329 B
master AllCycleSimpleBody netcoreapp3.1 375ns 1.37ns 4.95ns 0.00462 0 0 328 B
master AllCycleMoreComplexBody net472 299ns 1.73ns 13.9ns 0.0482 0 0 305 B
master AllCycleMoreComplexBody netcoreapp3.1 371ns 1.83ns 7.78ns 0.00422 0 0 304 B
master BodyExtractorSimpleBody net472 423ns 2.37ns 15.9ns 0.0569 0 0 361 B
master BodyExtractorSimpleBody netcoreapp3.1 452ns 2.31ns 10.3ns 0.00376 0 0 272 B
master BodyExtractorMoreComplexBody net472 24μs 89.3ns 346ns 1.19 0.0125 0 7.62 KB
master BodyExtractorMoreComplexBody netcoreapp3.1 21.6μs 105ns 444ns 0.0931 0 0 6.75 KB
#2682 AllCycleSimpleBody net472 299ns 1.52ns 7.28ns 0.052 0 0 329 B
#2682 AllCycleSimpleBody netcoreapp3.1 378ns 1.21ns 4.36ns 0.00455 0 0 328 B
#2682 AllCycleMoreComplexBody net472 302ns 1.73ns 13.2ns 0.0482 0 0 305 B
#2682 AllCycleMoreComplexBody netcoreapp3.1 386ns 2.24ns 19.8ns 0.00421 0 0 304 B
#2682 BodyExtractorSimpleBody net472 423ns 2.13ns 9.74ns 0.0571 0 0 361 B
#2682 BodyExtractorSimpleBody netcoreapp3.1 442ns 2.23ns 9.72ns 0.00364 0 0 272 B
#2682 BodyExtractorMoreComplexBody net472 24.5μs 138ns 903ns 1.19 0.0121 0 7.62 KB
#2682 BodyExtractorMoreComplexBody netcoreapp3.1 20.8μs 81.2ns 304ns 0.094 0 0 6.75 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net472 0ns 0ns 0ns 0 0 0 0 b
master SendRequest netcoreapp3.1 293μs 1.51μs 7.07μs 0.143 0 0 19.74 KB
#2682 SendRequest net472 0ns 0ns 0ns 0 0 0 0 b
#2682 SendRequest netcoreapp3.1 288μs 975ns 3.65μs 0.15 0 0 19.74 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net472 1.67μs 8.7ns 42.6ns 0.0943 0.000827 0 594 B
master ExecuteNonQuery netcoreapp3.1 1.51μs 7.56ns 49ns 0.00838 0 0 632 B
#2682 ExecuteNonQuery net472 1.78μs 9.94ns 62.8ns 0.0942 0 0 594 B
#2682 ExecuteNonQuery netcoreapp3.1 1.53μs 8.61ns 54.5ns 0.00888 0 0 632 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net472 2.67μs 13.3ns 70.1ns 0.126 0 0 802 B
master CallElasticsearch netcoreapp3.1 1.72μs 7.84ns 30.4ns 0.0109 0 0 792 B
master CallElasticsearchAsync net472 3μs 15.8ns 83.8ns 0.148 0 0 939 B
master CallElasticsearchAsync netcoreapp3.1 1.79μs 4.06ns 14.6ns 0.0126 0 0 912 B
#2682 CallElasticsearch net472 2.56μs 14.4ns 91.9ns 0.125 0 0 802 B
#2682 CallElasticsearch netcoreapp3.1 1.71μs 9.1ns 59ns 0.0112 0 0 792 B
#2682 CallElasticsearchAsync net472 2.88μs 14.9ns 74.7ns 0.149 0 0 939 B
#2682 CallElasticsearchAsync netcoreapp3.1 2.02μs 11.2ns 71ns 0.0124 0 0 912 B
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net472 2.9μs 11.2ns 43.5ns 0.167 0 0 1.06 KB
master ExecuteAsync netcoreapp3.1 2.06μs 8.7ns 36.9ns 0.0142 0 0 1.03 KB
#2682 ExecuteAsync net472 2.93μs 15.7ns 80ns 0.168 0.00146 0 1.06 KB
#2682 ExecuteAsync netcoreapp3.1 2.01μs 8.89ns 34.4ns 0.0139 0 0 1.03 KB
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net472 6.57μs 25.4ns 95ns 0.36 0 0 2.28 KB
master SendAsync netcoreapp3.1 5.01μs 28.4ns 199ns 0.0311 0 0 2.21 KB
#2682 SendAsync net472 6.72μs 26.6ns 96ns 0.36 0 0 2.28 KB
#2682 SendAsync netcoreapp3.1 4.99μs 21.6ns 89ns 0.0311 0 0 2.21 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net472 3.54μs 10.7ns 42.7ns 0.228 0 0 1.45 KB
master EnrichedLog netcoreapp3.1 3.25μs 15.3ns 61.1ns 0.0217 0 0 1.53 KB
#2682 EnrichedLog net472 3.65μs 20.1ns 115ns 0.226 0 0 1.45 KB
#2682 EnrichedLog netcoreapp3.1 3.22μs 16ns 73.3ns 0.0201 0 0 1.53 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net472 291μs 1.25μs 4.85μs 0.426 0.142 0 4.33 KB
master EnrichedLog netcoreapp3.1 225μs 646ns 2.42μs 0 0 0 4.21 KB
#2682 EnrichedLog net472 284μs 912ns 3.53μs 0.416 0.139 0 4.33 KB
#2682 EnrichedLog netcoreapp3.1 238μs 1.36μs 10.4μs 0 0 0 4.21 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net472 8.05μs 44.6ns 296ns 0.503 0 0 3.23 KB
master EnrichedLog netcoreapp3.1 6.69μs 31.6ns 126ns 0.0489 0 0 3.6 KB
#2682 EnrichedLog net472 7.54μs 41.3ns 298ns 0.505 0 0 3.23 KB
#2682 EnrichedLog netcoreapp3.1 6.64μs 24.2ns 90.7ns 0.0503 0 0 3.6 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net472 2.63μs 13ns 55ns 0.16 0.00127 0 1.01 KB
master SendReceive netcoreapp3.1 2.12μs 9.86ns 39.4ns 0.014 0 0 1.01 KB
#2682 SendReceive net472 2.39μs 10.9ns 43.8ns 0.16 0.0012 0 1.01 KB
#2682 SendReceive netcoreapp3.1 2.14μs 10.9ns 51ns 0.0137 0 0 1.01 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net472 6.87μs 32.1ns 124ns 0.289 0 0 1.87 KB
master EnrichedLog netcoreapp3.1 5.72μs 31ns 167ns 0.0194 0 0 1.49 KB
#2682 EnrichedLog net472 7.09μs 32.2ns 129ns 0.291 0 0 1.87 KB
#2682 EnrichedLog netcoreapp3.1 5.32μs 30.4ns 234ns 0.0192 0 0 1.49 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net472 973ns 4.7ns 18.8ns 0.0717 0 0 457 B
master StartFinishSpan netcoreapp3.1 864ns 3.35ns 12.5ns 0.00604 0 0 456 B
master StartFinishScope net472 1.06μs 5.78ns 33.2ns 0.0846 0 0 538 B
master StartFinishScope netcoreapp3.1 1.1μs 6.33ns 49.8ns 0.00806 0 0 576 B
#2682 StartFinishSpan net472 991ns 4.25ns 20.4ns 0.0716 0 0 457 B
#2682 StartFinishSpan netcoreapp3.1 925ns 5.1ns 30.6ns 0.00611 0 0 456 B
#2682 StartFinishScope net472 1.08μs 5.62ns 29.2ns 0.0843 0 0 538 B
#2682 StartFinishScope netcoreapp3.1 1.07μs 6.05ns 42.8ns 0.00759 0 0 576 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #2682

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net472 1.162 1,479.91 1,273.22

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net472 1.48μs 7.56ns 33.8ns 0.0838 0 0 538 B
master RunOnMethodBegin netcoreapp3.1 1.22μs 4.71ns 17ns 0.00821 0 0 576 B
#2682 RunOnMethodBegin net472 1.29μs 7.41ns 56.9ns 0.0845 0 0 538 B
#2682 RunOnMethodBegin netcoreapp3.1 1.16μs 6.02ns 30.7ns 0.00794 0 0 576 B

@robertpi
robertpi merged commit 3a71a13 into master Apr 19, 2022
@robertpi
robertpi deleted the appsec/robert/user-details-api-change-request branch April 19, 2022 07:34
@github-actions github-actions Bot added this to the vNext milestone Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:asm area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants