Skip to content

Compute top-level span in tracer#2137

Merged
marcotc merged 1 commit into
masterfrom
compute-top-level
Jul 8, 2022
Merged

Compute top-level span in tracer#2137
marcotc merged 1 commit into
masterfrom
compute-top-level

Conversation

@marcotc

@marcotc marcotc commented Jul 8, 2022

Copy link
Copy Markdown
Member

This PR is the first step towards early top level detection in the tracer.

As a preamble, the definition of top-level span is:

A span is defined as a top level if any of the following are true:

  • It’s a root span
  • Its parent has a different service
  • It’s a local root in a distributed trace (local root of flushed trace in an agent)

After the introduction of the service_entry attribute in #2080, now know how to calculate the effective top-level spans in a trace, exactly how the agent does. Both the tracer and agent must follow the definition in previous paragraph.

For every trace received, the agent calculate the top-level spans and tags them with _dd.top_level.
This is the default case. But if we send a special header, (Datadog-Client-Computed-Top-Level), the agent will skip calculating the top-level spans itself.

With this PR, this is he trace timeline:

  1. Tracer sends the trace tagged with top-level tags
  2. Agent does not find the special HTTP header
  3. Agent calculates the top-level spans again, and marks the exact same spans with the _dd.top_level metric.

This means that the traces are effectively the same, but each top-level span received the tagging, span.set_metric('_dd.top_level', 1.0), twice, having no ill-effect.

Follow up work

Introduce the special header https://github.com/DataDog/datadog-agent/blob/b4542cc65a1289cfe72903e52c9ed4d219d6453b/pkg/trace/api/api.go#L359-L361 to allow for the Agent to completely skip top-level calculation.

@marcotc marcotc self-assigned this Jul 8, 2022
@marcotc
marcotc requested a review from a team July 8, 2022 01:02
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #2137 (9ad3d84) into fix-tag-helper (b8e097a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@               Coverage Diff               @@
##           fix-tag-helper    #2137   +/-   ##
===============================================
  Coverage           97.52%   97.53%           
===============================================
  Files                1040     1040           
  Lines               53991    54005   +14     
===============================================
+ Hits                52656    52672   +16     
+ Misses               1335     1333    -2     
Impacted Files Coverage Δ
lib/datadog/tracing/metadata/ext.rb 100.00% <100.00%> (ø)
lib/datadog/tracing/span.rb 97.64% <100.00%> (+1.21%) ⬆️
lib/ddtrace/transport/ext.rb 100.00% <100.00%> (ø)
lib/ddtrace/transport/http.rb 100.00% <100.00%> (ø)
spec/datadog/tracing/span_spec.rb 100.00% <100.00%> (ø)
lib/datadog/core/diagnostics/environment_logger.rb 98.41% <0.00%> (-1.59%) ⬇️
spec/datadog/profiling/ext/forking_spec.rb 100.00% <0.00%> (+0.60%) ⬆️
spec/support/span_helpers.rb 80.64% <0.00%> (+3.22%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@marcotc
marcotc force-pushed the compute-top-level branch from 9ad3d84 to c7edbab Compare July 8, 2022 01:11
Base automatically changed from fix-tag-helper to master July 8, 2022 08:20
@marcotc
marcotc merged commit 640b62e into master Jul 8, 2022
@marcotc
marcotc deleted the compute-top-level branch July 8, 2022 17:45
@github-actions github-actions Bot added this to the 1.2.0 milestone Jul 8, 2022
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.

3 participants