Skip to content

Commit b98bded

Browse files
committed
meld default data into main SampleContext type so it appears in type hints
1 parent 573fe73 commit b98bded

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

packages/minimal/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function _callOnClient(method: string, ...args: any[]): void {
207207
*
208208
* @param context Properties of the new `Transaction`.
209209
* @param customSampleContext Information given to the transaction sampling function (along with context-dependent
210-
* default values)
210+
* default values). See {@link Options.tracesSampler}.
211211
*/
212212
export function startTransaction(context: TransactionContext, customSampleContext?: CustomSampleContext): Transaction {
213213
return callOnHub('startTransaction', { ...context }, customSampleContext);

packages/tracing/src/hubextensions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getActiveDomain, getMainCarrier, Hub } from '@sentry/hub';
2-
import { CustomSampleContext, DefaultSampleContext, SampleContext, TransactionContext } from '@sentry/types';
2+
import { CustomSampleContext, SampleContext, TransactionContext } from '@sentry/types';
33
import {
44
dynamicRequire,
55
extractNodeRequestData,
@@ -100,8 +100,8 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, sampleContext:
100100
*
101101
* @returns The default sample context
102102
*/
103-
function getDefaultSampleContext(): DefaultSampleContext {
104-
const defaultSampleContext: DefaultSampleContext = {};
103+
function getDefaultSampleContext(): SampleContext {
104+
const defaultSampleContext: SampleContext = {};
105105

106106
if (isNodeEnv()) {
107107
const domain = getActiveDomain();

packages/types/src/hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export interface Hub {
199199
*
200200
* @param context Properties of the new `Transaction`.
201201
* @param customSampleContext Information given to the transaction sampling function (along with context-dependent
202-
* default values)
202+
* default values). See {@link Options.tracesSampler}.
203203
*/
204204
startTransaction(context: TransactionContext, customSampleContext?: CustomSampleContext): Transaction;
205205
}

packages/types/src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ export { Span, SpanContext } from './span';
2323
export { StackFrame } from './stackframe';
2424
export { Stacktrace } from './stacktrace';
2525
export { Status } from './status';
26-
export {
27-
CustomSampleContext,
28-
DefaultSampleContext,
29-
SampleContext,
30-
Transaction,
31-
TransactionContext,
32-
} from './transaction';
26+
export { CustomSampleContext, SampleContext, Transaction, TransactionContext } from './transaction';
3327
export { Thread } from './thread';
3428
export { Transport, TransportOptions, TransportClass } from './transport';
3529
export { User } from './user';

packages/types/src/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export interface Options {
126126
* Tracing is enabled if either this or `tracesSampleRate` is defined. If both are defined, `tracesSampleRate` is
127127
* ignored.
128128
*
129-
* Will automatically be passed a context object of default and optional custom data. See {@link Hub.startTransaction}.
129+
* Will automatically be passed a context object of default and optional custom data. See
130+
* {@link Transaction.sampleContext} and {@link Hub.startTransaction}.
130131
*
131132
* @returns A sample rate between 0 and 1 (0 drops the trace, 1 guarantees it will be sent).
132133
*/

packages/types/src/transaction.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ export interface Transaction extends TransactionContext, Span {
5050
setName(name: string): void;
5151
}
5252

53-
/**
54-
* The context passed to the tracesSampler function by default.
55-
*/
56-
export interface DefaultSampleContext {
57-
/** Object representing the URL of the current page or woker script. Passed in a browser or service worker context */
58-
location?: Location | WorkerLocation;
59-
60-
/** Object representing the incoming request to a node server. Passed when in a node server context. */
61-
request?: ExtractedNodeRequestData;
62-
}
63-
6453
/**
6554
* Context data passed by the user when starting a transaction, to be used by the tracesSampler method.
6655
*/
@@ -69,7 +58,19 @@ export interface CustomSampleContext {
6958
}
7059

7160
/**
72-
* The data passed to the `tracesSampler` function, which forms the basis for whatever decisions it might make.
73-
* Combination of default values (which differ per SDK/integration) and data passed to `startTransaction`.
61+
* Data passed to the `tracesSampler` function, which forms the basis for whatever decisions it might make.
62+
*
63+
* Adds default data to data provided by the user. See {@link Hub.startTransaction}
7464
*/
75-
export type SampleContext = DefaultSampleContext & CustomSampleContext;
65+
export interface SampleContext extends CustomSampleContext {
66+
/**
67+
* Object representing the URL of the current page or worker script. Passed by default in a browser or service worker
68+
* context
69+
*/
70+
location?: Location | WorkerLocation;
71+
72+
/**
73+
* Object representing the incoming request to a node server. Passed by default in a node server context.
74+
*/
75+
request?: ExtractedNodeRequestData;
76+
}

0 commit comments

Comments
 (0)