Skip to content

Commit 68fce59

Browse files
authored
Add metrics for tracking partial granularity (#1560)
1 parent 7deaed9 commit 68fce59

File tree

5 files changed

+231
-141
lines changed

5 files changed

+231
-141
lines changed

newrelic/core/application.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,11 @@ def harvest(self, shutdown=False, flexible=False):
13731373
spans_sampled = spans.num_samples
13741374
internal_count_metric("Supportability/SpanEvent/TotalEventsSeen", spans_seen)
13751375
internal_count_metric("Supportability/SpanEvent/TotalEventsSent", spans_sampled)
1376+
if configuration.distributed_tracing.sampler.partial_granularity.enabled:
1377+
internal_count_metric(
1378+
f"Supportability/Python/PartialGranularity/{configuration.distributed_tracing.sampler.partial_granularity.type}",
1379+
1,
1380+
)
13761381

13771382
stats.reset_span_events()
13781383

newrelic/core/node_mixin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ def span_events(
162162
partial_granularity_sampled=partial_granularity_sampled,
163163
ct_exit_spans=ct_exit_spans,
164164
)
165+
ct_exit_spans["instrumented"] += 1
165166
parent_id = parent_guid
166167
if span: # span will be None if the span is an inprocess span or repeated exit span.
168+
ct_exit_spans["kept"] += 1
167169
yield span
168170
# Compressed spans are always reparented onto the entry span.
169171
if not settings.distributed_tracing.sampler.partial_granularity.type == "compact" or span[0].get(
@@ -179,7 +181,9 @@ def span_events(
179181
partial_granularity_sampled=partial_granularity_sampled,
180182
ct_exit_spans=ct_exit_spans,
181183
):
184+
ct_exit_spans["instrumented"] += 1
182185
if event: # event will be None if the span is an inprocess span or repeated exit span.
186+
ct_exit_spans["kept"] += 1
183187
yield event
184188

185189

newrelic/core/stats_engine.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,20 @@ def record_transaction(self, transaction):
11901190
elif transaction.sampled:
11911191
for event in transaction.span_events(self.__settings):
11921192
self._span_events.add(event, priority=transaction.priority)
1193+
if transaction.partial_granularity_sampled:
1194+
partial_gran_type = settings.distributed_tracing.sampler.partial_granularity.type
1195+
self.record_custom_metrics(
1196+
[
1197+
(
1198+
f"Supportability/DistributedTrace/PartialGranularity/{partial_gran_type}/Span/Instrumented",
1199+
{"count": transaction.instrumented},
1200+
),
1201+
(
1202+
f"Supportability/DistributedTrace/PartialGranularity/{partial_gran_type}/Span/Kept",
1203+
{"count": transaction.kept},
1204+
),
1205+
]
1206+
)
11931207

11941208
# Merge in log events
11951209

newrelic/core/transaction_node.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def span_events(self, settings, attr_class=dict):
634634
("priority", self.priority),
635635
)
636636
)
637-
ct_exit_spans = {}
637+
ct_exit_spans = {"instrumented": 0, "kept": 0}
638638
yield from self.root.span_events(
639639
settings,
640640
base_attrs,
@@ -643,3 +643,9 @@ def span_events(self, settings, attr_class=dict):
643643
partial_granularity_sampled=self.partial_granularity_sampled,
644644
ct_exit_spans=ct_exit_spans,
645645
)
646+
# If this transaction is partial granularity sampled, record the number of spans
647+
# instrumented and the number of spans kept to monitor cost savings of partial
648+
# granularity tracing.
649+
if self.partial_granularity_sampled:
650+
self.instrumented = ct_exit_spans["instrumented"]
651+
self.kept = ct_exit_spans["kept"]

0 commit comments

Comments
 (0)