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

@sentry/tracing

Package Overview
Dependencies
Maintainers
12
Versions
317
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/tracing - npm Package Compare versions

Comparing version 6.3.0-beta.0 to 6.3.0-beta.1

6

dist/browser/browsertracing.d.ts

@@ -90,9 +90,9 @@ import { Hub } from '@sentry/hub';

/**
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
* Gets transaction context from a sentry-trace meta.
*
* @returns Transaction context data or undefined neither tag exists or has valid data
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
*/
export declare function extractTraceDataFromMetaTags(): Partial<TransactionContext> | undefined;
export declare function getHeaderContext(): Partial<TransactionContext> | undefined;
/** Returns the value of a meta tag */
export declare function getMetaContent(metaName: string): string | null;
//# sourceMappingURL=browsertracing.d.ts.map

@@ -69,3 +69,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var _a = this.options, beforeNavigate = _a.beforeNavigate, idleTimeout = _a.idleTimeout, maxTransactionDuration = _a.maxTransactionDuration;
var parentContextFromHeader = context.op === 'pageload' ? extractTraceDataFromMetaTags() : undefined;
var parentContextFromHeader = context.op === 'pageload' ? getHeaderContext() : undefined;
var expandedContext = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, context), parentContextFromHeader), { trimEnd: true });

@@ -97,18 +97,14 @@ var modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext;

/**
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
* Gets transaction context from a sentry-trace meta.
*
* @returns Transaction context data or undefined neither tag exists or has valid data
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
*/
function extractTraceDataFromMetaTags() {
var _a, _b;
var sentrytraceValue = getMetaContent('sentry-trace');
var tracestateValue = getMetaContent('tracestate');
var sentrytraceData = sentrytraceValue ? utils_2.extractSentrytraceData(sentrytraceValue) : undefined;
var tracestateData = tracestateValue ? utils_2.extractTracestateData(tracestateValue) : undefined;
if (sentrytraceData || ((_a = tracestateData) === null || _a === void 0 ? void 0 : _a.sentry) || ((_b = tracestateData) === null || _b === void 0 ? void 0 : _b.thirdparty)) {
return tslib_1.__assign(tslib_1.__assign({}, sentrytraceData), (tracestateData && { metadata: { tracestate: tracestateData } }));
function getHeaderContext() {
var header = getMetaContent('sentry-trace');
if (header) {
return utils_2.extractTraceparentData(header);
}
return undefined;
}
exports.extractTraceDataFromMetaTags = extractTraceDataFromMetaTags;
exports.getHeaderContext = getHeaderContext;
/** Returns the value of a meta tag */

@@ -115,0 +111,0 @@ function getMetaContent(metaName) {

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

import { Span } from '@sentry/types';
import { Span } from '../span';
export declare const DEFAULT_TRACING_ORIGINS: (string | RegExp)[];

@@ -3,0 +3,0 @@ /** Options for Request Instrumentation */

@@ -102,13 +102,13 @@ Object.defineProperty(exports, "__esModule", { value: true });

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
headers.append(Object.entries(span.getTraceHeaders()));
headers.append('sentry-trace', span.toTraceparent());
}
else if (Array.isArray(headers)) {
headers = tslib_1.__spread(headers, Object.entries(span.getTraceHeaders()));
headers = tslib_1.__spread(headers, [['sentry-trace', span.toTraceparent()]]);
}
else {
headers = tslib_1.__assign(tslib_1.__assign({}, headers), span.getTraceHeaders());
headers = tslib_1.__assign(tslib_1.__assign({}, headers), { 'sentry-trace': span.toTraceparent() });
}
}
else {
headers = span.getTraceHeaders();
headers = { 'sentry-trace': span.toTraceparent() };
}

@@ -155,7 +155,3 @@ options.headers = headers;

try {
var sentryHeaders = span.getTraceHeaders();
handlerData.xhr.setRequestHeader('sentry-trace', sentryHeaders['sentry-trace']);
if (sentryHeaders.tracestate) {
handlerData.xhr.setRequestHeader('tracestate', sentryHeaders.tracestate);
}
handlerData.xhr.setRequestHeader('sentry-trace', span.toTraceparent());
}

@@ -162,0 +158,0 @@ catch (_) {

@@ -10,2 +10,15 @@ Object.defineProperty(exports, "__esModule", { value: true });

var utils_2 = require("./utils");
/** Returns all trace headers that are currently on the top scope. */
function traceHeaders() {
var scope = this.getScope();
if (scope) {
var span = scope.getSpan();
if (span) {
return {
'sentry-trace': span.toTraceparent(),
};
}
}
return {};
}
/**

@@ -157,2 +170,5 @@ * Makes a sampling decision for the given transaction and stores it on the transaction.

}
if (!carrier.__SENTRY__.extensions.traceHeaders) {
carrier.__SENTRY__.extensions.traceHeaders = traceHeaders;
}
}

@@ -159,0 +175,0 @@ }

@@ -19,3 +19,3 @@ import { BrowserTracing } from './browser';

export { addExtensionMethods };
export { extractSentrytraceData, extractTracestateData, getActiveTransaction, hasTracingEnabled, SENTRY_TRACE_REGEX, stripUrlQueryAndFragment, } from './utils';
export { extractTraceparentData, getActiveTransaction, hasTracingEnabled, stripUrlQueryAndFragment, TRACEPARENT_REGEXP, } from './utils';
//# sourceMappingURL=index.d.ts.map

@@ -25,8 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

var utils_1 = require("./utils");
exports.extractSentrytraceData = utils_1.extractSentrytraceData;
exports.extractTracestateData = utils_1.extractTracestateData;
exports.extractTraceparentData = utils_1.extractTraceparentData;
exports.getActiveTransaction = utils_1.getActiveTransaction;
exports.hasTracingEnabled = utils_1.hasTracingEnabled;
exports.SENTRY_TRACE_REGEX = utils_1.SENTRY_TRACE_REGEX;
exports.stripUrlQueryAndFragment = utils_1.stripUrlQueryAndFragment;
exports.TRACEPARENT_REGEXP = utils_1.TRACEPARENT_REGEXP;
//# sourceMappingURL=index.js.map

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

import { Hub, Primitive, Span as SpanInterface, SpanContext, TraceHeaders, Transaction } from '@sentry/types';
import { Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
import { SpanStatus } from './spanstatus';

@@ -137,6 +137,2 @@ /**

*/
getTraceHeaders(): TraceHeaders;
/**
* @inheritDoc
*/
getTraceContext(): {

@@ -175,17 +171,3 @@ data?: {

};
/**
* Create a new Sentry tracestate header entry (i.e. `sentry=xxxxxx`)
*
* @returns The new Sentry tracestate entry, or undefined if there's no client or no dsn
*/
protected _getNewTracestate(hub?: Hub): string | undefined;
/**
* Return a traceparent-compatible header string.
*/
private _toSentrytrace;
/**
* Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN.
*/
private _toTracestate;
}
//# sourceMappingURL=span.d.ts.map
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/* eslint-disable max-lines */
var hub_1 = require("@sentry/hub");
var utils_1 = require("@sentry/utils");
var spanstatus_1 = require("./spanstatus");
var utils_2 = require("./utils");
/**

@@ -178,4 +175,7 @@ * Keeps track of finished spans for a given transaction

Span.prototype.toTraceparent = function () {
utils_1.logger.warn('Direct use of `span.toTraceparent` is deprecated. Use `span.getTraceHeaders` instead.');
return this._toSentrytrace();
var sampledString = '';
if (this.sampled !== undefined) {
sampledString = this.sampled ? '-1' : '-0';
}
return this.traceId + "-" + this.spanId + sampledString;
};

@@ -221,9 +221,2 @@ /**

*/
Span.prototype.getTraceHeaders = function () {
var tracestate = this._toTracestate();
return tslib_1.__assign({ 'sentry-trace': this._toSentrytrace() }, (tracestate && { tracestate: tracestate }));
};
/**
* @inheritDoc
*/
Span.prototype.getTraceContext = function () {

@@ -258,49 +251,2 @@ return utils_1.dropUndefinedKeys({

};
/**
* Create a new Sentry tracestate header entry (i.e. `sentry=xxxxxx`)
*
* @returns The new Sentry tracestate entry, or undefined if there's no client or no dsn
*/
Span.prototype._getNewTracestate = function (hub) {
if (hub === void 0) { hub = hub_1.getCurrentHub(); }
var _a;
var client = hub.getClient();
var dsn = (_a = client) === null || _a === void 0 ? void 0 : _a.getDsn();
if (!client || !dsn) {
return;
}
var _b = client.getOptions() || {}, environment = _b.environment, release = _b.release;
// TODO - the only reason we need the non-null assertion on `dsn.publicKey` (below) is because `dsn.publicKey` has
// to be optional while we transition from `dsn.user` -> `dsn.publicKey`. Once `dsn.user` is removed, we can make
// `dsn.publicKey` required and remove the `!`.
return "sentry=" + utils_2.computeTracestateValue({
traceId: this.traceId,
environment: environment,
release: release,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
publicKey: dsn.publicKey,
});
};
/**
* Return a traceparent-compatible header string.
*/
Span.prototype._toSentrytrace = function () {
var sampledString = '';
if (this.sampled !== undefined) {
sampledString = this.sampled ? '-1' : '-0';
}
return this.traceId + "-" + this.spanId + sampledString;
};
/**
* Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN.
*/
Span.prototype._toTracestate = function () {
var _a, _b, _c, _d, _e, _f;
var sentryTracestate = ((_c = (_b = (_a = this.transaction) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.tracestate) === null || _c === void 0 ? void 0 : _c.sentry) || this._getNewTracestate();
var thirdpartyTracestate = (_f = (_e = (_d = this.transaction) === null || _d === void 0 ? void 0 : _d.metadata) === null || _e === void 0 ? void 0 : _e.tracestate) === null || _f === void 0 ? void 0 : _f.thirdparty;
// if there's third-party data, add a leading comma; otherwise, convert from `undefined` to the empty string, so the
// end result doesn’t come out as `sentry=xxxxxundefined`
thirdpartyTracestate = thirdpartyTracestate ? "," + thirdpartyTracestate : '';
return "" + sentryTracestate + thirdpartyTracestate;
};
return Span;

@@ -307,0 +253,0 @@ }());

import { Hub } from '@sentry/hub';
import { Measurements, Transaction as TransactionInterface, TransactionContext, TransactionMetadata } from '@sentry/types';
import { Measurements, Transaction as TransactionInterface, TransactionContext } from '@sentry/types';
import { Span as SpanClass } from './span';
interface TransactionMetadata {
transactionSampling?: {
[key: string]: string | number;
};
}
/** JSDoc */
export declare class Transaction extends SpanClass implements TransactionInterface {
name: string;
metadata: TransactionMetadata;
private _metadata;
private _measurements;

@@ -54,2 +59,3 @@ /**

}
export {};
//# sourceMappingURL=transaction.d.ts.map

@@ -17,13 +17,14 @@ Object.defineProperty(exports, "__esModule", { value: true });

function Transaction(transactionContext, hub) {
var _a;
var _this = _super.call(this, transactionContext) || this;
_this._metadata = {};
_this._measurements = {};
/**
* The reference to the current hub.
*/
_this._hub = hub_1.getCurrentHub();
if (utils_1.isInstanceOf(hub, hub_1.Hub)) {
_this._hub = hub;
}
_this.name = transactionContext.name || '';
_this.metadata = transactionContext.metadata || {};
_this._trimEnd = transactionContext.trimEnd;
_this._hub = hub || hub_1.getCurrentHub();
// create a new sentry tracestate value if we didn't inherit one
if (!((_a = _this.metadata.tracestate) === null || _a === void 0 ? void 0 : _a.sentry)) {
_this.metadata.tracestate = tslib_1.__assign(tslib_1.__assign({}, _this.metadata.tracestate), { sentry: _this._getNewTracestate(_this._hub) });
}
// this is because transactions are also spans, and spans have a transaction pointer

@@ -62,3 +63,3 @@ _this.transaction = _this;

Transaction.prototype.setMetadata = function (newMetadata) {
this.metadata = tslib_1.__assign(tslib_1.__assign({}, this.metadata), newMetadata);
this._metadata = tslib_1.__assign(tslib_1.__assign({}, this._metadata), newMetadata);
};

@@ -104,3 +105,3 @@ /**

type: 'transaction',
debug_meta: this.metadata,
debug_meta: this._metadata,
};

@@ -107,0 +108,0 @@ var hasMeasurements = Object.keys(this._measurements).length > 0;

import { Hub } from '@sentry/hub';
import { Options, TraceparentData, Transaction } from '@sentry/types';
export declare const SENTRY_TRACE_REGEX: RegExp;
export declare const TRACEPARENT_REGEXP: RegExp;
/**

@@ -13,17 +13,7 @@ * Determines if tracing is currently enabled.

*
* @param header Traceparent string
* @param traceparent Traceparent string
*
* @returns Object containing data from the header, or undefined if traceparent string is malformed
*/
export declare function extractSentrytraceData(header: string): TraceparentData | undefined;
/**
* Extract data from an incoming `tracestate` header
*
* @param header
* @returns Object containing data from the header
*/
export declare function extractTracestateData(header: string): {
sentry?: string;
thirdparty?: string;
};
export declare function extractTraceparentData(traceparent: string): TraceparentData | undefined;
/** Grabs active transaction off scope, if any */

@@ -42,15 +32,2 @@ export declare function getActiveTransaction<T extends Transaction>(hub?: Hub): T | undefined;

export { stripUrlQueryAndFragment } from '@sentry/utils';
declare type SentryTracestateData = {
traceId: string;
environment: string | undefined | null;
release: string | undefined | null;
publicKey: string;
};
/**
* Compute the value of a Sentry tracestate header.
*
* @throws SentryError (because using the logger creates a circular dependency)
* @returns the base64-encoded header value
*/
export declare function computeTracestateValue(data: SentryTracestateData): string;
//# sourceMappingURL=utils.d.ts.map
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var hub_1 = require("@sentry/hub");
var utils_1 = require("@sentry/utils");
exports.SENTRY_TRACE_REGEX = new RegExp('^[ \\t]*' + // whitespace
exports.TRACEPARENT_REGEXP = new RegExp('^[ \\t]*' + // whitespace
'([0-9a-f]{32})?' + // trace_id

@@ -10,30 +8,2 @@ '-?([0-9a-f]{16})?' + // span_id

'[ \\t]*$');
// This is a normal base64 regex, modified to reflect that fact that we strip the trailing = or == off
var BASE64_STRIPPED_REGEX = new RegExp(
// for our purposes, we want to test against the entire string, so enforce that there's nothing before the main regex
"^" +
// any of the characters in the base64 "alphabet", in multiples of 4
'([a-zA-Z0-9+/]{4})*' +
// either nothing or 2 or 3 base64-alphabet characters (see
// https://en.wikipedia.org/wiki/Base64#Decoding_Base64_without_padding
// for why there's never only 1 extra character)
'([a-zA-Z0-9+/]{2,3})?' +
// see above re: matching entire string
"$");
// comma-delimited list of entries of the form `xxx=yyy`
var tracestateEntry = '[^=]+=[^=]+';
var TRACESTATE_ENTRIES_REGEX = new RegExp(
// one or more xxxxx=yyyy entries
"^(" + tracestateEntry + ")+" +
// each entry except the last must be followed by a comma
'(,|$)');
// this doesn't check that the value is valid, just that there's something there of the form `sentry=xxxx`
var SENTRY_TRACESTATE_ENTRY_REGEX = new RegExp(
// either sentry is the first entry or there's stuff immediately before it, ending in a commma (this prevents matching
// something like `coolsentry=xxx`)
'(?:^|.+,)' +
// sentry's part, not including the potential comma
'(sentry=[^,]*)' +
// either there's a comma and another vendor's entry or we end
'(?:,.+|$)');
/**

@@ -51,8 +21,8 @@ * Determines if tracing is currently enabled.

*
* @param header Traceparent string
* @param traceparent Traceparent string
*
* @returns Object containing data from the header, or undefined if traceparent string is malformed
*/
function extractSentrytraceData(header) {
var matches = header.match(exports.SENTRY_TRACE_REGEX);
function extractTraceparentData(traceparent) {
var matches = traceparent.match(exports.TRACEPARENT_REGEXP);
if (matches) {

@@ -74,39 +44,3 @@ var parentSampled = void 0;

}
exports.extractSentrytraceData = extractSentrytraceData;
/**
* Extract data from an incoming `tracestate` header
*
* @param header
* @returns Object containing data from the header
*/
function extractTracestateData(header) {
var _a;
var sentryEntry, thirdPartyEntry, before, after;
// find sentry's entry, if any
var sentryMatch = SENTRY_TRACESTATE_ENTRY_REGEX.exec(header);
if (sentryMatch !== null) {
sentryEntry = sentryMatch[1];
// remove the commas after the split so we don't end up with `xxx=yyy,,zzz=qqq` (double commas) when we put them
// back together
_a = tslib_1.__read(header.split(sentryEntry).map(function (s) { return s.replace(/^,*|,*$/g, ''); }), 2), before = _a[0], after = _a[1];
// extract sentry's value from its entry and test to make sure it's valid; if it isn't, discard the entire entry
// so that a new one will be created by the Transaction constructor
var sentryValue = sentryEntry.replace('sentry=', '');
if (!BASE64_STRIPPED_REGEX.test(sentryValue)) {
sentryEntry = undefined;
}
}
else {
// this could just as well be `before`; we just need to get the thirdparty data into one or the other since
// there's no valid Sentry entry
after = header;
}
// if either thirdparty part is invalid or empty, remove it before gluing them together
var validThirdpartyEntries = [before, after].filter(function (x) { return TRACESTATE_ENTRIES_REGEX.test(x || ''); });
if (validThirdpartyEntries.length) {
thirdPartyEntry = validThirdpartyEntries.join(',');
}
return { sentry: sentryEntry, thirdparty: thirdPartyEntry };
}
exports.extractTracestateData = extractTracestateData;
exports.extractTraceparentData = extractTraceparentData;
/** Grabs active transaction off scope, if any */

@@ -136,31 +70,4 @@ function getActiveTransaction(hub) {

// so it can be used in manual instrumentation without necessitating a hard dependency on @sentry/utils
var utils_2 = require("@sentry/utils");
exports.stripUrlQueryAndFragment = utils_2.stripUrlQueryAndFragment;
/**
* Compute the value of a Sentry tracestate header.
*
* @throws SentryError (because using the logger creates a circular dependency)
* @returns the base64-encoded header value
*/
function computeTracestateValue(data) {
// `JSON.stringify` will drop keys with undefined values, but not ones with null values, so this prevents
// `environment` and `release` from being dropped if they haven't been set by `Sentry.init`
data.environment = data.environment || null;
data.release = data.release || null;
// See https://www.w3.org/TR/trace-context/#tracestate-header-field-values
// The spec for tracestate header values calls for a string of the form
//
// identifier1=value1,identifier2=value2,...
//
// which means the value can't include any equals signs, since they already have meaning. Equals signs are commonly
// used to pad the end of base64 values though, so to avoid confusion, we strip them off. (Most languages' base64
// decoding functions (including those in JS) are able to function without the padding.)
try {
return utils_1.unicodeToBase64(JSON.stringify(data)).replace(/={1,2}$/, '');
}
catch (err) {
throw new utils_1.SentryError("[Tracing] Error computing tracestate value from data: " + err + "\nData: " + data);
}
}
exports.computeTracestateValue = computeTracestateValue;
var utils_1 = require("@sentry/utils");
exports.stripUrlQueryAndFragment = utils_1.stripUrlQueryAndFragment;
//# sourceMappingURL=utils.js.map

@@ -90,9 +90,9 @@ import { Hub } from '@sentry/hub';

/**
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
* Gets transaction context from a sentry-trace meta.
*
* @returns Transaction context data or undefined neither tag exists or has valid data
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
*/
export declare function extractTraceDataFromMetaTags(): Partial<TransactionContext> | undefined;
export declare function getHeaderContext(): Partial<TransactionContext> | undefined;
/** Returns the value of a meta tag */
export declare function getMetaContent(metaName: string): string | null;
//# sourceMappingURL=browsertracing.d.ts.map

@@ -6,3 +6,3 @@ import { __assign } from "tslib";

import { SpanStatus } from '../spanstatus';
import { extractSentrytraceData, extractTracestateData, secToMs } from '../utils';
import { extractTraceparentData, secToMs } from '../utils';
import { registerBackgroundTabDetection } from './backgroundtab';

@@ -69,3 +69,3 @@ import { MetricsInstrumentation } from './metrics';

var _a = this.options, beforeNavigate = _a.beforeNavigate, idleTimeout = _a.idleTimeout, maxTransactionDuration = _a.maxTransactionDuration;
var parentContextFromHeader = context.op === 'pageload' ? extractTraceDataFromMetaTags() : undefined;
var parentContextFromHeader = context.op === 'pageload' ? getHeaderContext() : undefined;
var expandedContext = __assign(__assign(__assign({}, context), parentContextFromHeader), { trimEnd: true });

@@ -97,14 +97,10 @@ var modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext;

/**
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
* Gets transaction context from a sentry-trace meta.
*
* @returns Transaction context data or undefined neither tag exists or has valid data
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
*/
export function extractTraceDataFromMetaTags() {
var _a, _b;
var sentrytraceValue = getMetaContent('sentry-trace');
var tracestateValue = getMetaContent('tracestate');
var sentrytraceData = sentrytraceValue ? extractSentrytraceData(sentrytraceValue) : undefined;
var tracestateData = tracestateValue ? extractTracestateData(tracestateValue) : undefined;
if (sentrytraceData || ((_a = tracestateData) === null || _a === void 0 ? void 0 : _a.sentry) || ((_b = tracestateData) === null || _b === void 0 ? void 0 : _b.thirdparty)) {
return __assign(__assign({}, sentrytraceData), (tracestateData && { metadata: { tracestate: tracestateData } }));
export function getHeaderContext() {
var header = getMetaContent('sentry-trace');
if (header) {
return extractTraceparentData(header);
}

@@ -111,0 +107,0 @@ return undefined;

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

import { Span } from '@sentry/types';
import { Span } from '../span';
export declare const DEFAULT_TRACING_ORIGINS: (string | RegExp)[];

@@ -3,0 +3,0 @@ /** Options for Request Instrumentation */

@@ -100,13 +100,13 @@ import { __assign, __read, __spread } from "tslib";

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
headers.append(Object.entries(span.getTraceHeaders()));
headers.append('sentry-trace', span.toTraceparent());
}
else if (Array.isArray(headers)) {
headers = __spread(headers, Object.entries(span.getTraceHeaders()));
headers = __spread(headers, [['sentry-trace', span.toTraceparent()]]);
}
else {
headers = __assign(__assign({}, headers), span.getTraceHeaders());
headers = __assign(__assign({}, headers), { 'sentry-trace': span.toTraceparent() });
}
}
else {
headers = span.getTraceHeaders();
headers = { 'sentry-trace': span.toTraceparent() };
}

@@ -152,7 +152,3 @@ options.headers = headers;

try {
var sentryHeaders = span.getTraceHeaders();
handlerData.xhr.setRequestHeader('sentry-trace', sentryHeaders['sentry-trace']);
if (sentryHeaders.tracestate) {
handlerData.xhr.setRequestHeader('tracestate', sentryHeaders.tracestate);
}
handlerData.xhr.setRequestHeader('sentry-trace', span.toTraceparent());
}

@@ -159,0 +155,0 @@ catch (_) {

@@ -9,2 +9,15 @@ import { __assign } from "tslib";

import { hasTracingEnabled } from './utils';
/** Returns all trace headers that are currently on the top scope. */
function traceHeaders() {
var scope = this.getScope();
if (scope) {
var span = scope.getSpan();
if (span) {
return {
'sentry-trace': span.toTraceparent(),
};
}
}
return {};
}
/**

@@ -155,2 +168,5 @@ * Makes a sampling decision for the given transaction and stores it on the transaction.

}
if (!carrier.__SENTRY__.extensions.traceHeaders) {
carrier.__SENTRY__.extensions.traceHeaders = traceHeaders;
}
}

@@ -157,0 +173,0 @@ }

@@ -19,3 +19,3 @@ import { BrowserTracing } from './browser';

export { addExtensionMethods };
export { extractSentrytraceData, extractTracestateData, getActiveTransaction, hasTracingEnabled, SENTRY_TRACE_REGEX, stripUrlQueryAndFragment, } from './utils';
export { extractTraceparentData, getActiveTransaction, hasTracingEnabled, stripUrlQueryAndFragment, TRACEPARENT_REGEXP, } from './utils';
//# sourceMappingURL=index.d.ts.map

@@ -16,3 +16,3 @@ import { __assign } from "tslib";

export { addExtensionMethods };
export { extractSentrytraceData, extractTracestateData, getActiveTransaction, hasTracingEnabled, SENTRY_TRACE_REGEX, stripUrlQueryAndFragment, } from './utils';
export { extractTraceparentData, getActiveTransaction, hasTracingEnabled, stripUrlQueryAndFragment, TRACEPARENT_REGEXP, } from './utils';
//# sourceMappingURL=index.js.map

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

import { Hub, Primitive, Span as SpanInterface, SpanContext, TraceHeaders, Transaction } from '@sentry/types';
import { Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
import { SpanStatus } from './spanstatus';

@@ -137,6 +137,2 @@ /**

*/
getTraceHeaders(): TraceHeaders;
/**
* @inheritDoc
*/
getTraceContext(): {

@@ -175,17 +171,3 @@ data?: {

};
/**
* Create a new Sentry tracestate header entry (i.e. `sentry=xxxxxx`)
*
* @returns The new Sentry tracestate entry, or undefined if there's no client or no dsn
*/
protected _getNewTracestate(hub?: Hub): string | undefined;
/**
* Return a traceparent-compatible header string.
*/
private _toSentrytrace;
/**
* Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN.
*/
private _toTracestate;
}
//# sourceMappingURL=span.d.ts.map
import { __assign } from "tslib";
/* eslint-disable max-lines */
import { getCurrentHub } from '@sentry/hub';
import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils';
import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils';
import { SpanStatus } from './spanstatus';
import { computeTracestateValue } from './utils';
/**

@@ -177,4 +174,7 @@ * Keeps track of finished spans for a given transaction

Span.prototype.toTraceparent = function () {
logger.warn('Direct use of `span.toTraceparent` is deprecated. Use `span.getTraceHeaders` instead.');
return this._toSentrytrace();
var sampledString = '';
if (this.sampled !== undefined) {
sampledString = this.sampled ? '-1' : '-0';
}
return this.traceId + "-" + this.spanId + sampledString;
};

@@ -220,9 +220,2 @@ /**

*/
Span.prototype.getTraceHeaders = function () {
var tracestate = this._toTracestate();
return __assign({ 'sentry-trace': this._toSentrytrace() }, (tracestate && { tracestate: tracestate }));
};
/**
* @inheritDoc
*/
Span.prototype.getTraceContext = function () {

@@ -257,49 +250,2 @@ return dropUndefinedKeys({

};
/**
* Create a new Sentry tracestate header entry (i.e. `sentry=xxxxxx`)
*
* @returns The new Sentry tracestate entry, or undefined if there's no client or no dsn
*/
Span.prototype._getNewTracestate = function (hub) {
if (hub === void 0) { hub = getCurrentHub(); }
var _a;
var client = hub.getClient();
var dsn = (_a = client) === null || _a === void 0 ? void 0 : _a.getDsn();
if (!client || !dsn) {
return;
}
var _b = client.getOptions() || {}, environment = _b.environment, release = _b.release;
// TODO - the only reason we need the non-null assertion on `dsn.publicKey` (below) is because `dsn.publicKey` has
// to be optional while we transition from `dsn.user` -> `dsn.publicKey`. Once `dsn.user` is removed, we can make
// `dsn.publicKey` required and remove the `!`.
return "sentry=" + computeTracestateValue({
traceId: this.traceId,
environment: environment,
release: release,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
publicKey: dsn.publicKey,
});
};
/**
* Return a traceparent-compatible header string.
*/
Span.prototype._toSentrytrace = function () {
var sampledString = '';
if (this.sampled !== undefined) {
sampledString = this.sampled ? '-1' : '-0';
}
return this.traceId + "-" + this.spanId + sampledString;
};
/**
* Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN.
*/
Span.prototype._toTracestate = function () {
var _a, _b, _c, _d, _e, _f;
var sentryTracestate = ((_c = (_b = (_a = this.transaction) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.tracestate) === null || _c === void 0 ? void 0 : _c.sentry) || this._getNewTracestate();
var thirdpartyTracestate = (_f = (_e = (_d = this.transaction) === null || _d === void 0 ? void 0 : _d.metadata) === null || _e === void 0 ? void 0 : _e.tracestate) === null || _f === void 0 ? void 0 : _f.thirdparty;
// if there's third-party data, add a leading comma; otherwise, convert from `undefined` to the empty string, so the
// end result doesn’t come out as `sentry=xxxxxundefined`
thirdpartyTracestate = thirdpartyTracestate ? "," + thirdpartyTracestate : '';
return "" + sentryTracestate + thirdpartyTracestate;
};
return Span;

@@ -306,0 +252,0 @@ }());

import { Hub } from '@sentry/hub';
import { Measurements, Transaction as TransactionInterface, TransactionContext, TransactionMetadata } from '@sentry/types';
import { Measurements, Transaction as TransactionInterface, TransactionContext } from '@sentry/types';
import { Span as SpanClass } from './span';
interface TransactionMetadata {
transactionSampling?: {
[key: string]: string | number;
};
}
/** JSDoc */
export declare class Transaction extends SpanClass implements TransactionInterface {
name: string;
metadata: TransactionMetadata;
private _metadata;
private _measurements;

@@ -54,2 +59,3 @@ /**

}
export {};
//# sourceMappingURL=transaction.d.ts.map
import { __assign, __extends } from "tslib";
import { getCurrentHub } from '@sentry/hub';
import { dropUndefinedKeys, logger } from '@sentry/utils';
import { getCurrentHub, Hub } from '@sentry/hub';
import { dropUndefinedKeys, isInstanceOf, logger } from '@sentry/utils';
import { Span as SpanClass, SpanRecorder } from './span';

@@ -16,13 +16,14 @@ /** JSDoc */

function Transaction(transactionContext, hub) {
var _a;
var _this = _super.call(this, transactionContext) || this;
_this._metadata = {};
_this._measurements = {};
/**
* The reference to the current hub.
*/
_this._hub = getCurrentHub();
if (isInstanceOf(hub, Hub)) {
_this._hub = hub;
}
_this.name = transactionContext.name || '';
_this.metadata = transactionContext.metadata || {};
_this._trimEnd = transactionContext.trimEnd;
_this._hub = hub || getCurrentHub();
// create a new sentry tracestate value if we didn't inherit one
if (!((_a = _this.metadata.tracestate) === null || _a === void 0 ? void 0 : _a.sentry)) {
_this.metadata.tracestate = __assign(__assign({}, _this.metadata.tracestate), { sentry: _this._getNewTracestate(_this._hub) });
}
// this is because transactions are also spans, and spans have a transaction pointer

@@ -61,3 +62,3 @@ _this.transaction = _this;

Transaction.prototype.setMetadata = function (newMetadata) {
this.metadata = __assign(__assign({}, this.metadata), newMetadata);
this._metadata = __assign(__assign({}, this._metadata), newMetadata);
};

@@ -103,3 +104,3 @@ /**

type: 'transaction',
debug_meta: this.metadata,
debug_meta: this._metadata,
};

@@ -106,0 +107,0 @@ var hasMeasurements = Object.keys(this._measurements).length > 0;

import { Hub } from '@sentry/hub';
import { Options, TraceparentData, Transaction } from '@sentry/types';
export declare const SENTRY_TRACE_REGEX: RegExp;
export declare const TRACEPARENT_REGEXP: RegExp;
/**

@@ -13,17 +13,7 @@ * Determines if tracing is currently enabled.

*
* @param header Traceparent string
* @param traceparent Traceparent string
*
* @returns Object containing data from the header, or undefined if traceparent string is malformed
*/
export declare function extractSentrytraceData(header: string): TraceparentData | undefined;
/**
* Extract data from an incoming `tracestate` header
*
* @param header
* @returns Object containing data from the header
*/
export declare function extractTracestateData(header: string): {
sentry?: string;
thirdparty?: string;
};
export declare function extractTraceparentData(traceparent: string): TraceparentData | undefined;
/** Grabs active transaction off scope, if any */

@@ -42,15 +32,2 @@ export declare function getActiveTransaction<T extends Transaction>(hub?: Hub): T | undefined;

export { stripUrlQueryAndFragment } from '@sentry/utils';
declare type SentryTracestateData = {
traceId: string;
environment: string | undefined | null;
release: string | undefined | null;
publicKey: string;
};
/**
* Compute the value of a Sentry tracestate header.
*
* @throws SentryError (because using the logger creates a circular dependency)
* @returns the base64-encoded header value
*/
export declare function computeTracestateValue(data: SentryTracestateData): string;
//# sourceMappingURL=utils.d.ts.map

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

import { __read } from "tslib";
import { getCurrentHub } from '@sentry/hub';
import { SentryError, unicodeToBase64 } from '@sentry/utils';
export var SENTRY_TRACE_REGEX = new RegExp('^[ \\t]*' + // whitespace
export var TRACEPARENT_REGEXP = new RegExp('^[ \\t]*' + // whitespace
'([0-9a-f]{32})?' + // trace_id

@@ -9,30 +7,2 @@ '-?([0-9a-f]{16})?' + // span_id

'[ \\t]*$');
// This is a normal base64 regex, modified to reflect that fact that we strip the trailing = or == off
var BASE64_STRIPPED_REGEX = new RegExp(
// for our purposes, we want to test against the entire string, so enforce that there's nothing before the main regex
"^" +
// any of the characters in the base64 "alphabet", in multiples of 4
'([a-zA-Z0-9+/]{4})*' +
// either nothing or 2 or 3 base64-alphabet characters (see
// https://en.wikipedia.org/wiki/Base64#Decoding_Base64_without_padding
// for why there's never only 1 extra character)
'([a-zA-Z0-9+/]{2,3})?' +
// see above re: matching entire string
"$");
// comma-delimited list of entries of the form `xxx=yyy`
var tracestateEntry = '[^=]+=[^=]+';
var TRACESTATE_ENTRIES_REGEX = new RegExp(
// one or more xxxxx=yyyy entries
"^(" + tracestateEntry + ")+" +
// each entry except the last must be followed by a comma
'(,|$)');
// this doesn't check that the value is valid, just that there's something there of the form `sentry=xxxx`
var SENTRY_TRACESTATE_ENTRY_REGEX = new RegExp(
// either sentry is the first entry or there's stuff immediately before it, ending in a commma (this prevents matching
// something like `coolsentry=xxx`)
'(?:^|.+,)' +
// sentry's part, not including the potential comma
'(sentry=[^,]*)' +
// either there's a comma and another vendor's entry or we end
'(?:,.+|$)');
/**

@@ -49,8 +19,8 @@ * Determines if tracing is currently enabled.

*
* @param header Traceparent string
* @param traceparent Traceparent string
*
* @returns Object containing data from the header, or undefined if traceparent string is malformed
*/
export function extractSentrytraceData(header) {
var matches = header.match(SENTRY_TRACE_REGEX);
export function extractTraceparentData(traceparent) {
var matches = traceparent.match(TRACEPARENT_REGEXP);
if (matches) {

@@ -72,37 +42,2 @@ var parentSampled = void 0;

}
/**
* Extract data from an incoming `tracestate` header
*
* @param header
* @returns Object containing data from the header
*/
export function extractTracestateData(header) {
var _a;
var sentryEntry, thirdPartyEntry, before, after;
// find sentry's entry, if any
var sentryMatch = SENTRY_TRACESTATE_ENTRY_REGEX.exec(header);
if (sentryMatch !== null) {
sentryEntry = sentryMatch[1];
// remove the commas after the split so we don't end up with `xxx=yyy,,zzz=qqq` (double commas) when we put them
// back together
_a = __read(header.split(sentryEntry).map(function (s) { return s.replace(/^,*|,*$/g, ''); }), 2), before = _a[0], after = _a[1];
// extract sentry's value from its entry and test to make sure it's valid; if it isn't, discard the entire entry
// so that a new one will be created by the Transaction constructor
var sentryValue = sentryEntry.replace('sentry=', '');
if (!BASE64_STRIPPED_REGEX.test(sentryValue)) {
sentryEntry = undefined;
}
}
else {
// this could just as well be `before`; we just need to get the thirdparty data into one or the other since
// there's no valid Sentry entry
after = header;
}
// if either thirdparty part is invalid or empty, remove it before gluing them together
var validThirdpartyEntries = [before, after].filter(function (x) { return TRACESTATE_ENTRIES_REGEX.test(x || ''); });
if (validThirdpartyEntries.length) {
thirdPartyEntry = validThirdpartyEntries.join(',');
}
return { sentry: sentryEntry, thirdparty: thirdPartyEntry };
}
/** Grabs active transaction off scope, if any */

@@ -130,28 +65,2 @@ export function getActiveTransaction(hub) {

export { stripUrlQueryAndFragment } from '@sentry/utils';
/**
* Compute the value of a Sentry tracestate header.
*
* @throws SentryError (because using the logger creates a circular dependency)
* @returns the base64-encoded header value
*/
export function computeTracestateValue(data) {
// `JSON.stringify` will drop keys with undefined values, but not ones with null values, so this prevents
// `environment` and `release` from being dropped if they haven't been set by `Sentry.init`
data.environment = data.environment || null;
data.release = data.release || null;
// See https://www.w3.org/TR/trace-context/#tracestate-header-field-values
// The spec for tracestate header values calls for a string of the form
//
// identifier1=value1,identifier2=value2,...
//
// which means the value can't include any equals signs, since they already have meaning. Equals signs are commonly
// used to pad the end of base64 values though, so to avoid confusion, we strip them off. (Most languages' base64
// decoding functions (including those in JS) are able to function without the padding.)
try {
return unicodeToBase64(JSON.stringify(data)).replace(/={1,2}$/, '');
}
catch (err) {
throw new SentryError("[Tracing] Error computing tracestate value from data: " + err + "\nData: " + data);
}
}
//# sourceMappingURL=utils.js.map
{
"name": "@sentry/tracing",
"version": "6.3.0-beta.0",
"version": "6.3.0-beta.1",
"description": "Extensions for Sentry AM",

@@ -19,11 +19,11 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"dependencies": {
"@sentry/hub": "6.3.0-beta.0",
"@sentry/minimal": "6.3.0-beta.0",
"@sentry/types": "6.3.0-beta.0",
"@sentry/utils": "6.3.0-beta.0",
"@sentry/hub": "6.3.0-beta.1",
"@sentry/minimal": "6.3.0-beta.1",
"@sentry/types": "6.3.0-beta.1",
"@sentry/utils": "6.3.0-beta.1",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "6.2.1",
"@sentry/browser": "6.3.0-beta.0",
"@sentry-internal/eslint-config-sdk": "6.3.0-beta.1",
"@sentry/browser": "6.3.0-beta.1",
"@types/express": "^4.17.1",

@@ -30,0 +30,0 @@ "@types/jsdom": "^16.2.3",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

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

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

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