Skip to content

feat(types): beforeSend and beforeSendTransaction breaking changes #11354

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

Merged
merged 4 commits into from
Apr 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/browser/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@sentry/core';
import * as utils from '@sentry/utils';

import type { Event } from '../../src';
import { setCurrentClient } from '../../src';
import {
BrowserClient,
Expand Down Expand Up @@ -213,7 +212,7 @@ describe('SentryBrowser', () => {

it('should capture a message', done => {
const options = getDefaultBrowserClientOptions({
beforeSend: (event: Event): Event | null => {
beforeSend: event => {
expect(event.message).toBe('test');
expect(event.exception).toBeUndefined();
done();
Expand All @@ -227,7 +226,7 @@ describe('SentryBrowser', () => {

it('should capture an event', done => {
const options = getDefaultBrowserClientOptions({
beforeSend: (event: Event): Event | null => {
beforeSend: event => {
expect(event.message).toBe('event');
expect(event.exception).toBeUndefined();
done();
Expand All @@ -241,7 +240,7 @@ describe('SentryBrowser', () => {

it('should set `platform` on events', done => {
const options = getDefaultBrowserClientOptions({
beforeSend: (event: Event): Event | null => {
beforeSend: event => {
expect(event.platform).toBe('javascript');
done();
return event;
Expand Down
10 changes: 5 additions & 5 deletions packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, Envelope, Event } from '@sentry/types';
import type { Client, Envelope, ErrorEvent, Event, TransactionEvent } from '@sentry/types';
import { SentryError, SyncPromise, dsnToString, logger } from '@sentry/utils';

import { Scope, addBreadcrumb, getCurrentScope, getIsolationScope, makeSession, setCurrentClient } from '../../src';
Expand Down Expand Up @@ -1065,7 +1065,7 @@ describe('BaseClient', () => {

const beforeSend = jest.fn(
async event =>
new Promise<Event>(resolve => {
new Promise<ErrorEvent>(resolve => {
setTimeout(() => {
resolve(event);
}, 1);
Expand Down Expand Up @@ -1095,7 +1095,7 @@ describe('BaseClient', () => {

const beforeSendTransaction = jest.fn(
async event =>
new Promise<Event>(resolve => {
new Promise<TransactionEvent>(resolve => {
setTimeout(() => {
resolve(event);
}, 1);
Expand Down Expand Up @@ -1125,7 +1125,7 @@ describe('BaseClient', () => {

const beforeSend = jest.fn(async event => {
event.message = 'changed2';
return new Promise<Event>(resolve => {
return new Promise<ErrorEvent>(resolve => {
setTimeout(() => {
resolve(event);
}, 1);
Expand Down Expand Up @@ -1155,7 +1155,7 @@ describe('BaseClient', () => {

const beforeSendTransaction = jest.fn(async event => {
event.transaction = '/adopt/dont/shop';
return new Promise<Event>(resolve => {
return new Promise<TransactionEvent>(resolve => {
setTimeout(() => {
resolve(event);
}, 1);
Expand Down
11 changes: 6 additions & 5 deletions packages/types/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
import type { ErrorEvent, Event, EventHint, TransactionEvent } from './event';
import type { ErrorEvent, EventHint, TransactionEvent } from './event';
import type { Integration } from './integration';
import type { CaptureContext } from './scope';
import type { SdkMetadata } from './sdkmetadata';
Expand Down Expand Up @@ -255,7 +255,6 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
*/
tracesSampler?: (samplingContext: SamplingContext) => number | boolean;

// TODO (v8): Narrow the response type to `ErrorEvent` - this is technically a breaking change.
/**
* An event-processing callback for error and message events, guaranteed to be invoked after all other event
* processors, which allows an event to be modified or dropped.
Expand All @@ -267,9 +266,8 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
* @param hint Event metadata useful for processing.
* @returns A new event that will be sent | null.
*/
beforeSend?: (event: ErrorEvent, hint: EventHint) => PromiseLike<Event | null> | Event | null;
beforeSend?: (event: ErrorEvent, hint: EventHint) => PromiseLike<ErrorEvent | null> | ErrorEvent | null;

// TODO (v8): Narrow the response type to `TransactionEvent` - this is technically a breaking change.
/**
* An event-processing callback for transaction events, guaranteed to be invoked after all other event
* processors. This allows an event to be modified or dropped before it's sent.
Expand All @@ -281,7 +279,10 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
* @param hint Event metadata useful for processing.
* @returns A new event that will be sent | null.
*/
beforeSendTransaction?: (event: TransactionEvent, hint: EventHint) => PromiseLike<Event | null> | Event | null;
beforeSendTransaction?: (
event: TransactionEvent,
hint: EventHint,
) => PromiseLike<TransactionEvent | null> | TransactionEvent | null;

/**
* A callback invoked when adding a breadcrumb, allowing to optionally modify
Expand Down