|
12 | 12 | #import "SentryDependencyContainer.h" |
13 | 13 | #import "SentryDispatchQueueWrapper.h" |
14 | 14 | #import "SentryDsn.h" |
15 | | -#import "SentryEnvelope.h" |
| 15 | +#import "SentryEnvelope+Private.h" |
16 | 16 | #import "SentryEnvelopeItemType.h" |
17 | 17 | #import "SentryEvent.h" |
18 | 18 | #import "SentryException.h" |
|
28 | 28 | #import "SentryMechanismMeta.h" |
29 | 29 | #import "SentryMessage.h" |
30 | 30 | #import "SentryMeta.h" |
| 31 | +#import "SentryMsgPackSerializer.h" |
31 | 32 | #import "SentryNSError.h" |
32 | 33 | #import "SentryOptions+Private.h" |
33 | 34 | #import "SentryPropagationContext.h" |
34 | 35 | #import "SentryRandom.h" |
| 36 | +#import "SentryReplayEvent.h" |
35 | 37 | #import "SentrySDK+Private.h" |
36 | 38 | #import "SentryScope+Private.h" |
| 39 | +#import "SentrySerialization.h" |
37 | 40 | #import "SentrySession.h" |
38 | 41 | #import "SentryStacktraceBuilder.h" |
39 | 42 | #import "SentrySwift.h" |
@@ -470,13 +473,43 @@ - (void)captureSession:(SentrySession *)session |
470 | 473 | } |
471 | 474 |
|
472 | 475 | SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithSession:session]; |
473 | | - SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:nil |
474 | | - traceContext:nil]; |
475 | | - SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader |
| 476 | + SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:[SentryEnvelopeHeader empty] |
476 | 477 | singleItem:item]; |
477 | 478 | [self captureEnvelope:envelope]; |
478 | 479 | } |
479 | 480 |
|
| 481 | +- (void)captureReplayEvent:(SentryReplayEvent *)replayEvent |
| 482 | + replayRecording:(SentryReplayRecording *)replayRecording |
| 483 | + video:(NSURL *)videoURL |
| 484 | + withScope:(SentryScope *)scope |
| 485 | +{ |
| 486 | + replayEvent = (SentryReplayEvent *)[self prepareEvent:replayEvent |
| 487 | + withScope:scope |
| 488 | + alwaysAttachStacktrace:NO]; |
| 489 | + |
| 490 | + if (![replayEvent isKindOfClass:SentryReplayEvent.class]) { |
| 491 | + SENTRY_LOG_DEBUG(@"The event preprocessor didn't update the replay event in place. The " |
| 492 | + @"replay was discarded."); |
| 493 | + return; |
| 494 | + } |
| 495 | + |
| 496 | + SentryEnvelopeItem *videoEnvelopeItem = |
| 497 | + [[SentryEnvelopeItem alloc] initWithReplayEvent:replayEvent |
| 498 | + replayRecording:replayRecording |
| 499 | + video:videoURL]; |
| 500 | + |
| 501 | + if (videoEnvelopeItem == nil) { |
| 502 | + SENTRY_LOG_DEBUG(@"The Session Replay segment will not be sent to Sentry because an " |
| 503 | + @"Envelope Item could not be created."); |
| 504 | + return; |
| 505 | + } |
| 506 | + |
| 507 | + SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:[SentryEnvelopeHeader empty] |
| 508 | + items:@[ videoEnvelopeItem ]]; |
| 509 | + |
| 510 | + [self captureEnvelope:envelope]; |
| 511 | +} |
| 512 | + |
480 | 513 | - (void)captureEnvelope:(SentryEnvelope *)envelope |
481 | 514 | { |
482 | 515 | if ([self isDisabled]) { |
@@ -551,9 +584,11 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event |
551 | 584 |
|
552 | 585 | BOOL eventIsNotATransaction |
553 | 586 | = event.type == nil || ![event.type isEqualToString:SentryEnvelopeItemTypeTransaction]; |
| 587 | + BOOL eventIsNotReplay |
| 588 | + = event.type == nil || ![event.type isEqualToString:SentryEnvelopeItemTypeReplayVideo]; |
554 | 589 |
|
555 | 590 | // Transactions have their own sampleRate |
556 | | - if (eventIsNotATransaction && [self isSampled:self.options.sampleRate]) { |
| 591 | + if (eventIsNotATransaction && eventIsNotReplay && [self isSampled:self.options.sampleRate]) { |
557 | 592 | SENTRY_LOG_DEBUG(@"Event got sampled, will not send the event"); |
558 | 593 | [self recordLostEvent:kSentryDataCategoryError reason:kSentryDiscardReasonSampleRate]; |
559 | 594 | return nil; |
@@ -581,7 +616,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event |
581 | 616 | [self setSdk:event]; |
582 | 617 |
|
583 | 618 | // We don't want to attach debug meta and stacktraces for transactions; |
584 | | - if (eventIsNotATransaction) { |
| 619 | + if (eventIsNotATransaction && eventIsNotReplay) { |
585 | 620 | BOOL shouldAttachStacktrace = alwaysAttachStacktrace || self.options.attachStacktrace |
586 | 621 | || (nil != event.exceptions && [event.exceptions count] > 0); |
587 | 622 |
|
|
0 commit comments