Skip to content

Commit ba3bc24

Browse files
committed
fix dumb type error and some linting things
1 parent 9147013 commit ba3bc24

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

packages/gatsby/gatsby-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports.onClientEntry = function(_, pluginParams) {
1919

2020
const integrations = [...(pluginParams.integrations || [])];
2121

22-
if (hasTracingEnabled()) {
22+
if (hasTracingEnabled(pluginParams)) {
2323
if (BrowserTracingIntegration) {
2424
integrations.push(new BrowserTracingIntegration());
2525
} else if (TracingIntegration) {

packages/tracing/src/hubextensions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getMainCarrier, Hub } from '@sentry/hub';
22
import { SampleContext, TransactionContext } from '@sentry/types';
3+
import { hasTracingEnabled, logger } from '@sentry/utils';
34

45
import { IdleTransaction } from './idletransaction';
56
import { Transaction } from './transaction';
6-
import { hasTracingEnabled, logger } from '@sentry/utils';
77

88
/** Returns all trace headers that are currently on the top scope. */
99
function traceHeaders(this: Hub): { [key: string]: string } {
@@ -32,17 +32,17 @@ function traceHeaders(this: Hub): { [key: string]: string } {
3232
* Mutates the given Transaction object and then returns the mutated object.
3333
*/
3434
function sample<T extends Transaction>(hub: Hub, transaction: T): T {
35+
const client = hub.getClient();
36+
const options = (client && client.getOptions()) || {};
37+
3538
// nothing to do if tracing is disabled
36-
if (!hasTracingEnabled(hub)) {
39+
if (!hasTracingEnabled(options)) {
3740
transaction.sampled = false;
3841
return transaction;
3942
}
4043

4144
logger.log('Tracing enabled');
4245

43-
const client = hub.getClient();
44-
const options = (client && client.getOptions()) || {};
45-
4646
// we have to test for a pre-existsing sampling decision, in case this transaction is a child transaction and has
4747
// inherited its parent's decision
4848
if (transaction.sampled === undefined) {

packages/types/src/options.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
22
import { Event, EventHint } from './event';
33
import { Integration } from './integration';
44
import { LogLevel } from './loglevel';
5-
import { Transport, TransportClass, TransportOptions } from './transport';
65
import { SampleContext } from './transaction';
6+
import { Transport, TransportClass, TransportOptions } from './transport';
77

88
/** Base configuration options for every SDK. */
99
export interface Options {
@@ -82,16 +82,13 @@ export interface Options {
8282
/**
8383
* Sample rate to determine trace sampling.
8484
*
85-
* 0.0 = 0% chance of instrumenting
86-
* 1.0 = 100% chance of instrumenting
85+
* 0.0 = 0% chance of a given trace being sent (send no traces)
86+
* 1.0 = 100% chance of a given trace being sent (send all traces)
8787
*
88-
* Default: 0.0
88+
* Can be omitted without disabling tracing if `tracesSampler` is defined. If neither is defined, tracing is disabled.
8989
*/
9090
tracesSampleRate?: number;
9191

92-
/** Function to compute tracing sample rate dynamically and filter unwanted traces */
93-
tracesSampler?(traceContext: SampleContext): number | null;
94-
9592
/** Attaches stacktraces to pure capture message / log integrations */
9693
attachStacktrace?: boolean;
9794

@@ -148,4 +145,13 @@ export interface Options {
148145
* @returns The breadcrumb that will be added | null.
149146
*/
150147
beforeBreadcrumb?(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Breadcrumb | null;
148+
149+
/**
150+
* Function to compute tracing sample rate dynamically and filter unwanted traces.
151+
*
152+
* Can be defined in place of `tracesSampleRate`. If neither is defined, tracing is disabled.
153+
*
154+
* @returns A sample rate or `null` to drop the trace.
155+
*/
156+
tracesSampler?(traceContext: SampleContext): number | null;
151157
}

packages/utils/src/misc.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { Event, Hub, Integration, StackFrame, WrappedFunction } from '@sentry/types';
2+
import { Event, Integration, Options, StackFrame, WrappedFunction } from '@sentry/types';
33

44
import { isString } from './is';
55
import { snipLine } from './string';
@@ -516,9 +516,6 @@ export function addContextToFrame(lines: string[], frame: StackFrame, linesOfCon
516516
*
517517
* Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.
518518
*/
519-
export function hasTracingEnabled(hub: Hub): boolean {
520-
const client = hub.getClient();
521-
const options = (client && client.getOptions()) || {};
522-
519+
export function hasTracingEnabled(options: Options): boolean {
523520
return !!options.tracesSampleRate || !!options.tracesSampler;
524521
}

0 commit comments

Comments
 (0)