Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use native OpenTelemetry Spans in node-experimental #9085

Closed
wants to merge 10 commits into from
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ jobs:
- name: Pack
run: yarn build:tarball
- name: Archive artifacts
uses: actions/upload-artifact@v3.1.2
uses: actions/upload-artifact@v3.1.3
with:
name: ${{ github.sha }}
path: |
Expand Down Expand Up @@ -823,6 +823,7 @@ jobs:
'standard-frontend-react-tracing-import',
'sveltekit',
'generic-ts3.8',
'node-experimental-fastify-app',
]
build-command:
- false
Expand Down Expand Up @@ -951,7 +952,7 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}

- name: Upload results
uses: actions/upload-artifact@v3.1.2
uses: actions/upload-artifact@v3.1.3
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
with:
name: ${{ steps.process.outputs.artifactName }}
Expand Down
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 7.73.0

### Important Changes

- **feat(replay): Upgrade to rrweb2**
Expand All @@ -23,7 +27,20 @@ Here are benchmarks comparing the version 1 of rrweb to version 2
| netTx | 282.67 KB | 272.51 KB |
| netRx | 8.02 MB | 8.07 MB |

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
### Other Changes

- feat: Always assemble Envelopes (#9101)
- feat(node): Rate limit local variables for caught exceptions and enable `captureAllExceptions` by default (#9102)
- fix(core): Ensure `tunnel` is considered for `isSentryUrl` checks (#9130)
- fix(nextjs): Fix `RequestAsyncStorage` fallback path (#9126)
- fix(node-otel): Suppress tracing for generated sentry spans (#9142)
- fix(node): fill in span data from http request options object (#9112)
- fix(node): Fixes and improvements to ANR detection (#9128)
- fix(sveltekit): Avoid data invalidation in wrapped client-side `load` functions (#9071)
- ref(core): Refactor `InboundFilters` integration to use `processEvent` (#9020)
- ref(wasm): Refactor Wasm integration to use `processEvent` (#9019)

Work in this release contributed by @vlad-zhukov. Thank you for your contribution!

## 7.72.0

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "7.72.0",
"version": "7.73.0",
"npmClient": "yarn"
}
8 changes: 4 additions & 4 deletions packages/angular-ivy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/angular-ivy",
"version": "7.72.0",
"version": "7.73.0",
"description": "Official Sentry SDK for Angular with full Ivy Support",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/angular-ivy",
Expand All @@ -21,9 +21,9 @@
"rxjs": "^6.5.5 || ^7.x"
},
"dependencies": {
"@sentry/browser": "7.72.0",
"@sentry/types": "7.72.0",
"@sentry/utils": "7.72.0",
"@sentry/browser": "7.73.0",
"@sentry/types": "7.73.0",
"@sentry/utils": "7.73.0",
"tslib": "^2.4.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/angular",
"version": "7.72.0",
"version": "7.73.0",
"description": "Official Sentry SDK for Angular",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/angular",
Expand All @@ -21,9 +21,9 @@
"rxjs": "^6.5.5 || ^7.x"
},
"dependencies": {
"@sentry/browser": "7.72.0",
"@sentry/types": "7.72.0",
"@sentry/utils": "7.72.0",
"@sentry/browser": "7.73.0",
"@sentry/types": "7.73.0",
"@sentry/utils": "7.73.0",
"tslib": "^2.4.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry-internal/browser-integration-tests",
"version": "7.72.0",
"version": "7.73.0",
"main": "index.js",
"license": "MIT",
"engines": {
Expand Down
14 changes: 7 additions & 7 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/browser",
"version": "7.72.0",
"version": "7.73.0",
"description": "Official Sentry SDK for browsers",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/browser",
Expand All @@ -23,15 +23,15 @@
"access": "public"
},
"dependencies": {
"@sentry-internal/tracing": "7.72.0",
"@sentry/core": "7.72.0",
"@sentry/replay": "7.72.0",
"@sentry/types": "7.72.0",
"@sentry/utils": "7.72.0",
"@sentry-internal/tracing": "7.73.0",
"@sentry/core": "7.73.0",
"@sentry/replay": "7.73.0",
"@sentry/types": "7.73.0",
"@sentry/utils": "7.73.0",
"tslib": "^2.4.1 || ^1.9.3"
},
"devDependencies": {
"@sentry-internal/integration-shims": "7.72.0",
"@sentry-internal/integration-shims": "7.73.0",
"@types/md5": "2.1.33",
"btoa": "^1.2.1",
"chai": "^4.1.2",
Expand Down
10 changes: 5 additions & 5 deletions packages/bun/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/bun",
"version": "7.72.0",
"version": "7.73.0",
"description": "Official Sentry SDK for bun",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/bun",
Expand All @@ -23,10 +23,10 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "7.72.0",
"@sentry/node": "7.72.0",
"@sentry/types": "7.72.0",
"@sentry/utils": "7.72.0"
"@sentry/core": "7.73.0",
"@sentry/node": "7.73.0",
"@sentry/types": "7.73.0",
"@sentry/utils": "7.73.0"
},
"devDependencies": {
"bun-types": "latest"
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/core",
"version": "7.72.0",
"version": "7.73.0",
"description": "Base implementation for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/core",
Expand All @@ -23,8 +23,8 @@
"access": "public"
},
"dependencies": {
"@sentry/types": "7.72.0",
"@sentry/utils": "7.72.0",
"@sentry/types": "7.73.0",
"@sentry/utils": "7.73.0",
"tslib": "^2.4.1 || ^1.9.3"
},
"scripts": {
Expand Down
130 changes: 5 additions & 125 deletions packages/core/src/tracing/hubextensions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ClientOptions, CustomSamplingContext, Options, SamplingContext, TransactionContext } from '@sentry/types';
import { isNaN, logger } from '@sentry/utils';
import type { ClientOptions, CustomSamplingContext, TransactionContext } from '@sentry/types';
import { logger } from '@sentry/utils';

import type { Hub } from '../hub';
import { getMainCarrier } from '../hub';
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
import { registerErrorInstrumentation } from './errors';
import { IdleTransaction } from './idletransaction';
import { sampleTransaction } from './sampling';
import { Transaction } from './transaction';

/** Returns all trace headers that are currently on the top scope. */
Expand All @@ -20,126 +20,6 @@ function traceHeaders(this: Hub): { [key: string]: string } {
: {};
}

/**
* Makes a sampling decision for the given transaction and stores it on the transaction.
*
* Called every time a transaction is created. Only transactions which emerge with a `sampled` value of `true` will be
* sent to Sentry.
*
* @param transaction: The transaction needing a sampling decision
* @param options: The current client's options, so we can access `tracesSampleRate` and/or `tracesSampler`
* @param samplingContext: Default and user-provided data which may be used to help make the decision
*
* @returns The given transaction with its `sampled` value set
*/
function sample<T extends Transaction>(
transaction: T,
options: Pick<Options, 'tracesSampleRate' | 'tracesSampler' | 'enableTracing'>,
samplingContext: SamplingContext,
): T {
// nothing to do if tracing is not enabled
if (!hasTracingEnabled(options)) {
transaction.sampled = false;
return transaction;
}

// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
if (transaction.sampled !== undefined) {
transaction.setMetadata({
sampleRate: Number(transaction.sampled),
});
return transaction;
}

// we would have bailed already if neither `tracesSampler` nor `tracesSampleRate` nor `enableTracing` were defined, so one of these should
// work; prefer the hook if so
let sampleRate;
if (typeof options.tracesSampler === 'function') {
sampleRate = options.tracesSampler(samplingContext);
transaction.setMetadata({
sampleRate: Number(sampleRate),
});
} else if (samplingContext.parentSampled !== undefined) {
sampleRate = samplingContext.parentSampled;
} else if (typeof options.tracesSampleRate !== 'undefined') {
sampleRate = options.tracesSampleRate;
transaction.setMetadata({
sampleRate: Number(sampleRate),
});
} else {
// When `enableTracing === true`, we use a sample rate of 100%
sampleRate = 1;
transaction.setMetadata({
sampleRate,
});
}

// Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
// only valid values are booleans or numbers between 0 and 1.)
if (!isValidSampleRate(sampleRate)) {
__DEBUG_BUILD__ && logger.warn('[Tracing] Discarding transaction because of invalid sample rate.');
transaction.sampled = false;
return transaction;
}

// if the function returned 0 (or false), or if `tracesSampleRate` is 0, it's a sign the transaction should be dropped
if (!sampleRate) {
__DEBUG_BUILD__ &&
logger.log(
`[Tracing] Discarding transaction because ${
typeof options.tracesSampler === 'function'
? 'tracesSampler returned 0 or false'
: 'a negative sampling decision was inherited or tracesSampleRate is set to 0'
}`,
);
transaction.sampled = false;
return transaction;
}

// Now we roll the dice. Math.random is inclusive of 0, but not of 1, so strict < is safe here. In case sampleRate is
// a boolean, the < comparison will cause it to be automatically cast to 1 if it's true and 0 if it's false.
transaction.sampled = Math.random() < (sampleRate as number | boolean);

// if we're not going to keep it, we're done
if (!transaction.sampled) {
__DEBUG_BUILD__ &&
logger.log(
`[Tracing] Discarding transaction because it's not included in the random sample (sampling rate = ${Number(
sampleRate,
)})`,
);
return transaction;
}

__DEBUG_BUILD__ && logger.log(`[Tracing] starting ${transaction.op} transaction - ${transaction.name}`);
return transaction;
}

/**
* Checks the given sample rate to make sure it is valid type and value (a boolean, or a number between 0 and 1).
*/
function isValidSampleRate(rate: unknown): boolean {
// we need to check NaN explicitly because it's of type 'number' and therefore wouldn't get caught by this typecheck
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (isNaN(rate) || !(typeof rate === 'number' || typeof rate === 'boolean')) {
__DEBUG_BUILD__ &&
logger.warn(
`[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(
rate,
)} of type ${JSON.stringify(typeof rate)}.`,
);
return false;
}

// in case sampleRate is a boolean, it will get automatically cast to 1 if it's true and 0 if it's false
if (rate < 0 || rate > 1) {
__DEBUG_BUILD__ &&
logger.warn(`[Tracing] Given sample rate is invalid. Sample rate must be between 0 and 1. Got ${rate}.`);
return false;
}
return true;
}

/**
* Creates a new transaction and adds a sampling decision if it doesn't yet have one.
*
Expand Down Expand Up @@ -177,7 +57,7 @@ The transaction will not be sampled. Please use the ${configInstrumenter} instru
}

let transaction = new Transaction(transactionContext, this);
transaction = sample(transaction, options, {
transaction = sampleTransaction(transaction, options, {
parentSampled: transactionContext.parentSampled,
transactionContext,
...customSamplingContext,
Expand Down Expand Up @@ -207,7 +87,7 @@ export function startIdleTransaction(
const options: Partial<ClientOptions> = (client && client.getOptions()) || {};

let transaction = new IdleTransaction(transactionContext, hub, idleTimeout, finalTimeout, heartbeatInterval, onScope);
transaction = sample(transaction, options, {
transaction = sampleTransaction(transaction, options, {
parentSampled: transactionContext.parentSampled,
transactionContext,
...customSamplingContext,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export type { SpanStatusType } from './span';
export { trace, getActiveSpan, startSpan, startInactiveSpan, startActiveSpan, startSpanManual } from './trace';
export { getDynamicSamplingContextFromClient } from './dynamicSamplingContext';
export { setMeasurement } from './measurement';
export { sampleTransaction } from './sampling';
Loading