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

Add transaction op default #2691

Merged
merged 7 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- Add `lastEventId` method to the API ([#2675](https://github.com/getsentry/sentry-react-native/pull/2675))

### Fix
- `Sentry.startTransaction` doesn't require `op` ([#2691](https://github.com/getsentry/sentry-react-native/pull/2691))
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved

### Dependencies

- Bump Cocoa SDK from v7.31.2 to v7.31.3 ([#2647](https://github.com/getsentry/sentry-react-native/pull/2647))
Expand Down
6 changes: 5 additions & 1 deletion src/js/measurements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function _addTracingExtensions(): void {
}
}

type StartTransactionFunction = (
export type StartTransactionFunction = (
this: Hub,
transactionContext: TransactionContext,
customSamplingContext?: CustomSamplingContext
Expand All @@ -48,6 +48,10 @@ const _patchStartTransaction = (
transactionContext: TransactionContext,
customSamplingContext?: CustomSamplingContext
): Transaction {
if (!transactionContext.op) {
transactionContext.op = 'default';
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
}
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved

const transaction: Transaction = originalStartTransaction.apply(this, [
transactionContext,
customSamplingContext,
Expand Down
27 changes: 27 additions & 0 deletions test/measurements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getCurrentHub,getMainCarrier } from '@sentry/core';

import { _addTracingExtensions, StartTransactionFunction } from '../src/js/measurements';

describe('Tracing extensions', () => {
test('transaction has default op', async () => {
_addTracingExtensions();
const hub = getCurrentHub();
const carrier = getMainCarrier();
const startTransaction = carrier.__SENTRY__?.extensions?.startTransaction as StartTransactionFunction | undefined;

const transaction = startTransaction?.apply(hub, [{}]);

expect(transaction).toEqual(expect.objectContaining({ op: 'default' }));
});

test('transaction does not overwrite custom op', async () => {
_addTracingExtensions();
const hub = getCurrentHub();
const carrier = getMainCarrier();
const startTransaction = carrier.__SENTRY__?.extensions?.startTransaction as StartTransactionFunction | undefined;

const transaction = startTransaction?.apply(hub, [{ op: 'custom' }]);

expect(transaction).toEqual(expect.objectContaining({ op: 'custom' }));
});
});