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

Provide visibility to errors if segment events do not send #1035

Open
ElizabethWoodhouse opened this issue Feb 5, 2024 · 2 comments
Open
Labels
bug Something isn't working enhancement New feature or request

Comments

@ElizabethWoodhouse
Copy link

ElizabethWoodhouse commented Feb 5, 2024

Found that we're unable to see when segment events have successfully sent: when calling analytics.track the app receives undefined as a response (even if the event has been sent successfully). When an event has not been successfully sent there have been multiple times an error gets swallowed inside analytics-next and never surface to the consuming app.

Examples:

  • When sending additional eventProperties I accidentally sent data that could not be json stringified saw in the debugger that the even failed here but we did not have access to the error so an error was never thrown inside our app even though we have analytics.track wrapped in a try/catch. There's no way to have typescript catch this error prior to sending because eventProperties are type to take any value
  • We were unable to see that the utm-parameter 'search' should be passed in as a string - Fix wrong utm parsing by making context.page.search the source of truth for query params. #839 so we were silently not sending events.
@silesky silesky added bug Something isn't working enhancement New feature or request labels Mar 14, 2024
@marianomerlo
Copy link

marianomerlo commented Dec 16, 2024

Not sure if it's the same issue but it looks like very similar. I'm trying to programatically validate my segment Key:

const { Analytics } = require('@segment/analytics-node');

return new Promise((resolve, reject) => {
  new Analytics({ writeKey: 'thisIsAWrongKey' }).track(
    {
      userId: 'anonymous',
      event: 'API KEY VALIDATION',
      properties: {}
    },
    (err) => {
      if (err) {
        reject(new Error('Analytics key is invalid'));
      }
      resolve();
    }
  );
});

Internally it seems that is depends on ctx.failedDelivery() to call the callback with an error but ctx.failedDelivery() is undefined.

@jgrauel
Copy link

jgrauel commented Dec 16, 2024

We have also observed that we don't get any indication when loading of analytics fails as well, it too is swallowed inside and never hits the catch block

SegmentAnalytics
    .load({ writeKey })
    .then(() => {

    })
    .catch((error) => {
      logger.warn(error, `Segment - ${callingMethodName} : Encountered error when attempting to load.`)
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants