hashintel / hash

🚀 The open-source, multi-tenant, self-building knowledge graph
https://hash.dev
Other
1.08k stars 83 forks source link

H-3544: Fix spans occurring in unrelated queries #5630

Closed TimDiekmann closed 5 days ago

TimDiekmann commented 5 days ago

🌟 What is the purpose of this PR?

We have an issue that tracing spans from previous queries occurring in new queries.

🔍 What does this change?

When Span::enter() is called and the returned Drop-guard is kept over an .await point it's possible that this results in wrong traces. For more information see the Span::enter() documentation. This PR avoids calling .enter() in async context and uses the Instrument trait instead.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

📜 Does this require a change to the docs?

The changes in this PR:

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

github-actions[bot] commented 5 days ago

Benchmark results

@rust/hash-graph-benches – Integrations

## scaling_read_entity_complete_one_depth | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | 25 entities | $$71.3 \mathrm{ms} \pm 431 \mathrm{μs}\left({\color{gray}-3.624 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_one_depth/entity_by_id/25+entities/flamegraph.svg) | | entity_by_id | 5 entities | $$25.4 \mathrm{ms} \pm 306 \mathrm{μs}\left({\color{gray}0.666 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_one_depth/entity_by_id/5+entities/flamegraph.svg) | | entity_by_id | 1 entities | $$20.2 \mathrm{ms} \pm 96.1 \mathrm{μs}\left({\color{gray}-0.049 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_one_depth/entity_by_id/1+entities/flamegraph.svg) | | entity_by_id | 10 entities | $$30.7 \mathrm{ms} \pm 149 \mathrm{μs}\left({\color{lightgreen}-40.204 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_one_depth/entity_by_id/10+entities/flamegraph.svg) | | entity_by_id | 50 entities | $$543 \mathrm{ms} \pm 3.39 \mathrm{ms}\left({\color{red}100 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_one_depth/entity_by_id/50+entities/flamegraph.svg) | ## representative_read_entity | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/playlist/v/1` | $$15.7 \mathrm{ms} \pm 197 \mathrm{μs}\left({\color{lightgreen}-6.544 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_9/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/book/v/1` | $$16.5 \mathrm{ms} \pm 175 \mathrm{μs}\left({\color{gray}-1.807 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_5/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/organization/v/1` | $$15.8 \mathrm{ms} \pm 160 \mathrm{μs}\left({\color{gray}-3.847 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_6/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1` | $$16.9 \mathrm{ms} \pm 219 \mathrm{μs}\left({\color{red}6.55 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_3/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/person/v/1` | $$16.6 \mathrm{ms} \pm 160 \mathrm{μs}\left({\color{gray}-2.078 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_7/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/page/v/2` | $$16.2 \mathrm{ms} \pm 167 \mathrm{μs}\left({\color{gray}1.40 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_8/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/block/v/1` | $$16.4 \mathrm{ms} \pm 191 \mathrm{μs}\left({\color{gray}0.041 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_4/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/song/v/1` | $$16.2 \mathrm{ms} \pm 183 \mathrm{μs}\left({\color{gray}-1.935 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/building/v/1` | $$17.4 \mathrm{ms} \pm 269 \mathrm{μs}\left({\color{gray}3.35 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_2/flamegraph.svg) | ## scaling_read_entity_complete_zero_depth | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | 25 entities | $$3.30 \mathrm{ms} \pm 17.8 \mathrm{μs}\left({\color{red}19.9 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_zero_depth/entity_by_id/25+entities/flamegraph.svg) | | entity_by_id | 5 entities | $$1.91 \mathrm{ms} \pm 11.3 \mathrm{μs}\left({\color{gray}-1.234 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_zero_depth/entity_by_id/5+entities/flamegraph.svg) | | entity_by_id | 1 entities | $$1.87 \mathrm{ms} \pm 7.61 \mathrm{μs}\left({\color{gray}-0.336 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_zero_depth/entity_by_id/1+entities/flamegraph.svg) | | entity_by_id | 10 entities | $$2.12 \mathrm{ms} \pm 10.9 \mathrm{μs}\left({\color{gray}0.226 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_zero_depth/entity_by_id/10+entities/flamegraph.svg) | | entity_by_id | 50 entities | $$5.26 \mathrm{ms} \pm 26.6 \mathrm{μs}\left({\color{gray}-0.269 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_complete_zero_depth/entity_by_id/50+entities/flamegraph.svg) | ## scaling_read_entity_linkless | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | 1 entities | $$1.85 \mathrm{ms} \pm 10.7 \mathrm{μs}\left({\color{gray}0.277 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_linkless/entity_by_id/1+entities/flamegraph.svg) | | entity_by_id | 10000 entities | $$13.5 \mathrm{ms} \pm 100 \mathrm{μs}\left({\color{gray}0.542 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_linkless/entity_by_id/10000+entities/flamegraph.svg) | | entity_by_id | 100 entities | $$1.95 \mathrm{ms} \pm 6.91 \mathrm{μs}\left({\color{gray}-0.336 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_linkless/entity_by_id/100+entities/flamegraph.svg) | | entity_by_id | 1000 entities | $$2.80 \mathrm{ms} \pm 16.5 \mathrm{μs}\left({\color{gray}-2.656 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_linkless/entity_by_id/1000+entities/flamegraph.svg) | | entity_by_id | 10 entities | $$1.91 \mathrm{ms} \pm 8.10 \mathrm{μs}\left({\color{gray}0.882 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/scaling_read_entity_linkless/entity_by_id/10+entities/flamegraph.svg) | ## representative_read_multiple_entities | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | link_by_source_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$106 \mathrm{ms} \pm 734 \mathrm{μs}\left({\color{gray}-0.811 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=255,+PT=255,+ET=255,+E=255/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$87.8 \mathrm{ms} \pm 883 \mathrm{μs}\left({\color{gray}-0.645 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=0,+ET=2,+E=2/flamegraph.svg) | | link_by_source_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$96.1 \mathrm{ms} \pm 615 \mathrm{μs}\left({\color{gray}-1.009 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=2,+PT=2,+ET=2,+E=2/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$41.2 \mathrm{ms} \pm 309 \mathrm{μs}\left({\color{gray}-2.083 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=0,+ET=0,+E=0/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$91.5 \mathrm{ms} \pm 533 \mathrm{μs}\left({\color{gray}-1.146 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=2,+ET=2,+E=2/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$78.7 \mathrm{ms} \pm 453 \mathrm{μs}\left({\color{gray}-0.976 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=0,+ET=0,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$67.9 \mathrm{ms} \pm 351 \mathrm{μs}\left({\color{gray}-0.227 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/entity_by_property/depths_+DT=255,+PT=255,+ET=255,+E=255/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$48.4 \mathrm{ms} \pm 235 \mathrm{μs}\left({\color{gray}-0.716 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=0,+ET=2,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$57.8 \mathrm{ms} \pm 341 \mathrm{μs}\left({\color{gray}-0.050 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/entity_by_property/depths_+DT=2,+PT=2,+ET=2,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$38.9 \mathrm{ms} \pm 240 \mathrm{μs}\left({\color{gray}-1.112 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=0,+ET=0,+E=0/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$53.2 \mathrm{ms} \pm 225 \mathrm{μs}\left({\color{gray}-0.293 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=2,+ET=2,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$42.9 \mathrm{ms} \pm 306 \mathrm{μs}\left({\color{gray}-1.127 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=0,+ET=0,+E=2/flamegraph.svg) | ## representative_read_entity_type | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | get_entity_type_by_id | Account ID: `d4e16033-c281-4cde-aa35-9085bf2e7579` | $$1.39 \mathrm{ms} \pm 8.44 \mathrm{μs}\left({\color{gray}1.21 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/e24f7edabb2036fe5e9fd2a20fb36012d2bdfa8e/representative_read_entity_type/get_entity_type_by_id/Account+ID_+`d4e16033-c281-4cde-aa35-9085bf2e7579`/flamegraph.svg) |