Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sentry-internal/tracing

Package Overview
Dependencies
Maintainers
10
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry-internal/tracing - npm Package Compare versions

Comparing version 7.57.0-beta.0 to 7.57.0

38

cjs/browser/browsertracing.js

@@ -22,3 +22,2 @@ Object.defineProperty(exports, '__esModule', { value: true });

enableLongTask: true,
_experiments: {},
...request.defaultRequestInstrumentationOptions,

@@ -47,5 +46,15 @@ };

constructor(_options) {BrowserTracing.prototype.__init.call(this);
__init2() {this._hasSetTracePropagationTargets = false;}
constructor(_options) {BrowserTracing.prototype.__init.call(this);BrowserTracing.prototype.__init2.call(this);
core.addTracingExtensions();
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__)) {
this._hasSetTracePropagationTargets = !!(
_options &&
// eslint-disable-next-line deprecation/deprecation
(_options.tracePropagationTargets || _options.tracingOrigins)
);
}
this.options = {

@@ -85,2 +94,5 @@ ...DEFAULT_BROWSER_TRACING_OPTIONS,

this._getCurrentHub = getCurrentHub;
const hub = getCurrentHub();
const client = hub.getClient();
const clientOptions = client && client.getOptions();

@@ -94,3 +106,2 @@ const {

traceXHR,
tracePropagationTargets,
shouldCreateSpanForRequest,

@@ -100,2 +111,20 @@ _experiments,

const clientOptionsTracePropagationTargets = clientOptions && clientOptions.tracePropagationTargets;
// There are three ways to configure tracePropagationTargets:
// 1. via top level client option `tracePropagationTargets`
// 2. via BrowserTracing option `tracePropagationTargets`
// 3. via BrowserTracing option `tracingOrigins` (deprecated)
//
// To avoid confusion, favour top level client option `tracePropagationTargets`, and fallback to
// BrowserTracing option `tracePropagationTargets` and then `tracingOrigins` (deprecated).
// This is done as it minimizes bundle size (we don't have to have undefined checks).
//
// If both 1 and either one of 2 or 3 are set (from above), we log out a warning.
const tracePropagationTargets = clientOptionsTracePropagationTargets || this.options.tracePropagationTargets;
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && this._hasSetTracePropagationTargets && clientOptionsTracePropagationTargets) {
utils.logger.warn(
'[Tracing] The `tracePropagationTargets` option was set in the BrowserTracing integration and top level `Sentry.init`. The top level `Sentry.init` value is being used.',
);
}
instrumentRouting(

@@ -127,2 +156,5 @@ (context) => {

shouldCreateSpanForRequest,
_experiments: {
enableHTTPTimings: _experiments.enableHTTPTimings,
},
});

@@ -129,0 +161,0 @@ }

@@ -0,1 +1,5 @@

var {
_optionalChain
} = require('@sentry/utils/cjs/buildPolyfills');
Object.defineProperty(exports, '__esModule', { value: true });

@@ -18,2 +22,3 @@

tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS,
_experiments: {},
};

@@ -24,3 +29,3 @@

// eslint-disable-next-line deprecation/deprecation
const { traceFetch, traceXHR, tracePropagationTargets, tracingOrigins, shouldCreateSpanForRequest } = {
const { traceFetch, traceXHR, tracePropagationTargets, tracingOrigins, shouldCreateSpanForRequest, _experiments } = {
traceFetch: defaultRequestInstrumentationOptions.traceFetch,

@@ -44,3 +49,6 @@ traceXHR: defaultRequestInstrumentationOptions.traceXHR,

utils.addInstrumentationHandler('fetch', (handlerData) => {
fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
const createdSpan = fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
if (_optionalChain([_experiments, 'optionalAccess', _2 => _2.enableHTTPTimings]) && createdSpan) {
addHTTPTimings(createdSpan);
}
});

@@ -51,3 +59,6 @@ }

utils.addInstrumentationHandler('xhr', (handlerData) => {
xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
const createdSpan = xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
if (_optionalChain([_experiments, 'optionalAccess', _3 => _3.enableHTTPTimings]) && createdSpan) {
addHTTPTimings(createdSpan);
}
});

@@ -58,2 +69,44 @@ }

/**
* Creates a temporary observer to listen to the next fetch/xhr resourcing timings,
* so that when timings hit their per-browser limit they don't need to be removed.
*
* @param span A span that has yet to be finished, must contain `url` on data.
*/
function addHTTPTimings(span) {
const url = span.data.url;
const observer = new PerformanceObserver(list => {
const entries = list.getEntries() ;
entries.forEach(entry => {
if ((entry.initiatorType === 'fetch' || entry.initiatorType === 'xmlhttprequest') && entry.name.endsWith(url)) {
const spanData = resourceTimingEntryToSpanData(entry);
spanData.forEach(data => span.setData(...data));
observer.disconnect();
}
});
});
observer.observe({
entryTypes: ['resource'],
});
}
function resourceTimingEntryToSpanData(resourceTiming) {
const version = resourceTiming.nextHopProtocol.split('/')[1] || 'none';
const timingSpanData = [];
if (version) {
timingSpanData.push(['network.protocol.version', version]);
}
if (!utils.browserPerformanceTimeOrigin) {
return timingSpanData;
}
return [
...timingSpanData,
['http.request.connect_start', (utils.browserPerformanceTimeOrigin + resourceTiming.connectStart) / 1000],
['http.request.request_start', (utils.browserPerformanceTimeOrigin + resourceTiming.requestStart) / 1000],
['http.request.response_start', (utils.browserPerformanceTimeOrigin + resourceTiming.responseStart) / 1000],
];
}
/**
* A function that determines whether to attach tracing headers to a request.

@@ -69,2 +122,4 @@ * This was extracted from `instrumentOutgoingRequests` to make it easier to test shouldAttachHeaders.

* Create and track fetch request spans
*
* @returns Span if a span was created, otherwise void.
*/

@@ -111,4 +166,3 @@ function fetchCallback(

const currentScope = core.getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const currentSpan = core.getCurrentHub().getScope().getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

@@ -147,2 +201,3 @@

}
return span;
}

@@ -216,2 +271,4 @@ }

* Create and track xhr request spans
*
* @returns Span if a span was created, otherwise void.
*/

@@ -251,4 +308,3 @@ function xhrCallback(

const currentScope = core.getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const currentSpan = core.getCurrentHub().getScope().getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

@@ -288,2 +344,4 @@

}
return span;
}

@@ -295,6 +353,4 @@ }

exports.defaultRequestInstrumentationOptions = defaultRequestInstrumentationOptions;
exports.fetchCallback = fetchCallback;
exports.instrumentOutgoingRequests = instrumentOutgoingRequests;
exports.shouldAttachHeaders = shouldAttachHeaders;
exports.xhrCallback = xhrCallback;
//# sourceMappingURL=request.js.map

47

cjs/node/integrations/prisma.js

@@ -24,11 +24,25 @@ Object.defineProperty(exports, '__esModule', { value: true });

/**
* Prisma ORM Client Instance
*/
/**
* @inheritDoc
*/
constructor(options = {}) {Prisma.prototype.__init.call(this);
if (isValidPrismaClient(options.client)) {
this._client = options.client;
// We instrument the PrismaClient inside the constructor and not inside `setupOnce` because in some cases of server-side
// bundling (Next.js) multiple Prisma clients can be instantiated, even though users don't intend to. When instrumenting
// in setupOnce we can only ever instrument one client.
// https://github.com/getsentry/sentry-javascript/issues/7216#issuecomment-1602375012
// In the future we might explore providing a dedicated PrismaClient middleware instead of this hack.
if (isValidPrismaClient(options.client) && !options.client._sentryInstrumented) {
utils.addNonEnumerableProperty(options.client , '_sentryInstrumented', true);
options.client.$use((params, next) => {
if (nodeUtils.shouldDisableAutoInstrumentation(core.getCurrentHub)) {
return next(params);
}
const action = params.action;
const model = params.model;
return core.trace(
{ name: model ? `${model} ${action}` : action, op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
() => next(params),
);
});
} else {

@@ -45,21 +59,4 @@ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&

*/
setupOnce(_, getCurrentHub) {
if (!this._client) {
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('PrismaIntegration is missing a Prisma Client Instance');
return;
}
if (nodeUtils.shouldDisableAutoInstrumentation(getCurrentHub)) {
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('Prisma Integration is skipped because of instrumenter configuration.');
return;
}
this._client.$use((params, next) => {
const action = params.action;
const model = params.model;
return core.trace(
{ name: model ? `${model} ${action}` : action, op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
() => next(params),
);
});
setupOnce() {
// Noop - here for backwards compatibility
}

@@ -66,0 +63,0 @@ } Prisma.__initStatic();

@@ -20,3 +20,2 @@ import { TRACING_DEFAULTS, addTracingExtensions, extractTraceparentData, startIdleTransaction, getActiveTransaction } from '@sentry/core';

enableLongTask: true,
_experiments: {},
...defaultRequestInstrumentationOptions,

@@ -45,5 +44,15 @@ };

constructor(_options) {BrowserTracing.prototype.__init.call(this);
__init2() {this._hasSetTracePropagationTargets = false;}
constructor(_options) {BrowserTracing.prototype.__init.call(this);BrowserTracing.prototype.__init2.call(this);
addTracingExtensions();
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__)) {
this._hasSetTracePropagationTargets = !!(
_options &&
// eslint-disable-next-line deprecation/deprecation
(_options.tracePropagationTargets || _options.tracingOrigins)
);
}
this.options = {

@@ -83,2 +92,5 @@ ...DEFAULT_BROWSER_TRACING_OPTIONS,

this._getCurrentHub = getCurrentHub;
const hub = getCurrentHub();
const client = hub.getClient();
const clientOptions = client && client.getOptions();

@@ -92,3 +104,2 @@ const {

traceXHR,
tracePropagationTargets,
shouldCreateSpanForRequest,

@@ -98,2 +109,20 @@ _experiments,

const clientOptionsTracePropagationTargets = clientOptions && clientOptions.tracePropagationTargets;
// There are three ways to configure tracePropagationTargets:
// 1. via top level client option `tracePropagationTargets`
// 2. via BrowserTracing option `tracePropagationTargets`
// 3. via BrowserTracing option `tracingOrigins` (deprecated)
//
// To avoid confusion, favour top level client option `tracePropagationTargets`, and fallback to
// BrowserTracing option `tracePropagationTargets` and then `tracingOrigins` (deprecated).
// This is done as it minimizes bundle size (we don't have to have undefined checks).
//
// If both 1 and either one of 2 or 3 are set (from above), we log out a warning.
const tracePropagationTargets = clientOptionsTracePropagationTargets || this.options.tracePropagationTargets;
if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && this._hasSetTracePropagationTargets && clientOptionsTracePropagationTargets) {
logger.warn(
'[Tracing] The `tracePropagationTargets` option was set in the BrowserTracing integration and top level `Sentry.init`. The top level `Sentry.init` value is being used.',
);
}
instrumentRouting(

@@ -125,2 +154,5 @@ (context) => {

shouldCreateSpanForRequest,
_experiments: {
enableHTTPTimings: _experiments.enableHTTPTimings,
},
});

@@ -127,0 +159,0 @@ }

@@ -0,3 +1,4 @@

import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';
import { hasTracingEnabled, getCurrentHub } from '@sentry/core';
import { addInstrumentationHandler, dynamicSamplingContextToSentryBaggageHeader, isInstanceOf, BAGGAGE_HEADER_NAME, SENTRY_XHR_DATA_KEY, stringMatchesSomePattern } from '@sentry/utils';
import { addInstrumentationHandler, browserPerformanceTimeOrigin, dynamicSamplingContextToSentryBaggageHeader, isInstanceOf, BAGGAGE_HEADER_NAME, SENTRY_XHR_DATA_KEY, stringMatchesSomePattern } from '@sentry/utils';

@@ -16,2 +17,3 @@ /* eslint-disable max-lines */

tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS,
_experiments: {},
};

@@ -22,3 +24,3 @@

// eslint-disable-next-line deprecation/deprecation
const { traceFetch, traceXHR, tracePropagationTargets, tracingOrigins, shouldCreateSpanForRequest } = {
const { traceFetch, traceXHR, tracePropagationTargets, tracingOrigins, shouldCreateSpanForRequest, _experiments } = {
traceFetch: defaultRequestInstrumentationOptions.traceFetch,

@@ -42,3 +44,6 @@ traceXHR: defaultRequestInstrumentationOptions.traceXHR,

addInstrumentationHandler('fetch', (handlerData) => {
fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
const createdSpan = fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
if (_optionalChain([_experiments, 'optionalAccess', _2 => _2.enableHTTPTimings]) && createdSpan) {
addHTTPTimings(createdSpan);
}
});

@@ -49,3 +54,6 @@ }

addInstrumentationHandler('xhr', (handlerData) => {
xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
const createdSpan = xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
if (_optionalChain([_experiments, 'optionalAccess', _3 => _3.enableHTTPTimings]) && createdSpan) {
addHTTPTimings(createdSpan);
}
});

@@ -56,2 +64,44 @@ }

/**
* Creates a temporary observer to listen to the next fetch/xhr resourcing timings,
* so that when timings hit their per-browser limit they don't need to be removed.
*
* @param span A span that has yet to be finished, must contain `url` on data.
*/
function addHTTPTimings(span) {
const url = span.data.url;
const observer = new PerformanceObserver(list => {
const entries = list.getEntries() ;
entries.forEach(entry => {
if ((entry.initiatorType === 'fetch' || entry.initiatorType === 'xmlhttprequest') && entry.name.endsWith(url)) {
const spanData = resourceTimingEntryToSpanData(entry);
spanData.forEach(data => span.setData(...data));
observer.disconnect();
}
});
});
observer.observe({
entryTypes: ['resource'],
});
}
function resourceTimingEntryToSpanData(resourceTiming) {
const version = resourceTiming.nextHopProtocol.split('/')[1] || 'none';
const timingSpanData = [];
if (version) {
timingSpanData.push(['network.protocol.version', version]);
}
if (!browserPerformanceTimeOrigin) {
return timingSpanData;
}
return [
...timingSpanData,
['http.request.connect_start', (browserPerformanceTimeOrigin + resourceTiming.connectStart) / 1000],
['http.request.request_start', (browserPerformanceTimeOrigin + resourceTiming.requestStart) / 1000],
['http.request.response_start', (browserPerformanceTimeOrigin + resourceTiming.responseStart) / 1000],
];
}
/**
* A function that determines whether to attach tracing headers to a request.

@@ -67,2 +117,4 @@ * This was extracted from `instrumentOutgoingRequests` to make it easier to test shouldAttachHeaders.

* Create and track fetch request spans
*
* @returns Span if a span was created, otherwise void.
*/

@@ -109,4 +161,3 @@ function fetchCallback(

const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const currentSpan = getCurrentHub().getScope().getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

@@ -145,2 +196,3 @@

}
return span;
}

@@ -214,2 +266,4 @@ }

* Create and track xhr request spans
*
* @returns Span if a span was created, otherwise void.
*/

@@ -249,4 +303,3 @@ function xhrCallback(

const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const currentSpan = getCurrentHub().getScope().getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

@@ -286,6 +339,8 @@

}
return span;
}
}
export { DEFAULT_TRACE_PROPAGATION_TARGETS, addTracingHeadersToFetchRequest, defaultRequestInstrumentationOptions, fetchCallback, instrumentOutgoingRequests, shouldAttachHeaders, xhrCallback };
export { DEFAULT_TRACE_PROPAGATION_TARGETS, addTracingHeadersToFetchRequest, defaultRequestInstrumentationOptions, instrumentOutgoingRequests, shouldAttachHeaders };
//# sourceMappingURL=request.js.map

@@ -1,3 +0,3 @@

import { trace } from '@sentry/core';
import { logger } from '@sentry/utils';
import { trace, getCurrentHub } from '@sentry/core';
import { addNonEnumerableProperty, logger } from '@sentry/utils';
import { shouldDisableAutoInstrumentation } from './utils/node-utils.js';

@@ -22,11 +22,25 @@

/**
* Prisma ORM Client Instance
*/
/**
* @inheritDoc
*/
constructor(options = {}) {Prisma.prototype.__init.call(this);
if (isValidPrismaClient(options.client)) {
this._client = options.client;
// We instrument the PrismaClient inside the constructor and not inside `setupOnce` because in some cases of server-side
// bundling (Next.js) multiple Prisma clients can be instantiated, even though users don't intend to. When instrumenting
// in setupOnce we can only ever instrument one client.
// https://github.com/getsentry/sentry-javascript/issues/7216#issuecomment-1602375012
// In the future we might explore providing a dedicated PrismaClient middleware instead of this hack.
if (isValidPrismaClient(options.client) && !options.client._sentryInstrumented) {
addNonEnumerableProperty(options.client , '_sentryInstrumented', true);
options.client.$use((params, next) => {
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
return next(params);
}
const action = params.action;
const model = params.model;
return trace(
{ name: model ? `${model} ${action}` : action, op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
() => next(params),
);
});
} else {

@@ -43,21 +57,4 @@ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&

*/
setupOnce(_, getCurrentHub) {
if (!this._client) {
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('PrismaIntegration is missing a Prisma Client Instance');
return;
}
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('Prisma Integration is skipped because of instrumenter configuration.');
return;
}
this._client.$use((params, next) => {
const action = params.action;
const model = params.model;
return trace(
{ name: model ? `${model} ${action}` : action, op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
() => next(params),
);
});
setupOnce() {
// Noop - here for backwards compatibility
}

@@ -64,0 +61,0 @@ } Prisma.__initStatic();

{
"name": "@sentry-internal/tracing",
"version": "7.57.0-beta.0",
"version": "7.57.0",
"description": "Sentry Internal Tracing Package",

@@ -26,5 +26,5 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"dependencies": {
"@sentry/core": "7.57.0-beta.0",
"@sentry/types": "7.57.0-beta.0",
"@sentry/utils": "7.57.0-beta.0",
"@sentry/core": "7.57.0",
"@sentry/types": "7.57.0",
"@sentry/utils": "7.57.0",
"tslib": "^2.4.1 || ^1.9.3"

@@ -31,0 +31,0 @@ },

@@ -84,2 +84,3 @@ import type { Hub } from '@sentry/core';

enableInteractions: boolean;
enableHTTPTimings: boolean;
onStartRouteTransaction: (t: Transaction | undefined, ctx: TransactionContext, getCurrentHub: () => Hub) => void;

@@ -122,2 +123,3 @@ }>;

private _collectWebVitals;
private _hasSetTracePropagationTargets;
constructor(_options?: Partial<BrowserTracingOptions>);

@@ -124,0 +126,0 @@ /**

@@ -7,2 +7,8 @@ import type { DynamicSamplingContext, Span } from '@sentry/types';

/**
* Allow experiments for the request instrumentation.
*/
_experiments: Partial<{
enableHTTPTimings: boolean;
}>;
/**
* @deprecated Will be removed in v8.

@@ -85,6 +91,2 @@ * Use `shouldCreateSpanForRequest` to control span creation and `tracePropagationTargets` to control

/**
* Create and track fetch request spans
*/
export declare function fetchCallback(handlerData: FetchData, shouldCreateSpan: (url: string) => boolean, shouldAttachHeaders: (url: string) => boolean, spans: Record<string, Span>): void;
/**
* Adds sentry-trace and baggage headers to the various forms of fetch headers

@@ -98,7 +100,3 @@ */

}): PolymorphicRequestHeaders;
/**
* Create and track xhr request spans
*/
export declare function xhrCallback(handlerData: XHRData, shouldCreateSpan: (url: string) => boolean, shouldAttachHeaders: (url: string) => boolean, spans: Record<string, Span>): void;
export {};
//# sourceMappingURL=request.d.ts.map

@@ -1,3 +0,2 @@

import type { Hub } from '@sentry/core';
import type { EventProcessor, Integration } from '@sentry/types';
import type { Integration } from '@sentry/types';
/** Tracing integration for @prisma/client package */

@@ -14,6 +13,2 @@ export declare class Prisma implements Integration {

/**
* Prisma ORM Client Instance
*/
private readonly _client?;
/**
* @inheritDoc

@@ -27,4 +22,4 @@ */

*/
setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void;
setupOnce(): void;
}
//# sourceMappingURL=prisma.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc