Normalize CosmosDB resource URI IDs to reduce resource cardinality#8541
Conversation
Snapshots difference summaryThe following differences have been observed in committed snapshots. It is meant to help the reviewer. 2 occurrences of : - Resource: Delete dbs/db/colls/items/docs/TestFamily.1,
+ Resource: Delete dbs/db/colls/items/docs/?,
2 occurrences of : - Resource: Read dbs/db/colls/items/docs/TestFamily.1,
+ Resource: Read dbs/db/colls/items/docs/?,
2 occurrences of : - Resource: Replace dbs/db/colls/items/docs/TestFamily.1,
+ Resource: Replace dbs/db/colls/items/docs/?,
2 occurrences of : - Resource: Read dbs/db/colls/items/docs/Andersen.1,
+ Resource: Read dbs/db/colls/items/docs/?,
2 occurrences of : - Resource: Read dbs/db/colls/items/docs/Wakefield.7,
+ Resource: Read dbs/db/colls/items/docs/?,
|
4ef47f1 to
c5d2bac
Compare
BenchmarksBenchmark execution time: 2026-04-30 12:15:03 Comparing candidate commit 5c26637 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics, 58 known flaky benchmarks, 29 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8541) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (74ms) : 70, 79
master - mean (75ms) : 70, 81
section Bailout
This PR (8541) - mean (79ms) : 76, 83
master - mean (79ms) : 76, 83
section CallTarget+Inlining+NGEN
This PR (8541) - mean (1,123ms) : 1072, 1174
master - mean (1,130ms) : 1057, 1203
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (117ms) : 112, 123
master - mean (117ms) : 109, 124
section Bailout
This PR (8541) - mean (115ms) : 111, 118
master - mean (115ms) : 112, 117
section CallTarget+Inlining+NGEN
This PR (8541) - mean (814ms) : 788, 839
master - mean (811ms) : 786, 835
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (103ms) : 99, 106
master - mean (104ms) : 98, 109
section Bailout
This PR (8541) - mean (106ms) : 100, 112
master - mean (103ms) : 98, 108
section CallTarget+Inlining+NGEN
This PR (8541) - mean (953ms) : 914, 993
master - mean (948ms) : 901, 995
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (101ms) : 97, 104
master - mean (101ms) : 97, 106
section Bailout
This PR (8541) - mean (104ms) : 97, 111
master - mean (105ms) : 99, 111
section CallTarget+Inlining+NGEN
This PR (8541) - mean (839ms) : 780, 897
master - mean (831ms) : 790, 871
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (201ms) : 192, 209
master - mean (203ms) : 194, 212
section Bailout
This PR (8541) - mean (204ms) : 197, 211
master - mean (206ms) : 196, 216
section CallTarget+Inlining+NGEN
This PR (8541) - mean (1,231ms) : 1186, 1276
master - mean (1,243ms) : 1203, 1283
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (289ms) : 275, 303
master - mean (290ms) : 275, 305
section Bailout
This PR (8541) - mean (292ms) : 276, 307
master - mean (292ms) : 280, 304
section CallTarget+Inlining+NGEN
This PR (8541) - mean (997ms) : 971, 1024
master - mean (994ms) : 964, 1024
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (287ms) : 274, 301
master - mean (283ms) : 271, 294
section Bailout
This PR (8541) - mean (290ms) : 277, 302
master - mean (285ms) : 269, 301
section CallTarget+Inlining+NGEN
This PR (8541) - mean (1,169ms) : 1128, 1210
master - mean (1,166ms) : 1125, 1206
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8541) - mean (289ms) : 271, 307
master - mean (282ms) : 269, 295
section Bailout
This PR (8541) - mean (291ms) : 271, 311
master - mean (282ms) : 270, 294
section CallTarget+Inlining+NGEN
This PR (8541) - mean (1,058ms) : 999, 1117
master - mean (1,044ms) : 991, 1096
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
andrewlock
left a comment
There was a problem hiding this comment.
I think we can optimize the allocations, but the main question I have is whether we're sure we're ok making a breaking change here without an escape hatch?
| return resourceUriString; | ||
| } | ||
|
|
||
| var segments = resourceUriString.Split('/'); |
There was a problem hiding this comment.
We should avoid using Split if possible because it allocates a bunch. We should be able to do this more efficiently using either IndexOf('/') and manually handling it, or potentially using StringSplitEnumerator.
There was a problem hiding this comment.
Addressed in f2334a0 (assuming you were referring to SpanSplitEnumerator)
andrewlock
left a comment
There was a problem hiding this comment.
As discussed offline, I think we can probably remove the setting for now if we consider this to be a bugfix (and not fixing it could cause cardinality issues for customers).
| if (sb is null && redact) | ||
| { | ||
| // On the first redaction found, append everything from 0 until the start of that segment as-is | ||
| sb = StringBuilderCache.Acquire(resourceUriString.Length); |
There was a problem hiding this comment.
nit/FYI: given you know the maximum length of the string up front, and you're only adding string segments to it (no additional formatting), you could avoid using the StringBuilder entirely in the "fast path" and use a stackalloc which may be preferable. There's also ValueStringBuilder which works similarly. You might want to consider that as an alternative 🙂
There was a problem hiding this comment.
Didn't know about ValueStringBuilder until now, if that's alright let's leave that up as a possible optimization in case this ever becomes a hot path
## Description Normalize CosmosDB resource URI IDs to reduce resource cardinality. Resource cardinality should be bound, as it affects metrics and UI. Normalize even segments from the URI that are not the database id or the collection id. Replicates dotnet fix DataDog/dd-trace-dotnet#8541 ## Testing Unit tests ## Risks Users with dashboards and monitors configured on the resource of these spans. Changed without possibility to fall back to the old behavior because this is a bug: * Unbounded card can be problematic * Filters/groups on resources containing IDs are pretty much useless Co-authored-by: pablo.martinezbernardo <[email protected]>
Summary of changes
Normalize CosmosDB resource URI IDs to reduce resource cardinality
Reason for change
Resource cardinality should be bound, as it affects metrics and UI
Implementation details
Normalize even segments from the URI that are not the database id or the collection id
Test coverage
Unit tests