|
178 | 178 | _unsafe_cleanUpContinuousProfilerV2();
|
179 | 179 | } else if (internalTraceId != nil) {
|
180 | 180 | # if !SDK_V9
|
181 |
| - if (sentry_isContinuousProfilingEnabled(hub.getClient)) { |
| 181 | + SentryClient *_Nullable client = hub.getClient; |
| 182 | + if (client == nil) { |
| 183 | + SENTRY_LOG_ERROR(@"No client found, skipping cleanup."); |
| 184 | + return; |
| 185 | + } |
| 186 | + if (sentry_isContinuousProfilingEnabled(SENTRY_UNWRAP_NULLABLE(SentryClient, client))) { |
182 | 187 | SENTRY_LOG_ERROR(@"Tracers are not tracked with continuous profiling V1.");
|
183 | 188 | return;
|
184 | 189 | }
|
|
256 | 261 | {
|
257 | 262 | if (sentry_profileConfiguration != nil && sentry_profileConfiguration.isProfilingThisLaunch
|
258 | 263 | && sentry_profileConfiguration.profileOptions != nil
|
259 |
| - && sentry_isTraceLifecycle(sentry_profileConfiguration.profileOptions)) { |
| 264 | + && sentry_isTraceLifecycle(SENTRY_UNWRAP_NULLABLE( |
| 265 | + SentryProfileOptions, sentry_profileConfiguration.profileOptions))) { |
260 | 266 | SENTRY_LOG_DEBUG(@"Stopping launch UI trace profile.");
|
261 | 267 | sentry_stopTrackingRootSpanForContinuousProfilerV2();
|
262 | 268 | return;
|
263 | 269 | }
|
264 | 270 |
|
265 |
| - if (isProfiling && sentry_isContinuousProfilingV2Enabled(hub.getClient) |
266 |
| - && sentry_isProfilingCorrelatedToTraces(hub.getClient)) { |
| 271 | + SentryClient *_Nullable client = hub.getClient; |
| 272 | + if (isProfiling && client != nil |
| 273 | + && sentry_isContinuousProfilingV2Enabled(SENTRY_UNWRAP_NULLABLE(SentryClient, client)) |
| 274 | + && sentry_isProfilingCorrelatedToTraces(SENTRY_UNWRAP_NULLABLE(SentryClient, client))) { |
267 | 275 | SENTRY_LOG_DEBUG(@"Stopping tracking root span tracer with profilerReferenceId %@",
|
268 | 276 | sentry_stringFromSentryID(transaction.trace.profilerReferenceID));
|
269 | 277 | sentry_stopTrackingRootSpanForContinuousProfilerV2();
|
|
309 | 317 | [SentryTraceProfiler recordMetrics];
|
310 | 318 | transaction.endSystemTime = sentry_getSystemTime();
|
311 | 319 |
|
312 |
| - const auto profiler = sentry_profilerForFinishedTracer(transaction.trace.profilerReferenceID); |
313 |
| - if (!profiler) { |
| 320 | + SentryProfiler *_Nullable nullableProfiler |
| 321 | + = sentry_profilerForFinishedTracer(transaction.trace.profilerReferenceID); |
| 322 | + if (!nullableProfiler) { |
314 | 323 | [hub captureTransaction:transaction withScope:hub.scope];
|
315 | 324 | return;
|
316 | 325 | }
|
| 326 | + SentryProfiler *_Nonnull profiler = SENTRY_UNWRAP_NULLABLE(SentryProfiler, nullableProfiler); |
317 | 327 |
|
318 | 328 | // This code can run on the main thread, and the profile serialization can take a couple of
|
319 | 329 | // milliseconds. Therefore, we move this to a background thread to avoid potentially
|
|
329 | 339 | } else {
|
330 | 340 | [hub captureTransaction:transaction
|
331 | 341 | withScope:hub.scope
|
332 |
| - additionalEnvelopeItems:@[ profileEnvelopeItem ]]; |
| 342 | + additionalEnvelopeItems:@[ SENTRY_UNWRAP_NULLABLE( |
| 343 | + SentryEnvelopeItem, profileEnvelopeItem) ]]; |
333 | 344 | }
|
334 | 345 | });
|
335 | 346 | }
|
|
342 | 353 | // profile config file
|
343 | 354 | return _sentry_startContinuousProfilerV2ForTrace(
|
344 | 355 | sentry_profileConfiguration.profileOptions, transactionContext);
|
345 |
| - } else if (sentry_isContinuousProfilingV2Enabled(hub.getClient)) { |
| 356 | + } |
| 357 | + SentryClient *_Nullable client = hub.getClient; |
| 358 | + if (client != nil |
| 359 | + && sentry_isContinuousProfilingV2Enabled(SENTRY_UNWRAP_NULLABLE(SentryClient, client))) { |
346 | 360 | // non launch profile
|
347 | 361 | if (sentry_getParentSpanID(transactionContext) != nil) {
|
348 | 362 | SENTRY_LOG_DEBUG(@"Not a root span, will not start automatically for trace lifecycle.");
|
349 | 363 | return nil;
|
350 | 364 | }
|
351 | 365 | return _sentry_startContinuousProfilerV2ForTrace(
|
352 |
| - sentry_getProfiling(hub.getClient), transactionContext); |
353 |
| - } else { |
354 |
| - BOOL profileShouldBeSampled |
355 |
| - = configuration.profilesSamplerDecision.decision == kSentrySampleDecisionYes; |
| 366 | + sentry_getProfiling(SENTRY_UNWRAP_NULLABLE(SentryClient, client)), transactionContext); |
| 367 | + } |
| 368 | + BOOL profileShouldBeSampled |
| 369 | + = configuration.profilesSamplerDecision.decision == kSentrySampleDecisionYes; |
356 | 370 | # if !SDK_V9
|
357 |
| - BOOL isContinuousProfiling = sentry_isContinuousProfilingEnabled(hub.client); |
358 |
| - BOOL shouldStartNormalTraceProfile = !isContinuousProfiling && profileShouldBeSampled; |
| 371 | + BOOL isContinuousProfiling = client != nil |
| 372 | + && sentry_isContinuousProfilingEnabled(SENTRY_UNWRAP_NULLABLE(SentryClient, client)); |
| 373 | + BOOL shouldStartNormalTraceProfile = !isContinuousProfiling && profileShouldBeSampled; |
359 | 374 | # else
|
360 |
| - BOOL shouldStartNormalTraceProfile = profileShouldBeSampled; |
| 375 | + BOOL shouldStartNormalTraceProfile = profileShouldBeSampled; |
361 | 376 | # endif // !SDK_V9
|
362 | 377 |
|
363 |
| - if (sentry_isTracingAppLaunch || shouldStartNormalTraceProfile) { |
364 |
| - SentryId *internalID = sentry_getSentryId(); |
365 |
| - if ([SentryTraceProfiler startWithTracer:internalID]) { |
366 |
| - SENTRY_LOG_DEBUG(@"Started profiler for trace %@ with internal id %@", |
367 |
| - sentry_stringFromSentryID(sentry_getTraceID(transactionContext)), |
368 |
| - sentry_stringFromSentryID(internalID)); |
369 |
| - return internalID; |
370 |
| - } |
| 378 | + if (sentry_isTracingAppLaunch || shouldStartNormalTraceProfile) { |
| 379 | + SentryId *internalID = sentry_getSentryId(); |
| 380 | + if ([SentryTraceProfiler startWithTracer:internalID]) { |
| 381 | + SENTRY_LOG_DEBUG(@"Started profiler for trace %@ with internal id %@", |
| 382 | + sentry_stringFromSentryID(sentry_getTraceID(transactionContext)), |
| 383 | + sentry_stringFromSentryID(internalID)); |
| 384 | + return internalID; |
371 | 385 | }
|
372 |
| - return nil; |
373 | 386 | }
|
| 387 | + return nil; |
374 | 388 | }
|
375 | 389 |
|
376 | 390 | # if defined(SENTRY_TEST) || defined(SENTRY_TEST_CI) || defined(DEBUG)
|
|
0 commit comments