Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Track call fails when property has bigint attribute #375

Open
rgaino opened this issue Nov 15, 2023 · 0 comments
Open

Track call fails when property has bigint attribute #375

rgaino opened this issue Nov 15, 2023 · 0 comments

Comments

@rgaino
Copy link

rgaino commented Nov 15, 2023

Package version is latest: "@segment/analytics-node": "^1.1.3".

The segment node package fails to send events when any of the properties attributes are of the bigint type. There's no type error, and no error returned in the callback, but the track() calls returns immediately.

import { Analytics } from '@segment/analytics-node';

const analytics = new Analytics({ writeKey: process.env.SEGMENT_WRITE_KEY });

const start = new Date();
const timeElapsedInMs = () => new Date().getTime() - start.getTime();

analytics.track(
	{
		userId: 'test@test.com',
		event: 'NoBigInt event',
		properties: {
			someInt: 1,
		},
	},
	(err) => console.log('err1:', err, 'timeElapsedInMs:', timeElapsedInMs()),
);

analytics.track(
	{
		userId: 'test@test.com',
		event: 'BigInt event',
		properties: {
			someInt: 2,
			someBigInt: BigInt(1234567890),
		},
	},
	(err) => console.log('err2:', err, 'timeElapsedInMs:', timeElapsedInMs()),
);

output:

err2: undefined timeElapsedInMs: 302
err1: undefined timeElapsedInMs: 11033

I'm not quite sure what the behaviour should be here, but it took me some digging to figure out what was going on. On my app, I added a type check because I have a wrapper and use TypeScript, so now I'm covered. I think at a minimum the library should not allow bigint types, because currently the type is Record<string, any> (see https://github.com/segmentio/analytics-next/blob/master/packages/core/src/events/interfaces.ts#L22C50-L22C50), or the callback should return an error, or both.

Thanks!

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

No branches or pull requests

1 participant