|
7 | 7 | use Sentry\Event; |
8 | 8 | use Sentry\EventId; |
9 | 9 | use Sentry\Profiles\ProfileChunk; |
10 | | -use Sentry\Profiles\Profiles; |
| 10 | +use Sentry\Profiles\Profiler as ContinuousProfiler; |
11 | 11 | use Sentry\Profiling\Profiler; |
12 | 12 | use Sentry\SentrySdk; |
13 | 13 | use Sentry\State\HubInterface; |
@@ -38,7 +38,7 @@ final class Transaction extends Span |
38 | 38 | protected $metadata; |
39 | 39 |
|
40 | 40 | /** |
41 | | - * @var Profiler|null Reference instance to the {@see Profiler} |
| 41 | + * @var Profiler|ContinuousProfiler|null Reference instance to the {@see Profiler or @see ContinuousProfiler} |
42 | 42 | */ |
43 | 43 | protected $profiler; |
44 | 44 |
|
@@ -121,19 +121,31 @@ public function initSpanRecorder(int $maxSpans = 1000): self |
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 |
|
124 | | - public function initProfiler(): Profiler |
| 124 | + /** |
| 125 | + * @return Profiler|ContinuousProfiler|null |
| 126 | + */ |
| 127 | + public function initProfiler() |
125 | 128 | { |
126 | 129 | if ($this->profiler === null) { |
127 | 130 | $client = $this->hub->getClient(); |
128 | 131 | $options = $client !== null ? $client->getOptions() : null; |
129 | 132 |
|
130 | | - $this->profiler = new Profiler($options); |
| 133 | + if ($options !== null) { |
| 134 | + if ($options->getProfilesLifecycle() === 'trace' && $options->getProfilesSessionSampleRate() !== null) { |
| 135 | + $this->profiler = new ContinuousProfiler($options); |
| 136 | + } else { |
| 137 | + $this->profiler = new Profiler($options); |
| 138 | + } |
| 139 | + } |
131 | 140 | } |
132 | 141 |
|
133 | 142 | return $this->profiler; |
134 | 143 | } |
135 | 144 |
|
136 | | - public function getProfiler(): ?Profiler |
| 145 | + /** |
| 146 | + * @return Profiler|ContinuousProfiler|null |
| 147 | + */ |
| 148 | + public function getProfiler() |
137 | 149 | { |
138 | 150 | return $this->profiler; |
139 | 151 | } |
@@ -185,16 +197,18 @@ public function finish(?float $endTimestamp = null): ?EventId |
185 | 197 | $event->setSdkMetadata('dynamic_sampling_context', $this->getDynamicSamplingContext()); |
186 | 198 | $event->setSdkMetadata('transaction_metadata', $this->getMetadata()); |
187 | 199 |
|
188 | | - if ($this->profiler !== null) { |
| 200 | + // Legacy Profiler |
| 201 | + if ($this->profiler !== null && $this->profiler instanceof Profiler) { |
189 | 202 | $profile = $this->profiler->getProfile(); |
190 | 203 | if ($profile !== null) { |
191 | 204 | $event->setSdkMetadata('profile', $profile); |
192 | 205 | } |
193 | 206 | } |
194 | 207 |
|
195 | | - if (Profiles::getInstance()->getProfiler()->getProfilerId() !== null) { |
| 208 | + // Continuous Profiler |
| 209 | + if ($this->profiler !== null && $this->profiler instanceof ContinuousProfiler) { |
196 | 210 | $event->setContext('profile', [ |
197 | | - 'profiler_id' => Profiles::getInstance()->getProfiler()->getProfilerId(), |
| 211 | + 'profiler_id' => $this->profiler->getProfilerId(), |
198 | 212 | ]); |
199 | 213 |
|
200 | 214 | $traceContext = $this->getTraceContext(); |
|
0 commit comments