Skip to content

Commit

Permalink
ref: Use startTransaction where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
rhcarvalho committed Jun 5, 2020
1 parent 62cbc1e commit 9eb304b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/apm/src/integrations/tracing.ts
Expand Up @@ -431,7 +431,7 @@ export class Tracing implements Integration {
return undefined;
}

Tracing._activeTransaction = hub.startSpan({
Tracing._activeTransaction = hub.startTransaction({
trimEnd: true,
...transactionContext,
}) as Transaction;
Expand Down
18 changes: 6 additions & 12 deletions packages/apm/test/hub.test.ts
@@ -1,6 +1,5 @@
import { BrowserClient } from '@sentry/browser';
import { Hub, Scope } from '@sentry/hub';
import { Span, Transaction } from '@sentry/types';

import { addExtensionMethods } from '../src/hubextensions';

Expand All @@ -21,21 +20,18 @@ describe('Hub', () => {
});
test('set tracesSampleRate 0 on transaction', () => {
const hub = new Hub(new BrowserClient({ tracesSampleRate: 0 }));
// @ts-ignore
const transaction = hub.startSpan({ name: 'foo' }) as any;
const transaction = hub.startTransaction({ name: 'foo' });
expect(transaction.sampled).toBe(false);
});
test('set tracesSampleRate 1 on transaction', () => {
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
// @ts-ignore
const transaction = hub.startSpan({ name: 'foo' }) as any;
const transaction = hub.startTransaction({ name: 'foo' });
expect(transaction.sampled).toBeTruthy();
});
test('set tracesSampleRate should be propergated to children', () => {
const hub = new Hub(new BrowserClient({ tracesSampleRate: 0 }));
// @ts-ignore
const transaction = hub.startSpan({ name: 'foo' }) as any;
const child = transaction.startChild({ op: 1 });
const transaction = hub.startTransaction({ name: 'foo' });
const child = transaction.startChild({ op: 'test' });
expect(child.sampled).toBeFalsy();
});
});
Expand All @@ -49,8 +45,7 @@ describe('Hub', () => {

test('simple standalone Transaction', () => {
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
// @ts-ignore
const transaction = hub.startSpan({ name: 'transaction' }) as Transaction;
const transaction = hub.startTransaction({ name: 'transaction' });
expect(transaction.spanId).toBeTruthy();
// tslint:disable-next-line: no-unbound-method
expect(transaction.setName).toBeTruthy();
Expand All @@ -71,8 +66,7 @@ describe('Hub', () => {
test('create a child if there is a Span already on the scope', () => {
const myScope = new Scope();
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }), myScope);
// @ts-ignore
const transaction = hub.startSpan({ name: 'transaction' }) as Transaction;
const transaction = hub.startTransaction({ name: 'transaction' });
hub.configureScope(scope => {
scope.setSpan(transaction);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/node/test/manual/apm-transaction/main.js
Expand Up @@ -24,8 +24,8 @@ class Tracing {
? Span.fromTraceparent(req.headers['sentry-trace'], {
transaction,
})
: Sentry.getCurrentHub().startSpan({
transaction,
: Sentry.startTransaction({
name: transaction,
});

Sentry.getCurrentHub().configureScope(scope => {
Expand Down

0 comments on commit 9eb304b

Please sign in to comment.