segmentio / analytics-node

The hassle-free way to integrate analytics into any node application.

Home Page:https://segment.com/libraries/node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Track call fails when property has bigint attribute

rgaino opened this issue · comments

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!