Skip to content

Commit

Permalink
Fix runtime-id and system.pid tags not being set on distributed traces (
Browse files Browse the repository at this point in the history
DataDog#2562)

* Add regression test

* Fix runtime id tag not being set on distributed traces

As per title.

* Use same logic for pid

* Update releasenotes/notes/runtimeid-39dfdf1e0c1af45d.yaml

Co-authored-by: Brett Langdon <me@brett.is>

* Fix spelling, grpc snapshot

Co-authored-by: Brett Langdon <me@brett.is>
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
  • Loading branch information
3 people authored Jun 22, 2021
1 parent 852214d commit 6d81403
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 34 deletions.
6 changes: 4 additions & 2 deletions ddtrace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,6 @@ def _start_span(
on_finish=[self._on_span_finish],
)
span._local_root = span
span.metrics[system.PID] = self._pid or getpid()
span.meta["runtime-id"] = get_runtime_id()
if config.report_hostname:
span.meta[HOSTNAME_KEY] = hostname.get_hostname()
span.sampled = self.sampler.sample(span)
Expand Down Expand Up @@ -581,6 +579,10 @@ def _start_span(
# We must always mark the span as sampled so it is forwarded to the agent
span.sampled = True

if not span._parent:
span.meta["runtime-id"] = get_runtime_id()
span.metrics[system.PID] = self._pid

# Apply default global tags.
if self.tags:
span.set_tags(self.tags)
Expand Down
2 changes: 2 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mysqldb
namespace
opentracer
opentracing
pid
plugin
posix
postgres
Expand All @@ -107,6 +108,7 @@ repo
respawn
runnable
runtime
runtime-id
sanic
sql
sqlalchemy
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/runtimeid-39dfdf1e0c1af45d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fix runtime-id and system.pid tags not being set on distributed traces.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"span_id" 0
"trace_id" 0
"parent_id" nil
"start" 1619744633550844100
"duration" 1911900
"meta" {"runtime-id" "04d67a3bd550461295cfd98eedc69d99"
"grpc.port" "55945"
"start" 1624047273666117000
"duration" 2052000
"meta" {"runtime-id" "d8bca53d2d0942c69b9144e37b3626c6"
"grpc.port" "59087"
"grpc.host" "::"
"grpc.method.kind" "unary"
"span.kind" "client"
Expand All @@ -20,7 +20,7 @@
"metrics" {"_dd.agent_psr" 1.0
"_dd.measured" 1
"_sampling_priority_v1" 1
"system.pid" 714
"system.pid" 18581
"_dd.tracer_kr" 1.0}}
{"name" "grpc"
"service" "grpc-server"
Expand All @@ -30,14 +30,16 @@
"span_id" 1
"trace_id" 0
"parent_id" 0
"start" 1619744633552296900
"duration" 48200
"meta" {"grpc.method.path" "/Servicer/Handler"
"start" 1624047273667894000
"duration" 43000
"meta" {"runtime-id" "d8bca53d2d0942c69b9144e37b3626c6"
"grpc.method.path" "/Servicer/Handler"
"grpc.method.service" "Servicer"
"grpc.method.name" "Handler"
"grpc.method.kind" "unary"
"span.kind" "server"}
"metrics" {"_dd.measured" 1}}]
"metrics" {"_dd.measured" 1
"system.pid" 18581}}]
[{"name" "grpc"
"service" "grpc-client"
"resource" "/pkg.Servicer/Handler"
Expand All @@ -46,10 +48,10 @@
"span_id" 0
"trace_id" 1
"parent_id" nil
"start" 1619744633553123900
"duration" 1079700
"meta" {"runtime-id" "04d67a3bd550461295cfd98eedc69d99"
"grpc.port" "55945"
"start" 1624047273668507000
"duration" 601000
"meta" {"runtime-id" "d8bca53d2d0942c69b9144e37b3626c6"
"grpc.port" "59087"
"grpc.method.package" "pkg"
"grpc.host" "::"
"grpc.method.kind" "unary"
Expand All @@ -61,7 +63,7 @@
"metrics" {"_dd.agent_psr" 1.0
"_dd.measured" 1
"_sampling_priority_v1" 1
"system.pid" 714
"system.pid" 18581
"_dd.tracer_kr" 1.0}}
{"name" "grpc"
"service" "grpc-server"
Expand All @@ -71,12 +73,14 @@
"span_id" 1
"trace_id" 1
"parent_id" 0
"start" 1619744633553812700
"duration" 42900
"meta" {"grpc.method.path" "/pkg.Servicer/Handler"
"start" 1624047273668929000
"duration" 29000
"meta" {"runtime-id" "d8bca53d2d0942c69b9144e37b3626c6"
"grpc.method.path" "/pkg.Servicer/Handler"
"grpc.method.package" "pkg"
"grpc.method.service" "Servicer"
"grpc.method.name" "Handler"
"grpc.method.kind" "unary"
"span.kind" "server"}
"metrics" {"_dd.measured" 1}}]]
"metrics" {"_dd.measured" 1
"system.pid" 18581}}]]
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"span_id" 0
"trace_id" 0
"parent_id" nil
"start" 1618357801277945181
"duration" 107575512
"meta" {"runtime-id" "cb4a438bb8364fa5ac0fec9f7df34c89"}
"start" 1624045258581163000
"duration" 22147000
"meta" {"runtime-id" "afc32eb3be454c03b8a140291d5fd696"}
"metrics" {"_dd.agent_psr" 1.0
"_sampling_priority_v1" 1
"system.pid" 8786
"system.pid" 12507
"_dd.tracer_kr" 1.0}}
{"name" "child"
"service" nil
Expand All @@ -19,7 +19,9 @@
"span_id" 1
"trace_id" 0
"parent_id" 0
"start" 1618357801293690837
"duration" 76002
"start" 1624045258591089000
"duration" 53000
"meta" {"runtime-id" "dc30b84ca01142239a7f2a51d9c7725e"}
"metrics" {"_sampling_priority_v1" 1
"system.pid" 12517
"_dd.tracer_kr" 1.0}}]]
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"span_id" 0
"trace_id" 0
"parent_id" nil
"start" 1618357412996234998
"duration" 425047115
"meta" {"runtime-id" "31d11c17a6c547ccb9169d1347b1379e"}
"start" 1624045173599735000
"duration" 51650000
"meta" {"runtime-id" "120a8105b0c542d889b939d7c91d71fa"}
"metrics" {"_dd.agent_psr" 1.0
"_sampling_priority_v1" 1
"system.pid" 6435
"system.pid" 12266
"_dd.tracer_kr" 1.0}}
{"name" "child1"
"service" nil
Expand All @@ -19,9 +19,11 @@
"span_id" 1
"trace_id" 0
"parent_id" 0
"start" 1618357413012622804
"duration" 315314377
"start" 1624045173606288000
"duration" 32138000
"meta" {"runtime-id" "8fba36822c6846d895a13f5d043543be"}
"metrics" {"_sampling_priority_v1" 1
"system.pid" 12294
"_dd.tracer_kr" 1.0}}
{"name" "child2"
"service" nil
Expand All @@ -30,7 +32,9 @@
"span_id" 2
"trace_id" 0
"parent_id" 1
"start" 1618357413236058471
"duration" 75980
"start" 1624045173612023000
"duration" 86000
"meta" {"runtime-id" "859c494affcb4933a1e15b6c4d2561b8"}
"metrics" {"_sampling_priority_v1" 1
"system.pid" 12295
"_dd.tracer_kr" 1.0}}]]
9 changes: 9 additions & 0 deletions tests/tracer/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,15 @@ def task(tracer, q):
assert children_tag != span.get_tag("runtime-id")


def test_tracer_runtime_tags_cross_execution(tracer):
ctx = Context(trace_id=12, span_id=21)
tracer.context_provider.activate(ctx)
with tracer.trace("span") as span:
pass
assert span.get_tag("runtime-id") is not None
assert span.get_metric(system.PID) is not None


def test_start_span_hooks():
t = ddtrace.Tracer()

Expand Down

0 comments on commit 6d81403

Please sign in to comment.