Socket
Socket
Sign inDemoInstall

@sentry/core

Package Overview
Dependencies
Maintainers
0
Versions
518
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/core - npm Package Compare versions

Comparing version 8.10.0 to 8.11.0

189

cjs/tracing/trace.js

@@ -33,36 +33,43 @@ Object.defineProperty(exports, '__esModule', { value: true });

*/
function startSpan(context, callback) {
function startSpan(options, callback) {
const acs = getAcs();
if (acs.startSpan) {
return acs.startSpan(context, callback);
return acs.startSpan(options, callback);
}
const spanContext = normalizeContext(context);
const spanArguments = parseSentrySpanArguments(options);
const { forceTransaction, parentSpan: customParentSpan } = options;
return currentScopes.withScope(context.scope, scope => {
const parentSpan = getParentSpan(scope);
return currentScopes.withScope(options.scope, () => {
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
const wrapper = getActiveSpanWrapper(customParentSpan);
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new sentryNonRecordingSpan.SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanContext,
forceTransaction: context.forceTransaction,
scope,
});
return wrapper(() => {
const scope = currentScopes.getCurrentScope();
const parentSpan = getParentSpan(scope);
spanOnScope._setSpanForScope(scope, activeSpan);
const shouldSkipSpan = options.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new sentryNonRecordingSpan.SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanArguments,
forceTransaction,
scope,
});
return handleCallbackErrors.handleCallbackErrors(
() => callback(activeSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanUtils.spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: spanstatus.SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
() => activeSpan.end(),
);
spanOnScope._setSpanForScope(scope, activeSpan);
return handleCallbackErrors.handleCallbackErrors(
() => callback(activeSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanUtils.spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: spanstatus.SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
() => activeSpan.end(),
);
});
});

@@ -81,39 +88,46 @@ }

*/
function startSpanManual(context, callback) {
function startSpanManual(options, callback) {
const acs = getAcs();
if (acs.startSpanManual) {
return acs.startSpanManual(context, callback);
return acs.startSpanManual(options, callback);
}
const spanContext = normalizeContext(context);
const spanArguments = parseSentrySpanArguments(options);
const { forceTransaction, parentSpan: customParentSpan } = options;
return currentScopes.withScope(context.scope, scope => {
const parentSpan = getParentSpan(scope);
return currentScopes.withScope(options.scope, () => {
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
const wrapper = getActiveSpanWrapper(customParentSpan);
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new sentryNonRecordingSpan.SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanContext,
forceTransaction: context.forceTransaction,
scope,
});
return wrapper(() => {
const scope = currentScopes.getCurrentScope();
const parentSpan = getParentSpan(scope);
spanOnScope._setSpanForScope(scope, activeSpan);
const shouldSkipSpan = options.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new sentryNonRecordingSpan.SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanArguments,
forceTransaction,
scope,
});
function finishAndSetSpan() {
activeSpan.end();
}
spanOnScope._setSpanForScope(scope, activeSpan);
return handleCallbackErrors.handleCallbackErrors(
() => callback(activeSpan, finishAndSetSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanUtils.spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: spanstatus.SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
);
function finishAndSetSpan() {
activeSpan.end();
}
return handleCallbackErrors.handleCallbackErrors(
() => callback(activeSpan, finishAndSetSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanUtils.spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: spanstatus.SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
);
});
});

@@ -131,24 +145,35 @@ }

*/
function startInactiveSpan(context) {
function startInactiveSpan(options) {
const acs = getAcs();
if (acs.startInactiveSpan) {
return acs.startInactiveSpan(context);
return acs.startInactiveSpan(options);
}
const spanContext = normalizeContext(context);
const spanArguments = parseSentrySpanArguments(options);
const { forceTransaction, parentSpan: customParentSpan } = options;
const scope = context.scope || currentScopes.getCurrentScope();
const parentSpan = getParentSpan(scope);
// If `options.scope` is defined, we use this as as a wrapper,
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
const wrapper = options.scope
? (callback) => currentScopes.withScope(options.scope, callback)
: customParentSpan
? (callback) => withActiveSpan(customParentSpan, callback)
: (callback) => callback();
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
return wrapper(() => {
const scope = currentScopes.getCurrentScope();
const parentSpan = getParentSpan(scope);
if (shouldSkipSpan) {
return new sentryNonRecordingSpan.SentryNonRecordingSpan();
}
const shouldSkipSpan = options.onlyIfParent && !parentSpan;
return createChildOrRootSpan({
parentSpan,
spanContext,
forceTransaction: context.forceTransaction,
scope,
if (shouldSkipSpan) {
return new sentryNonRecordingSpan.SentryNonRecordingSpan();
}
return createChildOrRootSpan({
parentSpan,
spanArguments,
forceTransaction,
scope,
});
});

@@ -242,3 +267,3 @@ }

parentSpan,
spanContext,
spanArguments,
forceTransaction,

@@ -257,3 +282,3 @@ scope,

if (parentSpan && !forceTransaction) {
span = _startChildSpan(parentSpan, scope, spanContext);
span = _startChildSpan(parentSpan, scope, spanArguments);
spanUtils.addChildSpanToSpan(parentSpan, span);

@@ -270,3 +295,3 @@ } else if (parentSpan) {

parentSpanId,
...spanContext,
...spanArguments,
},

@@ -293,3 +318,3 @@ scope,

parentSpanId,
...spanContext,
...spanArguments,
},

@@ -316,15 +341,13 @@ scope,

* but some of them need to be transformed.
*
* Eventually the StartSpanOptions will be more aligned with OpenTelemetry.
*/
function normalizeContext(context) {
const exp = context.experimental || {};
function parseSentrySpanArguments(options) {
const exp = options.experimental || {};
const initialCtx = {
isStandalone: exp.standalone,
...context,
...options,
};
if (context.startTime) {
if (options.startTime) {
const ctx = { ...initialCtx };
ctx.startTimestamp = spanUtils.spanTimeInputToSeconds(context.startTime);
ctx.startTimestamp = spanUtils.spanTimeInputToSeconds(options.startTime);
delete ctx.startTime;

@@ -425,2 +448,10 @@ return ctx;

function getActiveSpanWrapper(parentSpan) {
return parentSpan
? (callback) => {
return withActiveSpan(parentSpan, callback);
}
: (callback) => callback();
}
exports.continueTrace = continueTrace;

@@ -427,0 +458,0 @@ exports.startInactiveSpan = startInactiveSpan;

@@ -31,36 +31,43 @@ import { propagationContextFromHeaders, generatePropagationContext, logger } from '@sentry/utils';

*/
function startSpan(context, callback) {
function startSpan(options, callback) {
const acs = getAcs();
if (acs.startSpan) {
return acs.startSpan(context, callback);
return acs.startSpan(options, callback);
}
const spanContext = normalizeContext(context);
const spanArguments = parseSentrySpanArguments(options);
const { forceTransaction, parentSpan: customParentSpan } = options;
return withScope(context.scope, scope => {
const parentSpan = getParentSpan(scope);
return withScope(options.scope, () => {
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
const wrapper = getActiveSpanWrapper(customParentSpan);
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanContext,
forceTransaction: context.forceTransaction,
scope,
});
return wrapper(() => {
const scope = getCurrentScope();
const parentSpan = getParentSpan(scope);
_setSpanForScope(scope, activeSpan);
const shouldSkipSpan = options.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanArguments,
forceTransaction,
scope,
});
return handleCallbackErrors(
() => callback(activeSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
() => activeSpan.end(),
);
_setSpanForScope(scope, activeSpan);
return handleCallbackErrors(
() => callback(activeSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
() => activeSpan.end(),
);
});
});

@@ -79,39 +86,46 @@ }

*/
function startSpanManual(context, callback) {
function startSpanManual(options, callback) {
const acs = getAcs();
if (acs.startSpanManual) {
return acs.startSpanManual(context, callback);
return acs.startSpanManual(options, callback);
}
const spanContext = normalizeContext(context);
const spanArguments = parseSentrySpanArguments(options);
const { forceTransaction, parentSpan: customParentSpan } = options;
return withScope(context.scope, scope => {
const parentSpan = getParentSpan(scope);
return withScope(options.scope, () => {
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
const wrapper = getActiveSpanWrapper(customParentSpan);
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanContext,
forceTransaction: context.forceTransaction,
scope,
});
return wrapper(() => {
const scope = getCurrentScope();
const parentSpan = getParentSpan(scope);
_setSpanForScope(scope, activeSpan);
const shouldSkipSpan = options.onlyIfParent && !parentSpan;
const activeSpan = shouldSkipSpan
? new SentryNonRecordingSpan()
: createChildOrRootSpan({
parentSpan,
spanArguments,
forceTransaction,
scope,
});
function finishAndSetSpan() {
activeSpan.end();
}
_setSpanForScope(scope, activeSpan);
return handleCallbackErrors(
() => callback(activeSpan, finishAndSetSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
);
function finishAndSetSpan() {
activeSpan.end();
}
return handleCallbackErrors(
() => callback(activeSpan, finishAndSetSpan),
() => {
// Only update the span status if it hasn't been changed yet, and the span is not yet finished
const { status } = spanToJSON(activeSpan);
if (activeSpan.isRecording() && (!status || status === 'ok')) {
activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
}
},
);
});
});

@@ -129,24 +143,35 @@ }

*/
function startInactiveSpan(context) {
function startInactiveSpan(options) {
const acs = getAcs();
if (acs.startInactiveSpan) {
return acs.startInactiveSpan(context);
return acs.startInactiveSpan(options);
}
const spanContext = normalizeContext(context);
const spanArguments = parseSentrySpanArguments(options);
const { forceTransaction, parentSpan: customParentSpan } = options;
const scope = context.scope || getCurrentScope();
const parentSpan = getParentSpan(scope);
// If `options.scope` is defined, we use this as as a wrapper,
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
const wrapper = options.scope
? (callback) => withScope(options.scope, callback)
: customParentSpan
? (callback) => withActiveSpan(customParentSpan, callback)
: (callback) => callback();
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
return wrapper(() => {
const scope = getCurrentScope();
const parentSpan = getParentSpan(scope);
if (shouldSkipSpan) {
return new SentryNonRecordingSpan();
}
const shouldSkipSpan = options.onlyIfParent && !parentSpan;
return createChildOrRootSpan({
parentSpan,
spanContext,
forceTransaction: context.forceTransaction,
scope,
if (shouldSkipSpan) {
return new SentryNonRecordingSpan();
}
return createChildOrRootSpan({
parentSpan,
spanArguments,
forceTransaction,
scope,
});
});

@@ -240,3 +265,3 @@ }

parentSpan,
spanContext,
spanArguments,
forceTransaction,

@@ -255,3 +280,3 @@ scope,

if (parentSpan && !forceTransaction) {
span = _startChildSpan(parentSpan, scope, spanContext);
span = _startChildSpan(parentSpan, scope, spanArguments);
addChildSpanToSpan(parentSpan, span);

@@ -268,3 +293,3 @@ } else if (parentSpan) {

parentSpanId,
...spanContext,
...spanArguments,
},

@@ -291,3 +316,3 @@ scope,

parentSpanId,
...spanContext,
...spanArguments,
},

@@ -314,15 +339,13 @@ scope,

* but some of them need to be transformed.
*
* Eventually the StartSpanOptions will be more aligned with OpenTelemetry.
*/
function normalizeContext(context) {
const exp = context.experimental || {};
function parseSentrySpanArguments(options) {
const exp = options.experimental || {};
const initialCtx = {
isStandalone: exp.standalone,
...context,
...options,
};
if (context.startTime) {
if (options.startTime) {
const ctx = { ...initialCtx };
ctx.startTimestamp = spanTimeInputToSeconds(context.startTime);
ctx.startTimestamp = spanTimeInputToSeconds(options.startTime);
delete ctx.startTime;

@@ -423,3 +446,11 @@ return ctx;

function getActiveSpanWrapper(parentSpan) {
return parentSpan
? (callback) => {
return withActiveSpan(parentSpan, callback);
}
: (callback) => callback();
}
export { continueTrace, startInactiveSpan, startNewTrace, startSpan, startSpanManual, suppressTracing, withActiveSpan };
//# sourceMappingURL=trace.js.map
{
"name": "@sentry/core",
"version": "8.10.0",
"version": "8.11.0",
"description": "Base implementation for all Sentry JavaScript SDKs",

@@ -45,6 +45,6 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"dependencies": {
"@sentry/types": "8.10.0",
"@sentry/utils": "8.10.0"
"@sentry/types": "8.11.0",
"@sentry/utils": "8.11.0"
},
"sideEffects": false
}

@@ -13,3 +13,3 @@ import { Scope, Span, StartSpanOptions } from '@sentry/types';

*/
export declare function startSpan<T>(context: StartSpanOptions, callback: (span: Span) => T): T;
export declare function startSpan<T>(options: StartSpanOptions, callback: (span: Span) => T): T;
/**

@@ -25,3 +25,3 @@ * Similar to `Sentry.startSpan`. Wraps a function with a transaction/span, but does not finish the span

*/
export declare function startSpanManual<T>(context: StartSpanOptions, callback: (span: Span, finish: () => void) => T): T;
export declare function startSpanManual<T>(options: StartSpanOptions, callback: (span: Span, finish: () => void) => T): T;
/**

@@ -36,3 +36,3 @@ * Creates a span. This span is not set as active, so will not get automatic instrumentation spans

*/
export declare function startInactiveSpan(context: StartSpanOptions): Span;
export declare function startInactiveSpan(options: StartSpanOptions): Span;
/**

@@ -39,0 +39,0 @@ * Continue a trace from `sentry-trace` and `baggage` values.

@@ -13,3 +13,3 @@ import type { Scope, Span, StartSpanOptions } from '@sentry/types';

*/
export declare function startSpan<T>(context: StartSpanOptions, callback: (span: Span) => T): T;
export declare function startSpan<T>(options: StartSpanOptions, callback: (span: Span) => T): T;
/**

@@ -25,3 +25,3 @@ * Similar to `Sentry.startSpan`. Wraps a function with a transaction/span, but does not finish the span

*/
export declare function startSpanManual<T>(context: StartSpanOptions, callback: (span: Span, finish: () => void) => T): T;
export declare function startSpanManual<T>(options: StartSpanOptions, callback: (span: Span, finish: () => void) => T): T;
/**

@@ -36,3 +36,3 @@ * Creates a span. This span is not set as active, so will not get automatic instrumentation spans

*/
export declare function startInactiveSpan(context: StartSpanOptions): Span;
export declare function startInactiveSpan(options: StartSpanOptions): Span;
/**

@@ -39,0 +39,0 @@ * Continue a trace from `sentry-trace` and `baggage` values.

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