Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge ScopeExtensions to Scope #3186

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Added Crons support via `SentrySdk.CaptureCheckIn` and an integration with Hangfire ([#3128](https://github.com/getsentry/sentry-dotnet/pull/3128))

### API changes

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that change even visible to users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be for c# users

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their code won't have to change if they're recompiling with the new code. Technically I guess it's not binary compatible (if someone was using reflection to get at these extension methods for some strange reason, that would break)... I'm not sure how hard core we want to be about avoiding breaking changes. @bruno-garcia can we be "pragmatic" here?

Copy link
Contributor

@bitsandfoxes bitsandfoxes Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we be "pragmatic" here?

Yes, especially since this is improving/fixing things on the Powershell side and not just a refactor for fun.


### Fixes

- Empty strings are used instead of underscores to replace invalid metric tag values ([#3176](https://github.com/getsentry/sentry-dotnet/pull/3176))
Expand Down Expand Up @@ -49,14 +53,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 @@ -69,9 +73,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 @@ -113,7 +117,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 @@ -127,7 +131,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
Loading