Skip to content

Commit f162790

Browse files
Merge remote-tracking branch 'origin/main' into 5.0.0
2 parents 3ddf4dd + 9928882 commit f162790

File tree

5 files changed

+86
-6
lines changed

5 files changed

+86
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

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

9+
### Fix
10+
11+
- `Sentry.startTransaction` doesn't require `op` ([#2691](https://github.com/getsentry/sentry-react-native/pull/2691))
12+
913
### Dependencies
1014

1115
- Bump Cocoa SDK from v7.31.2 to v7.31.3 ([#2647](https://github.com/getsentry/sentry-react-native/pull/2647))
@@ -14,6 +18,9 @@
1418
- Bump JavaScript SDK from v7.21.1 to v7.26.0 ([#2672](https://github.com/getsentry/sentry-react-native/pull/2672), [#2648](https://github.com/getsentry/sentry-react-native/pull/2648), [#2692](https://github.com/getsentry/sentry-react-native/pull/2692))
1519
- [changelog](https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md#7260)
1620
- [diff](https://github.com/getsentry/sentry-javascript/compare/7.21.1...7.26.0)
21+
- Bump Android SDK from v6.9.1 to v6.9.2 ([#2677](https://github.com/getsentry/sentry-react-native/pull/2677))
22+
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#692)
23+
- [diff](https://github.com/getsentry/sentry-java/compare/6.9.1...6.9.2)
1724

1825
## 5.0.0-alpha.10
1926

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ android {
4242

4343
dependencies {
4444
implementation 'com.facebook.react:react-native:+'
45-
api 'io.sentry:sentry-android:6.9.1'
45+
api 'io.sentry:sentry-android:6.9.2'
4646
}

src/js/measurements.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getCurrentHub, getMainCarrier, Hub } from '@sentry/core';
22
import { Transaction } from '@sentry/tracing';
3-
import { CustomSamplingContext, TransactionContext } from '@sentry/types';
3+
import { CustomSamplingContext, Span, SpanContext, TransactionContext } from '@sentry/types';
44

55
import { ReactNativeTracing } from './tracing';
66

7+
const SPAN_OP_DEFAULT = 'default';
8+
79
/**
810
* Adds React Native's extensions. Needs to be called after @sentry/tracing's extension methods are added
911
*/
@@ -28,7 +30,7 @@ export function _addTracingExtensions(): void {
2830
}
2931
}
3032

31-
type StartTransactionFunction = (
33+
export type StartTransactionFunction = (
3234
this: Hub,
3335
transactionContext: TransactionContext,
3436
customSamplingContext?: CustomSamplingContext
@@ -48,10 +50,25 @@ const _patchStartTransaction = (
4850
transactionContext: TransactionContext,
4951
customSamplingContext?: CustomSamplingContext
5052
): Transaction {
53+
// Native SDKs require op to be set - for JS Relay sets `default`
54+
if (!transactionContext.op) {
55+
transactionContext.op = SPAN_OP_DEFAULT;
56+
}
57+
5158
const transaction: Transaction = originalStartTransaction.apply(this, [
5259
transactionContext,
5360
customSamplingContext,
5461
]);
62+
const originalStartChild: Transaction['startChild'] = transaction.startChild.bind(transaction);
63+
transaction.startChild = (
64+
spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'sampled' | 'traceId' | 'parentSpanId'>>,
65+
): Span => {
66+
return originalStartChild({
67+
...spanContext,
68+
// Native SDKs require op to be set
69+
op: spanContext?.op || SPAN_OP_DEFAULT,
70+
});
71+
};
5572

5673
const reactNativeTracing = getCurrentHub().getIntegration(
5774
ReactNativeTracing

test/measurements.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Carrier, getCurrentHub, getMainCarrier } from '@sentry/core';
2+
import { Transaction } from '@sentry/tracing';
3+
import { Hub } from '@sentry/types';
4+
5+
import { _addTracingExtensions, StartTransactionFunction } from '../src/js/measurements';
6+
7+
describe('Tracing extensions', () => {
8+
let hub: Hub;
9+
let carrier: Carrier;
10+
let startTransaction: StartTransactionFunction | undefined;
11+
12+
beforeEach(() => {
13+
_addTracingExtensions();
14+
hub = getCurrentHub();
15+
carrier = getMainCarrier();
16+
startTransaction = carrier.__SENTRY__?.extensions?.startTransaction as StartTransactionFunction | undefined;
17+
});
18+
19+
test('transaction has default op', async () => {
20+
const transaction: Transaction = startTransaction?.apply(hub, [{}]);
21+
22+
expect(transaction).toEqual(expect.objectContaining({ op: 'default' }));
23+
});
24+
25+
test('transaction does not overwrite custom op', async () => {
26+
const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]);
27+
28+
expect(transaction).toEqual(expect.objectContaining({ op: 'custom' }));
29+
});
30+
31+
test('transaction start span creates default op', async () => {
32+
const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]);
33+
const span = transaction?.startChild();
34+
35+
expect(span).toEqual(expect.objectContaining({ op: 'default' }));
36+
});
37+
38+
test('transaction start span keeps custom op', async () => {
39+
const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]);
40+
const span = transaction?.startChild({ op: 'custom' });
41+
42+
expect(span).toEqual(expect.objectContaining({ op: 'custom' }));
43+
});
44+
45+
test('transaction start span passes correct values to the child', async () => {
46+
const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]);
47+
const span = transaction?.startChild({ op: 'custom' });
48+
49+
expect(span).toEqual(expect.objectContaining({
50+
transaction,
51+
parentSpanId: transaction.spanId,
52+
sampled: transaction.sampled,
53+
traceId: transaction.traceId,
54+
}));
55+
});
56+
});

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6561,9 +6561,9 @@ punycode@^2.1.0, punycode@^2.1.1:
65616561
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
65626562

65636563
qs@~6.5.2:
6564-
version "6.5.2"
6565-
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
6566-
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
6564+
version "6.5.3"
6565+
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.3.tgz#3aeeffc91967ef6e35c0e488ef46fb296ab76aad"
6566+
integrity sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==
65676567

65686568
r2@^2.0.1:
65696569
version "2.0.1"

0 commit comments

Comments
 (0)