Skip to content

Commit d664fc6

Browse files
authored
chore: merge ScopeExtensions to Scope (#3186)
1 parent 448b2e2 commit d664fc6

8 files changed

+244
-288
lines changed

CHANGELOG.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- Added Crons support via `SentrySdk.CaptureCheckIn` and an integration with Hangfire ([#3128](https://github.com/getsentry/sentry-dotnet/pull/3128))
88
- Common tags set automatically for metrics and metrics summaries are attached to Spans ([#3191](https://github.com/getsentry/sentry-dotnet/pull/3191))
99

10+
### API changes
11+
12+
- Removed `ScopeExtensions` class - all the public methods moved directly to `Scope` ([#3186](https://github.com/getsentry/sentry-dotnet/pull/3186))
13+
1014
### Fixes
1115

1216
- The Sentry Middleware on ASP.NET Core no longer throws an exception after having been initialized multiple times ([#3185](https://github.com/getsentry/sentry-dotnet/pull/3185))
@@ -57,14 +61,14 @@
5761

5862
### Fixes
5963

60-
- To resolve conflicting types due to the SDK adding itself to the global usings:
64+
- To resolve conflicting types due to the SDK adding itself to the global usings:
6165
- The class `Sentry.Constants` has been renamed to `Sentry.SentryConstants` ([#3125](https://github.com/getsentry/sentry-dotnet/pull/3125))
6266

6367
## 4.0.2
6468

6569
### Fixes
6670

67-
- To resolve conflicting types due to the SDK adding itself to the global usings:
71+
- To resolve conflicting types due to the SDK adding itself to the global usings:
6872
- The class `Sentry.Context` has been renamed to `Sentry.SentryContext` ([#3121](https://github.com/getsentry/sentry-dotnet/pull/3121))
6973
- The class `Sentry.Package` has been renamed to `Sentry.SentryPackage` ([#3121](https://github.com/getsentry/sentry-dotnet/pull/3121))
7074
- The class `Sentry.Request` has been renamed to `Sentry.SentryRequest` ([#3121](https://github.com/getsentry/sentry-dotnet/pull/3121))
@@ -77,9 +81,9 @@
7781

7882
## 4.0.1
7983

80-
### Fixes
84+
### Fixes
8185

82-
- To resolve conflicting types due to the SDK adding itself to the global usings:
86+
- To resolve conflicting types due to the SDK adding itself to the global usings:
8387
- The interface `Sentry.ISession` has been renamed to `Sentry.ISentrySession` ([#3110](https://github.com/getsentry/sentry-dotnet/pull/3110))
8488
- The interface `Sentry.IJsonSerializable` has been renamed to `Sentry.ISentryJsonSerializable` ([#3116](https://github.com/getsentry/sentry-dotnet/pull/3116))
8589
- The class `Sentry.Session` has been renamed to `Sentry.SentrySession` ([#3110](https://github.com/getsentry/sentry-dotnet/pull/3110))
@@ -121,7 +125,7 @@ We're dropping support for some of the old target frameworks, please check this
121125
### Sentry Self-hosted Compatibility
122126

123127
If you're using `sentry.io` this change does not affect you.
124-
This SDK version is compatible with a self-hosted version of Sentry `22.12.0` or higher. If you are using an older version of [self-hosted Sentry](https://develop.sentry.dev/self-hosted/) (aka on-premise), you will need to [upgrade](https://develop.sentry.dev/self-hosted/releases/).
128+
This SDK version is compatible with a self-hosted version of Sentry `22.12.0` or higher. If you are using an older version of [self-hosted Sentry](https://develop.sentry.dev/self-hosted/) (aka on-premise), you will need to [upgrade](https://develop.sentry.dev/self-hosted/releases/).
125129

126130
### Significant change in behavior
127131

@@ -135,7 +139,7 @@ If you have conflicts, you can opt out by adding the following to your `csproj`:
135139
<SentryImplicitUsings>false</SentryImplicitUsings>
136140
</PropertyGroup>
137141
```
138-
- Transactions' spans are no longer automatically finished with the status `deadline_exceeded` by the transaction. This is now handled by the [Relay](https://github.com/getsentry/relay).
142+
- Transactions' spans are no longer automatically finished with the status `deadline_exceeded` by the transaction. This is now handled by the [Relay](https://github.com/getsentry/relay).
139143
- Customers self hosting Sentry must use verion 22.12.0 or later ([#3013](https://github.com/getsentry/sentry-dotnet/pull/3013))
140144
- The `User.IpAddress` is now set to `{{auto}}` by default, even when sendDefaultPII is disabled ([#2981](https://github.com/getsentry/sentry-dotnet/pull/2981))
141145
- The "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io can be used to control this instead

src/Sentry/Scope.cs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Sentry.Extensibility;
2+
using Sentry.Internal;
23
using Sentry.Internal.Extensions;
34

45
namespace Sentry;
@@ -560,6 +561,183 @@ public ISpan? Span
560561
set => _span = value;
561562
}
562563

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+
563741
internal void ResetTransaction(ITransactionTracer? expectedCurrentTransaction) =>
564742
Interlocked.CompareExchange(ref _transaction, null, expectedCurrentTransaction);
565743
}

0 commit comments

Comments
 (0)