Skip to content

Commit

Permalink
Return object from sendEvent (#5)
Browse files Browse the repository at this point in the history
I'm thinking we should make this an object in case we ever want to add
more info to this payload, e.g. the eventId
  • Loading branch information
Nicole White committed Aug 15, 2023
1 parent aa3d8f9 commit 6fe4d5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ export class AutoblocksTracer {
timestamp?: string;
properties?: EventProperties;
},
): Promise<string | undefined> {
): Promise<{ traceId?: string }> {
try {
return await this.sendEventUnsafe(message, args);
const traceId = await this.sendEventUnsafe(message, args);
return { traceId };
} catch (err) {
console.error(`Error sending event to Autoblocks: ${err}`);
return undefined;
return {};
}
}
}
6 changes: 3 additions & 3 deletions test/headers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Replay Headers', () => {
const commit = builder.getLocalCommitData({ sha: null });

const ab = new AutoblocksTracer('mock-ingestion-token');
const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('Replay Headers', () => {
});

const ab = new AutoblocksTracer('mock-ingestion-token');
const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('Replay Headers', () => {
});

const ab = new AutoblocksTracer('mock-ingestion-token');
const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand Down
16 changes: 8 additions & 8 deletions test/tracer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Autoblocks Tracer', () => {

it('sends a message', async () => {
const ab = new AutoblocksTracer('mock-ingestion-token');
const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand All @@ -70,7 +70,7 @@ describe('Autoblocks Tracer', () => {
it('sends a message with properties', async () => {
const ab = new AutoblocksTracer('mock-ingestion-token');

const traceId = await ab.sendEvent('mock-message', {
const { traceId } = await ab.sendEvent('mock-message', {
properties: { x: 1 },
});

Expand All @@ -92,7 +92,7 @@ describe('Autoblocks Tracer', () => {
properties: { x: 1 },
});

const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand All @@ -111,7 +111,7 @@ describe('Autoblocks Tracer', () => {
const ab = new AutoblocksTracer('mock-ingestion-token');
ab.setProperties({ x: 1 });

const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand All @@ -130,7 +130,7 @@ describe('Autoblocks Tracer', () => {
const ab = new AutoblocksTracer('mock-ingestion-token');
ab.updateProperties({ x: 1 });

const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand All @@ -151,7 +151,7 @@ describe('Autoblocks Tracer', () => {
});
ab.updateProperties({ x: 10 });

const traceId = await ab.sendEvent('mock-message', {
const { traceId } = await ab.sendEvent('mock-message', {
properties: { y: 20 },
});

Expand All @@ -175,7 +175,7 @@ describe('Autoblocks Tracer', () => {
ab.updateProperties({ x: 10 });
ab.setProperties({ x: 100 });

const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');

expect(traceId).toEqual('mock-trace-id');
expect(mockPost).toHaveBeenCalledWith(
Expand Down Expand Up @@ -274,7 +274,7 @@ describe('Autoblocks Tracer', () => {
});

const ab = new AutoblocksTracer('mock-ingestion-token');
const traceId = await ab.sendEvent('mock-message');
const { traceId } = await ab.sendEvent('mock-message');
expect(traceId).toBeUndefined();
});
});
Expand Down

0 comments on commit 6fe4d5d

Please sign in to comment.