Skip to content

[Event Lifecycle Hooks] Serialized Events Cause DX Issues #13285

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

Closed
souredoutlook opened this issue Aug 8, 2024 · 4 comments
Closed

[Event Lifecycle Hooks] Serialized Events Cause DX Issues #13285

souredoutlook opened this issue Aug 8, 2024 · 4 comments

Comments

@souredoutlook
Copy link
Member

Problem Statement

Any time a developer wants to mutate their event data before it's sent to Sentry they need to use a beforeX hook.

These hooks provide serialized events to work with which is convenient for evaluating an event's key's values but inconvenient for mutating the event without access to any of the event methods.

Example:

I want to upcycle a spans duration into a custom metric:

  beforeSendSpan: (span)=>{
    if (span.op.includes("ui.react")) {

      Sentry.metrics.distribution(`${span.op}.duration`, span.timestamp - span.start_timestamp, {
        tags: { componentName: span.description },
        unit: "millisecond",
      });

      console.log("Adding metric ",`${span.op}.duration`)
    }

    return span
  }

This metric is not connected to the sampled span and this API will be going away.

I can't use span.setAttribute here because the span is already serialized.

Solution Brainstorm

Provide lifecycle hooks that can hook into events prior to serialization so that event methods can be used on them.

@andreiborza
Copy link
Member

Hey, thanks for filing this. I've added it to our backlog.

Users can also set attributes on span.data in our beforeSendSpan hook, e.g. span.data?.['new-attr'] = 123.

@lforst
Copy link
Member

lforst commented Nov 8, 2024

I think our API should be powerful enough for all use-cases described here. We expose certain hooks on the Client like .on('spanStart') and .on('spanEnd'). These hooks also allow you to mutate the underlying entity.

Maybe I don't understand correctly but it would probably help to have a bit more concrete suggestions for what these hooks should look like and behave before we can implement this.

@AbhiPrasad
Copy link
Member

We have the lifecycle hooks, we just need to document them (if we decide to do that). Still in the backlog as such.

Copy link
Member

mydea commented Apr 14, 2025

this should no longer be an issue, as metrics are now just span data, which should be possible to set in the existing hooks nicely.

@mydea mydea closed this as completed Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants