Skip to content

Commit 54bac44

Browse files
committed
check for non valid spans
1 parent c5e1d48 commit 54bac44

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/FilebeatContextProcessor.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,26 @@ public function traceExtras(): array
8686
$context = \OpenTelemetry\Context\Context::getCurrent();
8787
$spanContext = \OpenTelemetry\API\Trace\Span::fromContext($context)->getContext();
8888

89-
return [
90-
'trace' => [
91-
'id' => $spanContext->getTraceId(),
92-
],
93-
];
89+
if($spanContext->isValid()){
90+
return [
91+
'trace' => [
92+
'id' => $spanContext->getTraceId(),
93+
],
94+
];
95+
}
9496
}
9597

9698
if (class_exists(\Elastic\Apm\ElasticApm::class)) {
9799
$traceId = \Elastic\Apm\ElasticApm::getCurrentTransaction()->getTraceId();
98100

99-
return [
100-
'trace' => [
101-
'id' => $traceId,
102-
],
103-
];
101+
// Only return a trace id if valid, i.e. not all zeros
102+
if ($traceId !== '00000000000000000000000000000000') {
103+
return [
104+
'trace' => [
105+
'id' => $traceId,
106+
],
107+
];
108+
}
104109
}
105110

106111
return [];

0 commit comments

Comments
 (0)