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

How to discard events from plugins #639

Open
Adeboye opened this issue Oct 25, 2022 · 3 comments
Open

How to discard events from plugins #639

Adeboye opened this issue Oct 25, 2022 · 3 comments

Comments

@Adeboye
Copy link

Adeboye commented Oct 25, 2022

Hi,

I am using plugins to do some validations on events, there are certain events I will like to discard if a certain condition is met. I have tried using ctx.cancel or throwing an error hoping the event pipeline stops but its just retries. How do I go about discarding events ? Refer to the example code below

const filterEvents: Plugin = {
    name: 'Filter events',
    type: 'before',
    version: '1.0.0',
    isLoaded: () => true,
    load: () => Promise.resolve(),
    track: (ctx: Context) => {
    
        // if some condition is met I want to discard this event and stop the pipeline processing
        if (condition met) {
            ctx.cancel();
        }
    
        return ctx;
    };
};
@chrisradek
Copy link
Contributor

@Adeboye Thanks for opening this issue.

In plugins that are before type, you can call ctx.cancel with a ContextCancelation that turns off retries. That would look like this:

import { Context, ContextCancelation } from '@segment/analytics-next

// ... 

track: (ctx: Context) => {
  if (condition_met) {
    ctx.cancel(new ContextCancelation({ retry: false }))
  }
}

@Adeboye
Copy link
Author

Adeboye commented Oct 25, 2022

Thanks for the answer, I was looking in the docs to find where this is documented, could you point me to the area @chrisradek

@Adeboye
Copy link
Author

Adeboye commented Oct 25, 2022

@chrisradek tried the above solution you provided, but I still see the retries happening, any ideas why this is till happening ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants