Skip to content

Commit

Permalink
fix dumb type error and some linting things
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Aug 14, 2020
1 parent 9147013 commit ba3bc24
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports.onClientEntry = function(_, pluginParams) {

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

if (hasTracingEnabled()) {
if (hasTracingEnabled(pluginParams)) {
if (BrowserTracingIntegration) {
integrations.push(new BrowserTracingIntegration());
} else if (TracingIntegration) {
Expand Down
10 changes: 5 additions & 5 deletions packages/tracing/src/hubextensions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getMainCarrier, Hub } from '@sentry/hub';
import { SampleContext, TransactionContext } from '@sentry/types';
import { hasTracingEnabled, logger } from '@sentry/utils';

import { IdleTransaction } from './idletransaction';
import { Transaction } from './transaction';
import { hasTracingEnabled, logger } from '@sentry/utils';

/** Returns all trace headers that are currently on the top scope. */
function traceHeaders(this: Hub): { [key: string]: string } {
Expand Down Expand Up @@ -32,17 +32,17 @@ function traceHeaders(this: Hub): { [key: string]: string } {
* Mutates the given Transaction object and then returns the mutated object.
*/
function sample<T extends Transaction>(hub: Hub, transaction: T): T {
const client = hub.getClient();
const options = (client && client.getOptions()) || {};

// nothing to do if tracing is disabled
if (!hasTracingEnabled(hub)) {
if (!hasTracingEnabled(options)) {
transaction.sampled = false;
return transaction;
}

logger.log('Tracing enabled');

const client = hub.getClient();
const options = (client && client.getOptions()) || {};

// we have to test for a pre-existsing sampling decision, in case this transaction is a child transaction and has
// inherited its parent's decision
if (transaction.sampled === undefined) {
Expand Down
20 changes: 13 additions & 7 deletions packages/types/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
import { Event, EventHint } from './event';
import { Integration } from './integration';
import { LogLevel } from './loglevel';
import { Transport, TransportClass, TransportOptions } from './transport';
import { SampleContext } from './transaction';
import { Transport, TransportClass, TransportOptions } from './transport';

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

/** Function to compute tracing sample rate dynamically and filter unwanted traces */
tracesSampler?(traceContext: SampleContext): number | null;

/** Attaches stacktraces to pure capture message / log integrations */
attachStacktrace?: boolean;

Expand Down Expand Up @@ -148,4 +145,13 @@ export interface Options {
* @returns The breadcrumb that will be added | null.
*/
beforeBreadcrumb?(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Breadcrumb | null;

/**
* Function to compute tracing sample rate dynamically and filter unwanted traces.
*
* Can be defined in place of `tracesSampleRate`. If neither is defined, tracing is disabled.
*
* @returns A sample rate or `null` to drop the trace.
*/
tracesSampler?(traceContext: SampleContext): number | null;
}
7 changes: 2 additions & 5 deletions packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Event, Hub, Integration, StackFrame, WrappedFunction } from '@sentry/types';
import { Event, Integration, Options, StackFrame, WrappedFunction } from '@sentry/types';

import { isString } from './is';
import { snipLine } from './string';
Expand Down Expand Up @@ -516,9 +516,6 @@ export function addContextToFrame(lines: string[], frame: StackFrame, linesOfCon
*
* Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.
*/
export function hasTracingEnabled(hub: Hub): boolean {
const client = hub.getClient();
const options = (client && client.getOptions()) || {};

export function hasTracingEnabled(options: Options): boolean {
return !!options.tracesSampleRate || !!options.tracesSampler;
}

0 comments on commit ba3bc24

Please sign in to comment.