Skip to content

Commit

Permalink
Merge pull request #22 from allenisalai/fix-datadog-tracer-reset
Browse files Browse the repository at this point in the history
Remove manual rate limiting  and fix GlobalTracer reset
  • Loading branch information
magikid authored Jan 15, 2024
2 parents 421ce69 + 8618736 commit 44ae175
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/Profiler/DatadogProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,9 @@ class DatadogProfiler implements ProfilerInterface

private LoggerInterface $logger;

private float $sampleRate = 1.0;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;

$sampleRateString = getenv('DD_TRACE_SAMPLE_RATE');
if (is_numeric($sampleRateString)) {
$sampleRate = (float) $sampleRateString;
$this->sampleRate = $sampleRate;
}
}

public function start(string $name, ?string $kind = null): void
Expand All @@ -41,10 +33,6 @@ public function start(string $name, ?string $kind = null): void
return;
}

if ($this->rateLimited()) {
return;
}

if (dd_trace_env_config('DD_TRACE_GENERATE_ROOT_SPAN')) {
$this->logger->error(
sprintf('You should set DD_TRACE_GENERATE_ROOT_SPAN=0 when using %s.', self::class)
Expand Down Expand Up @@ -98,14 +86,13 @@ public function stopAndIgnore(): void
return;
}

GlobalTracer::set(new Tracer());
}
$this->scope = null;

private function rateLimited(): bool
{
$randomFloat = mt_rand() / mt_getrandmax(); // between 0 and 1
// https://github.com/DataDog/dd-trace-php/issues/1533#issuecomment-1059211743
ini_set('datadog.trace.enabled', '0');
ini_set('datadog.trace.enabled', '1');

return $randomFloat > $this->sampleRate;
GlobalTracer::set(new Tracer());
}

private function isEnabled(): bool
Expand Down

0 comments on commit 44ae175

Please sign in to comment.