|
1 | 1 | using Sentry.Extensibility;
|
| 2 | +using Sentry.Internal; |
2 | 3 | using Sentry.Internal.Extensions;
|
3 | 4 |
|
4 | 5 | namespace Sentry;
|
@@ -560,6 +561,183 @@ public ISpan? Span
|
560 | 561 | set => _span = value;
|
561 | 562 | }
|
562 | 563 |
|
| 564 | + /// <summary> |
| 565 | + /// Invokes all event processor providers available. |
| 566 | + /// </summary> |
| 567 | + public IEnumerable<ISentryEventProcessor> GetAllEventProcessors() |
| 568 | + { |
| 569 | + foreach (var processor in Options.GetAllEventProcessors()) |
| 570 | + { |
| 571 | + yield return processor; |
| 572 | + } |
| 573 | + |
| 574 | + foreach (var processor in EventProcessors) |
| 575 | + { |
| 576 | + yield return processor; |
| 577 | + } |
| 578 | + } |
| 579 | + |
| 580 | + /// <summary> |
| 581 | + /// Invokes all transaction processor providers available. |
| 582 | + /// </summary> |
| 583 | + public IEnumerable<ISentryTransactionProcessor> GetAllTransactionProcessors() |
| 584 | + { |
| 585 | + foreach (var processor in Options.GetAllTransactionProcessors()) |
| 586 | + { |
| 587 | + yield return processor; |
| 588 | + } |
| 589 | + |
| 590 | + foreach (var processor in TransactionProcessors) |
| 591 | + { |
| 592 | + yield return processor; |
| 593 | + } |
| 594 | + } |
| 595 | + |
| 596 | + /// <summary> |
| 597 | + /// Invokes all exception processor providers available. |
| 598 | + /// </summary> |
| 599 | + public IEnumerable<ISentryEventExceptionProcessor> GetAllExceptionProcessors() |
| 600 | + { |
| 601 | + foreach (var processor in Options.GetAllExceptionProcessors()) |
| 602 | + { |
| 603 | + yield return processor; |
| 604 | + } |
| 605 | + |
| 606 | + foreach (var processor in ExceptionProcessors) |
| 607 | + { |
| 608 | + yield return processor; |
| 609 | + } |
| 610 | + } |
| 611 | + |
| 612 | + /// <summary> |
| 613 | + /// Add an exception processor. |
| 614 | + /// </summary> |
| 615 | + /// <param name="processor">The exception processor.</param> |
| 616 | + public void AddExceptionProcessor(ISentryEventExceptionProcessor processor) |
| 617 | + => ExceptionProcessors.Add(processor); |
| 618 | + |
| 619 | + /// <summary> |
| 620 | + /// Add the exception processors. |
| 621 | + /// </summary> |
| 622 | + /// <param name="processors">The exception processors.</param> |
| 623 | + public void AddExceptionProcessors(IEnumerable<ISentryEventExceptionProcessor> processors) |
| 624 | + { |
| 625 | + foreach (var processor in processors) |
| 626 | + { |
| 627 | + ExceptionProcessors.Add(processor); |
| 628 | + } |
| 629 | + } |
| 630 | + |
| 631 | + /// <summary> |
| 632 | + /// Adds an event processor which is invoked when creating a <see cref="SentryEvent"/>. |
| 633 | + /// </summary> |
| 634 | + /// <param name="processor">The event processor.</param> |
| 635 | + public void AddEventProcessor(ISentryEventProcessor processor) |
| 636 | + => EventProcessors.Add(processor); |
| 637 | + |
| 638 | + /// <summary> |
| 639 | + /// Adds an event processor which is invoked when creating a <see cref="SentryEvent"/>. |
| 640 | + /// </summary> |
| 641 | + /// <param name="processor">The event processor.</param> |
| 642 | + public void AddEventProcessor(Func<SentryEvent, SentryEvent> processor) |
| 643 | + => AddEventProcessor(new DelegateEventProcessor(processor)); |
| 644 | + |
| 645 | + /// <summary> |
| 646 | + /// Adds event processors which are invoked when creating a <see cref="SentryEvent"/>. |
| 647 | + /// </summary> |
| 648 | + /// <param name="processors">The event processors.</param> |
| 649 | + public void AddEventProcessors(IEnumerable<ISentryEventProcessor> processors) |
| 650 | + { |
| 651 | + foreach (var processor in processors) |
| 652 | + { |
| 653 | + EventProcessors.Add(processor); |
| 654 | + } |
| 655 | + } |
| 656 | + |
| 657 | + /// <summary> |
| 658 | + /// Adds an transaction processor which is invoked when creating a <see cref="SentryTransaction"/>. |
| 659 | + /// </summary> |
| 660 | + /// <param name="processor">The transaction processor.</param> |
| 661 | + public void AddTransactionProcessor(ISentryTransactionProcessor processor) |
| 662 | + => TransactionProcessors.Add(processor); |
| 663 | + |
| 664 | + /// <summary> |
| 665 | + /// Adds an transaction processor which is invoked when creating a <see cref="SentryTransaction"/>. |
| 666 | + /// </summary> |
| 667 | + /// <param name="processor">The transaction processor.</param> |
| 668 | + public void AddTransactionProcessor(Func<SentryTransaction, SentryTransaction?> processor) |
| 669 | + => AddTransactionProcessor(new DelegateTransactionProcessor(processor)); |
| 670 | + |
| 671 | + /// <summary> |
| 672 | + /// Adds transaction processors which are invoked when creating a <see cref="SentryTransaction"/>. |
| 673 | + /// </summary> |
| 674 | + /// <param name="processors">The transaction processors.</param> |
| 675 | + public void AddTransactionProcessors(IEnumerable<ISentryTransactionProcessor> processors) |
| 676 | + { |
| 677 | + foreach (var processor in processors) |
| 678 | + { |
| 679 | + TransactionProcessors.Add(processor); |
| 680 | + } |
| 681 | + } |
| 682 | + |
| 683 | + /// <summary> |
| 684 | + /// Adds an attachment. |
| 685 | + /// </summary> |
| 686 | + /// <remarks> |
| 687 | + /// Note: the stream must be seekable. |
| 688 | + /// </remarks> |
| 689 | + public void AddAttachment( |
| 690 | + Stream stream, |
| 691 | + string fileName, |
| 692 | + AttachmentType type = AttachmentType.Default, |
| 693 | + string? contentType = null) |
| 694 | + { |
| 695 | + var length = stream.TryGetLength(); |
| 696 | + if (length is null) |
| 697 | + { |
| 698 | + Options.LogWarning( |
| 699 | + "Cannot evaluate the size of attachment '{0}' because the stream is not seekable.", |
| 700 | + fileName); |
| 701 | + |
| 702 | + return; |
| 703 | + } |
| 704 | + |
| 705 | + // TODO: Envelope spec allows the last item to not have a length. |
| 706 | + // So if we make sure there's only 1 item without length, we can support it. |
| 707 | + AddAttachment( |
| 708 | + new SentryAttachment( |
| 709 | + type, |
| 710 | + new StreamAttachmentContent(stream), |
| 711 | + fileName, |
| 712 | + contentType)); |
| 713 | + } |
| 714 | + |
| 715 | + /// <summary> |
| 716 | + /// Adds an attachment. |
| 717 | + /// </summary> |
| 718 | + public void AddAttachment( |
| 719 | + byte[] data, |
| 720 | + string fileName, |
| 721 | + AttachmentType type = AttachmentType.Default, |
| 722 | + string? contentType = null) => |
| 723 | + AddAttachment( |
| 724 | + new SentryAttachment( |
| 725 | + type, |
| 726 | + new ByteAttachmentContent(data), |
| 727 | + fileName, |
| 728 | + contentType)); |
| 729 | + |
| 730 | + /// <summary> |
| 731 | + /// Adds an attachment. |
| 732 | + /// </summary> |
| 733 | + public void AddAttachment(string filePath, AttachmentType type = AttachmentType.Default, string? contentType = null) |
| 734 | + => AddAttachment( |
| 735 | + new SentryAttachment( |
| 736 | + type, |
| 737 | + new FileAttachmentContent(filePath, Options.UseAsyncFileIO), |
| 738 | + Path.GetFileName(filePath), |
| 739 | + contentType)); |
| 740 | + |
563 | 741 | internal void ResetTransaction(ITransactionTracer? expectedCurrentTransaction) =>
|
564 | 742 | Interlocked.CompareExchange(ref _transaction, null, expectedCurrentTransaction);
|
565 | 743 | }
|
0 commit comments