Skip to content

[Tracer] add SpanContext.None#2309

Merged
lucaspimentel merged 3 commits into
masterfrom
lpimentel/empty-spancontext
Jan 26, 2022
Merged

[Tracer] add SpanContext.None#2309
lucaspimentel merged 3 commits into
masterfrom
lpimentel/empty-spancontext

Conversation

@lucaspimentel

@lucaspimentel lucaspimentel commented Jan 13, 2022

Copy link
Copy Markdown
Member

See issue #2267.

Add a static SpanContext.None that can be used to explicitly prevent a span from inheriting the currently active span as its parent. This replaces the ignoreActiveScope parameter from .NET Tracer 1.x:

// Don't inherit the currently active span as the parent.
var startNewTrace = new SpanCreationSettings { Parent = SpanContext.None };

// This scope is now the root of a new trace.
// NOTE: It is also the active span in `Tracer.Instance.ActiveScope`. 
var scope = Tracer.Instance.StartActive("span-name", startNewTrace);

Open questions:

  • Property name: SpanContext.Empty or SpanContext.None?
  • Underlying type: SpanContext or a new internal ReadOnlySpanContext type?

@lucaspimentel lucaspimentel added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Jan 13, 2022
@andrewlock

This comment has been minimized.

@andrewlock

This comment has been minimized.

Comment thread tracer/src/Datadog.Trace/SpanContext.cs Outdated
@andrewlock

This comment has been minimized.

Comment thread tracer/src/Datadog.Trace/SpanContext.cs Outdated
@lucaspimentel lucaspimentel changed the title add SpanContext.Empty add SpanContext.None Jan 18, 2022
@lucaspimentel lucaspimentel marked this pull request as ready for review January 18, 2022 13:52
@lucaspimentel lucaspimentel requested a review from a team as a code owner January 18, 2022 13:52
@lucaspimentel lucaspimentel force-pushed the lpimentel/empty-spancontext branch from 3e8c0cd to a2f151d Compare January 18, 2022 13:58
@andrewlock

This comment has been minimized.

@zacharycmontoya zacharycmontoya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lucaspimentel lucaspimentel force-pushed the lpimentel/empty-spancontext branch from a2f151d to 67039a0 Compare January 25, 2022 15:51
@andrewlock

Copy link
Copy Markdown
Member

Benchmarks Report 🐌

Benchmarks for #2309 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.268
  • 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 938μs 4.78μs 21.4μs 0 0 0 3.16 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 726μs 1.46μs 5.48μs 0 0 0 2.57 KB
#2309 WriteAndFlushEnrichedTraces net472 949μs 4.8μs 21.4μs 0 0 0 3.16 KB
#2309 WriteAndFlushEnrichedTraces netcoreapp3.1 719μs 2.79μs 11.9μs 0 0 0 2.57 KB
Benchmarks.Trace.AspNetCoreBenchmark - Unknown 🤷 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 357μs 1.23μs 5.79μs 0.172 0 0 19.67 KB
#2309 SendRequest net472 0ns 0ns 0ns 0 0 0 0 b
#2309 SendRequest netcoreapp3.1 355μs 1.5μs 5.82μs 0.174 0 0 19.67 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.75μs 7.67ns 28.7ns 0.093 0.000894 0 586 B
master ExecuteNonQuery netcoreapp3.1 1.6μs 4.32ns 16.2ns 0.00876 0 0 624 B
#2309 ExecuteNonQuery net472 1.76μs 6.73ns 26.1ns 0.0923 0.00087 0 586 B
#2309 ExecuteNonQuery netcoreapp3.1 1.68μs 9.07ns 75.9ns 0.00876 0 0 624 B
Benchmarks.Trace.ElasticsearchBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #2309

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑net472 1.268 3,326.52 2,622.75

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net472 2.52μs 8.7ns 33.7ns 0.124 0 0 794 B
master CallElasticsearch netcoreapp3.1 1.89μs 10.4ns 67.3ns 0.0113 0 0 784 B
master CallElasticsearchAsync net472 3.33μs 13.4ns 50.1ns 0.145 0 0 931 B
master CallElasticsearchAsync netcoreapp3.1 2.03μs 11.7ns 88ns 0.0124 0 0 904 B
#2309 CallElasticsearch net472 2.56μs 14ns 92.7ns 0.124 0 0 794 B
#2309 CallElasticsearch netcoreapp3.1 1.8μs 7.62ns 27.5ns 0.0107 0 0 784 B
#2309 CallElasticsearchAsync net472 2.65μs 14.2ns 82.9ns 0.145 0 0 931 B
#2309 CallElasticsearchAsync netcoreapp3.1 1.87μs 4.97ns 19.3ns 0.013 0 0 904 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 3.03μs 16.4ns 111ns 0.165 0 0 1.05 KB
master ExecuteAsync netcoreapp3.1 2.16μs 7.18ns 26.9ns 0.0138 0 0 1.02 KB
#2309 ExecuteAsync net472 2.88μs 9.77ns 35.2ns 0.165 0 0 1.05 KB
#2309 ExecuteAsync netcoreapp3.1 2.07μs 6.77ns 25.3ns 0.0141 0 0 1.02 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.78μs 31.1ns 124ns 0.352 0 0 2.26 KB
master SendAsync netcoreapp3.1 4.89μs 18.8ns 70.3ns 0.0288 0 0 2.16 KB
#2309 SendAsync net472 6.86μs 22.8ns 88.2ns 0.352 0 0 2.26 KB
#2309 SendAsync netcoreapp3.1 4.72μs 15.3ns 55ns 0.0305 0 0 2.16 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.75μs 17.9ns 71.6ns 0.224 0 0 1.44 KB
master EnrichedLog netcoreapp3.1 3.41μs 10.9ns 42.2ns 0.02 0 0 1.52 KB
#2309 EnrichedLog net472 3.61μs 13.6ns 54.5ns 0.225 0 0 1.44 KB
#2309 EnrichedLog netcoreapp3.1 3.37μs 6.96ns 26.9ns 0.022 0 0 1.52 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 313μs 1.22μs 4.73μs 0.316 0.158 0 4.31 KB
master EnrichedLog netcoreapp3.1 251μs 1.01μs 3.79μs 0 0 0 4.19 KB
#2309 EnrichedLog net472 319μs 1.72μs 9.86μs 0.31 0.155 0 4.31 KB
#2309 EnrichedLog netcoreapp3.1 250μs 743ns 2.78μs 0 0 0 4.19 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.39μs 35.1ns 136ns 0.5 0 0 3.21 KB
master EnrichedLog netcoreapp3.1 6.93μs 36.9ns 248ns 0.0502 0 0 3.58 KB
#2309 EnrichedLog net472 8.69μs 48.7ns 323ns 0.499 0 0 3.21 KB
#2309 EnrichedLog netcoreapp3.1 6.85μs 16.3ns 56.6ns 0.0512 0 0 3.58 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.76μs 15.2ns 98.7ns 0.156 0 0 1 KB
master SendReceive netcoreapp3.1 2.15μs 12ns 82.2ns 0.0139 0 0 1 KB
#2309 SendReceive net472 2.49μs 5.28ns 20.4ns 0.156 0 0 1 KB
#2309 SendReceive netcoreapp3.1 2.25μs 6.58ns 25.5ns 0.0144 0 0 1 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.99μs 31.9ns 119ns 0.286 0 0 1.85 KB
master EnrichedLog netcoreapp3.1 5.49μs 16.7ns 64.7ns 0.0197 0 0 1.47 KB
#2309 EnrichedLog net472 6.69μs 21ns 75.7ns 0.287 0 0 1.85 KB
#2309 EnrichedLog netcoreapp3.1 5.54μs 14.9ns 55.7ns 0.0194 0 0 1.47 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 1.02μs 4.89ns 19.6ns 0.0702 0 0 449 B
master StartFinishSpan netcoreapp3.1 961ns 3.29ns 12.3ns 0.00615 0 0 448 B
master StartFinishScope net472 1.23μs 4.46ns 16.7ns 0.0829 0 0 530 B
master StartFinishScope netcoreapp3.1 1.11μs 2.52ns 9.76ns 0.00773 0 0 568 B
#2309 StartFinishSpan net472 978ns 4.39ns 15.8ns 0.0703 0 0 449 B
#2309 StartFinishSpan netcoreapp3.1 990ns 3.02ns 11.7ns 0.00635 0 0 448 B
#2309 StartFinishScope net472 1.22μs 3.88ns 15ns 0.0827 0 0 530 B
#2309 StartFinishScope netcoreapp3.1 1.16μs 5.43ns 24.3ns 0.00817 0 0 568 B

@andrewlock

Copy link
Copy Markdown
Member

Code Coverage Report 📊

✔️ Merging #2309 into master will not change line coverage
✔️ Merging #2309 into master will not change branch coverage
⛔ Merging #2309 into master will will increase complexity by 1

master #2309 Change
Lines 10429 / 14678 10422 / 14680
Lines % 71% 71% 0% ✔️
Branches 5361 / 7739 5351 / 7739
Branches % 69% 69% 0% ✔️
Complexity 8850 8851 1

View the full report for further details:

Datadog.Trace Breakdown ✔️

master #2309 Change
Lines % 71% 71% 0% ✔️
Branches % 69% 69% 0% ✔️
Complexity 8850 8851 1

The following classes have significant coverage changes.

File Line coverage change Branch coverage change Complexity change
Datadog.Trace.ClrProfiler.AutoInstrumentation.Couchbase.IIOServiceExecuteIntegrationBis -100% 0% ✔️ 0 ✔️
Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.TestMethodRunnerExecuteIntegration -33% -19% 0 ✔️
Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitCompositeWorkItemSkipChildrenIntegration -8% -8% 0 ✔️
Datadog.Trace.Ci.Agent.CIAgentWriter -5% -21% 0 ✔️
Datadog.Trace.Agent.StreamFactories.UnixDomainSocketStreamFactory 8% ✔️ 0% ✔️ 0 ✔️
Datadog.Trace.Agent.Transports.HttpStreamRequestFactory 20% ✔️ 0% ✔️ 0 ✔️

The following classes were added in #2309:

File Line coverage Branch coverage Complexity
Datadog.Trace.ReadOnlySpanContext 100% 100% 1

View the full reports for further details:

@lucaspimentel lucaspimentel merged commit c5abb49 into master Jan 26, 2022
@lucaspimentel lucaspimentel deleted the lpimentel/empty-spancontext branch January 26, 2022 14:14
@github-actions github-actions Bot added this to the vNext milestone Jan 26, 2022
@lucaspimentel lucaspimentel linked an issue Feb 2, 2022 that may be closed by this pull request
@lucaspimentel lucaspimentel changed the title add SpanContext.None [Tracer] add SpanContext.None Aug 25, 2022
@lucaspimentel lucaspimentel mentioned this pull request Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

How to create a root scope with v2 API

4 participants