question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `Hint` support to beforeSend and Event processors

See original GitHub issue

Hi, Sentry is great! I am however missing a way to add an attachment to an outgoing event in the BeforeSend callback. For example:

using var host = Host.CreateDefaultBuilder()
    .ConfigureLogging((context, builder) =>
    {
        builder.AddSentry(options =>
        {
            options.BeforeSend = sentryEvent =>
            {
                sentryEvent.AddBreadcrumb("Hello"); // I can do this
                sentryEvent.AddAttachment("Foo.txt"); // But I cannot do this
                return sentryEvent;
            };
        };
    })
    .Build();

Am I missing something, or this is a missing feature?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mattjohnsonpintcommented, Apr 3, 2023

Because we’ve currently implemented BeforeSend as a property that accepts a delegate function, there’s no clean way to add a Hint parameter to the function without making a breaking change that would require a major version bump. Methods are overloadable, but properties are not.

I’d like to handle this as follows:

public class SentryOptions
{
    // ...

    internal Func<SentryEvent, Hint, SentryEvent?>? _beforeSend;

    public void SetBeforeSend(Func<SentryEvent, SentryEvent?> beforeSend)
    {
        _beforeSend = (e, _) => beforeSend(e);
    }

    public void SetBeforeSend(Func<SentryEvent, Hint, SentryEvent?> beforeSend)
    {
        _beforeSend = beforeSend;
    }

    [Obsolete("This property will be removed in a future version. Use SetBeforeSend instead.")]
    public Func<SentryEvent, SentryEvent?>? BeforeSend
    {
        get => null;
        set => _beforeSend = value is null ? null : (e, _) => value(e);
    }

    // ...
}

The usage would then change from:

options.BeforeSend = @event => { ... };

To the following:

options.SetBeforeSend(@event => { ... });

… or when hints are desired:

options.SetBeforeSend((@event, hint) => { ... });
1reaction
mattjohnsonpintcommented, Jun 5, 2022

Note, this also applies to BeforeBreadcrumb, and our docs already (incorrectly) state that hints are supported.

https://docs.sentry.io/platforms/dotnet/configuration/options/#before-breadcrumb

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event Processors for Browser JavaScript
Like beforeSend and beforeSendTransaction , event processors are passed two arguments, the event itself and a hint object containing extra metadata.
Read more >
Filtering for Browser JavaScript
The beforeSend callback is passed both the event and a second argument, hint , that holds one or more hints. Typically a hint...
Read more >
AJAX event for when the server receives the request
Something like onSend is the beforeSend because it executes before sending, and while are you sending, why you would fire a event?
Read more >
Jquery Ajax beforeSend and success,error & complete
The loading class I am adding to the placeholder before sending is working for the first ajax call. However soon after the first...
Read more >
Unified API - Sentry Developer Documentation
We want a unified language/wording of all SDK APIs to aid support and documentation as well as ... event processors: Callbacks that run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found