Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions newrelic/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@ def harvest(self, shutdown=False, flexible=False):
spans_sampled = spans.num_samples
internal_count_metric("Supportability/SpanEvent/TotalEventsSeen", spans_seen)
internal_count_metric("Supportability/SpanEvent/TotalEventsSent", spans_sampled)
if configuration.distributed_tracing.sampler.partial_granularity.enabled:
internal_count_metric(
f"Supportability/Python/PartialGranularity/{configuration.distributed_tracing.sampler.partial_granularity.type}",
1,
)

stats.reset_span_events()

Expand Down
4 changes: 4 additions & 0 deletions newrelic/core/node_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ def span_events(
partial_granularity_sampled=partial_granularity_sampled,
ct_exit_spans=ct_exit_spans,
)
ct_exit_spans["instrumented"] += 1
parent_id = parent_guid
if span: # span will be None if the span is an inprocess span or repeated exit span.
ct_exit_spans["kept"] += 1
yield span
# Compressed spans are always reparented onto the entry span.
if not settings.distributed_tracing.sampler.partial_granularity.type == "compact" or span[0].get(
Expand All @@ -179,7 +181,9 @@ def span_events(
partial_granularity_sampled=partial_granularity_sampled,
ct_exit_spans=ct_exit_spans,
):
ct_exit_spans["instrumented"] += 1
if event: # event will be None if the span is an inprocess span or repeated exit span.
ct_exit_spans["kept"] += 1
yield event


Expand Down
14 changes: 14 additions & 0 deletions newrelic/core/stats_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,20 @@ def record_transaction(self, transaction):
elif transaction.sampled:
for event in transaction.span_events(self.__settings):
self._span_events.add(event, priority=transaction.priority)
if transaction.partial_granularity_sampled:
partial_gran_type = settings.distributed_tracing.sampler.partial_granularity.type
self.record_custom_metrics(
[
(
f"Supportability/DistributedTrace/PartialGranularity/{partial_gran_type}/Span/Instrumented",
{"count": transaction.instrumented},
),
(
f"Supportability/DistributedTrace/PartialGranularity/{partial_gran_type}/Span/Kept",
{"count": transaction.kept},
),
]
)

# Merge in log events

Expand Down
8 changes: 7 additions & 1 deletion newrelic/core/transaction_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def span_events(self, settings, attr_class=dict):
("priority", self.priority),
)
)
ct_exit_spans = {}
ct_exit_spans = {"instrumented": 0, "kept": 0}
yield from self.root.span_events(
settings,
base_attrs,
Expand All @@ -643,3 +643,9 @@ def span_events(self, settings, attr_class=dict):
partial_granularity_sampled=self.partial_granularity_sampled,
ct_exit_spans=ct_exit_spans,
)
# If this transaction is partial granularity sampled, record the number of spans
# instrumented and the number of spans kept to monitor cost savings of partial
# granularity tracing.
if self.partial_granularity_sampled:
self.instrumented = ct_exit_spans["instrumented"]
self.kept = ct_exit_spans["kept"]
Loading
Loading