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

fix(core): Return checkin id from client #8116

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/browser/test/unit/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { createTransport, Scope } from '@sentry/core';
import { MockIntegration } from '@sentry/core/test/lib/sdk.test';
import type { Client, Integration } from '@sentry/types';
import { resolvedSyncPromise } from '@sentry/utils';

Expand All @@ -18,6 +17,14 @@ function getDefaultBrowserOptions(options: Partial<BrowserOptions> = {}): Browse
};
}

export class MockIntegration implements Integration {
public name: string;
public setupOnce: () => void = jest.fn();
public constructor(name: string) {
this.name = name;
}
}

jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,14 @@ export function startTransaction(
* to create a monitor automatically when sending a check in.
*/
export function captureCheckIn(checkIn: CheckIn, upsertMonitorConfig?: MonitorConfig): string {
const capturedCheckIn =
checkIn.status !== 'in_progress' && checkIn.checkInId ? checkIn : { ...checkIn, checkInId: uuid4() };

const client = getCurrentHub().getClient();
if (!client) {
__DEBUG_BUILD__ && logger.warn('Cannot capture check-in. No client defined.');
} else if (!client.captureCheckIn) {
__DEBUG_BUILD__ && logger.warn('Cannot capture check-in. Client does not support sending check-ins.');
} else {
client.captureCheckIn(capturedCheckIn, upsertMonitorConfig);
return client.captureCheckIn(checkIn, upsertMonitorConfig);
}

return capturedCheckIn.checkInId;
return uuid4();
}
2 changes: 1 addition & 1 deletion packages/core/test/lib/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('captureCheckIn', () => {
} as unknown as Client;
});

expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual(expect.any(String));
expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual('some-id-wasd-1234');
});

it('returns an id when client is undefined', () => {
Expand Down