Skip to content

Commit

Permalink
chore: merge ScopeExtensions to Scope (#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Mar 7, 2024
1 parent 448b2e2 commit d664fc6
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 288 deletions.
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Added Crons support via `SentrySdk.CaptureCheckIn` and an integration with Hangfire ([#3128](https://github.com/getsentry/sentry-dotnet/pull/3128))
- Common tags set automatically for metrics and metrics summaries are attached to Spans ([#3191](https://github.com/getsentry/sentry-dotnet/pull/3191))

### API changes

- Removed `ScopeExtensions` class - all the public methods moved directly to `Scope` ([#3186](https://github.com/getsentry/sentry-dotnet/pull/3186))

### Fixes

- 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))
Expand Down Expand Up @@ -57,14 +61,14 @@

### Fixes

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

## 4.0.2

### Fixes

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

## 4.0.1

### Fixes
### Fixes

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

If you're using `sentry.io` this change does not affect you.
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/).
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/).

### Significant change in behavior

Expand All @@ -135,7 +139,7 @@ If you have conflicts, you can opt out by adding the following to your `csproj`:
<SentryImplicitUsings>false</SentryImplicitUsings>
</PropertyGroup>
```
- 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).
- 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).
- Customers self hosting Sentry must use verion 22.12.0 or later ([#3013](https://github.com/getsentry/sentry-dotnet/pull/3013))
- The `User.IpAddress` is now set to `{{auto}}` by default, even when sendDefaultPII is disabled ([#2981](https://github.com/getsentry/sentry-dotnet/pull/2981))
- The "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io can be used to control this instead
Expand Down
178 changes: 178 additions & 0 deletions src/Sentry/Scope.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Sentry.Extensibility;
using Sentry.Internal;
using Sentry.Internal.Extensions;

namespace Sentry;
Expand Down Expand Up @@ -560,6 +561,183 @@ public ISpan? Span
set => _span = value;
}

/// <summary>
/// Invokes all event processor providers available.
/// </summary>
public IEnumerable<ISentryEventProcessor> GetAllEventProcessors()
{
foreach (var processor in Options.GetAllEventProcessors())
{
yield return processor;
}

foreach (var processor in EventProcessors)
{
yield return processor;
}
}

/// <summary>
/// Invokes all transaction processor providers available.
/// </summary>
public IEnumerable<ISentryTransactionProcessor> GetAllTransactionProcessors()
{
foreach (var processor in Options.GetAllTransactionProcessors())
{
yield return processor;
}

foreach (var processor in TransactionProcessors)
{
yield return processor;
}
}

/// <summary>
/// Invokes all exception processor providers available.
/// </summary>
public IEnumerable<ISentryEventExceptionProcessor> GetAllExceptionProcessors()
{
foreach (var processor in Options.GetAllExceptionProcessors())
{
yield return processor;
}

foreach (var processor in ExceptionProcessors)
{
yield return processor;
}
}

/// <summary>
/// Add an exception processor.
/// </summary>
/// <param name="processor">The exception processor.</param>
public void AddExceptionProcessor(ISentryEventExceptionProcessor processor)
=> ExceptionProcessors.Add(processor);

/// <summary>
/// Add the exception processors.
/// </summary>
/// <param name="processors">The exception processors.</param>
public void AddExceptionProcessors(IEnumerable<ISentryEventExceptionProcessor> processors)
{
foreach (var processor in processors)
{
ExceptionProcessors.Add(processor);
}
}

/// <summary>
/// Adds an event processor which is invoked when creating a <see cref="SentryEvent"/>.
/// </summary>
/// <param name="processor">The event processor.</param>
public void AddEventProcessor(ISentryEventProcessor processor)
=> EventProcessors.Add(processor);

/// <summary>
/// Adds an event processor which is invoked when creating a <see cref="SentryEvent"/>.
/// </summary>
/// <param name="processor">The event processor.</param>
public void AddEventProcessor(Func<SentryEvent, SentryEvent> processor)
=> AddEventProcessor(new DelegateEventProcessor(processor));

/// <summary>
/// Adds event processors which are invoked when creating a <see cref="SentryEvent"/>.
/// </summary>
/// <param name="processors">The event processors.</param>
public void AddEventProcessors(IEnumerable<ISentryEventProcessor> processors)
{
foreach (var processor in processors)
{
EventProcessors.Add(processor);
}
}

/// <summary>
/// Adds an transaction processor which is invoked when creating a <see cref="SentryTransaction"/>.
/// </summary>
/// <param name="processor">The transaction processor.</param>
public void AddTransactionProcessor(ISentryTransactionProcessor processor)
=> TransactionProcessors.Add(processor);

/// <summary>
/// Adds an transaction processor which is invoked when creating a <see cref="SentryTransaction"/>.
/// </summary>
/// <param name="processor">The transaction processor.</param>
public void AddTransactionProcessor(Func<SentryTransaction, SentryTransaction?> processor)
=> AddTransactionProcessor(new DelegateTransactionProcessor(processor));

/// <summary>
/// Adds transaction processors which are invoked when creating a <see cref="SentryTransaction"/>.
/// </summary>
/// <param name="processors">The transaction processors.</param>
public void AddTransactionProcessors(IEnumerable<ISentryTransactionProcessor> processors)
{
foreach (var processor in processors)
{
TransactionProcessors.Add(processor);
}
}

/// <summary>
/// Adds an attachment.
/// </summary>
/// <remarks>
/// Note: the stream must be seekable.
/// </remarks>
public void AddAttachment(
Stream stream,
string fileName,
AttachmentType type = AttachmentType.Default,
string? contentType = null)
{
var length = stream.TryGetLength();
if (length is null)
{
Options.LogWarning(
"Cannot evaluate the size of attachment '{0}' because the stream is not seekable.",
fileName);

return;
}

// TODO: Envelope spec allows the last item to not have a length.
// So if we make sure there's only 1 item without length, we can support it.
AddAttachment(
new SentryAttachment(
type,
new StreamAttachmentContent(stream),
fileName,
contentType));
}

/// <summary>
/// Adds an attachment.
/// </summary>
public void AddAttachment(
byte[] data,
string fileName,
AttachmentType type = AttachmentType.Default,
string? contentType = null) =>
AddAttachment(
new SentryAttachment(
type,
new ByteAttachmentContent(data),
fileName,
contentType));

/// <summary>
/// Adds an attachment.
/// </summary>
public void AddAttachment(string filePath, AttachmentType type = AttachmentType.Default, string? contentType = null)
=> AddAttachment(
new SentryAttachment(
type,
new FileAttachmentContent(filePath, Options.UseAsyncFileIO),
Path.GetFileName(filePath),
contentType));

internal void ResetTransaction(ITransactionTracer? expectedCurrentTransaction) =>
Interlocked.CompareExchange(ref _transaction, null, expectedCurrentTransaction);
}
Loading

0 comments on commit d664fc6

Please sign in to comment.