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.3 to 6.3.0-beta.4

6

dist/browser/browsertracing.d.ts

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

/**
* Gets transaction context from a sentry-trace meta.
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
*
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
* @returns Transaction context data or undefined neither tag exists or has valid data
*/
export declare function getHeaderContext(): Partial<TransactionContext> | undefined;
export declare function extractTraceDataFromMetaTags(): 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' ? getHeaderContext() : undefined;
var parentContextFromHeader = context.op === 'pageload' ? extractTraceDataFromMetaTags() : undefined;
var expandedContext = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, context), parentContextFromHeader), { trimEnd: true });

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

/**
* Gets transaction context from a sentry-trace meta.
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
*
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
* @returns Transaction context data or undefined neither tag exists or has valid data
*/
function getHeaderContext() {
var header = getMetaContent('sentry-trace');
if (header) {
return utils_2.extractTraceparentData(header);
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 } }));
}
return undefined;
}
exports.getHeaderContext = getHeaderContext;
exports.extractTraceDataFromMetaTags = extractTraceDataFromMetaTags;
/** Returns the value of a meta tag */

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

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

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

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

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

}
var traceHeaders = span.getTraceHeaders();
if (headers) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof headers.append === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
headers.append('sentry-trace', span.toTraceparent());
if ('append' in headers && typeof headers.append === 'function') {
headers.append('sentry-trace', traceHeaders['sentry-trace']);
if (traceHeaders.tracestate) {
headers.append('tracestate', traceHeaders.tracestate);
}
}
else if (Array.isArray(headers)) {
headers = tslib_1.__spread(headers, [['sentry-trace', span.toTraceparent()]]);
// TODO use the nicer version below once we stop supporting Node 6
// headers = [...headers, ...Object.entries(traceHeaders)];
headers = tslib_1.__spread(headers, [['sentry-trace', traceHeaders['sentry-trace']], ['tracestate', traceHeaders.tracestate]]);
}
else {
headers = tslib_1.__assign(tslib_1.__assign({}, headers), { 'sentry-trace': span.toTraceparent() });
headers = tslib_1.__assign(tslib_1.__assign({}, headers), traceHeaders);
}
}
else {
headers = { 'sentry-trace': span.toTraceparent() };
headers = traceHeaders;
}

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

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

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

@@ -10,15 +10,2 @@ 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 {};
}
/**

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

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

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

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

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

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

var utils_1 = require("./utils");
exports.extractTraceparentData = utils_1.extractTraceparentData;
exports.extractSentrytraceData = utils_1.extractSentrytraceData;
exports.extractTracestateData = utils_1.extractTracestateData;
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 { Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
import { Hub, Primitive, Span as SpanInterface, SpanContext, TraceHeaders, Transaction } from '@sentry/types';
import { SpanStatus } from './spanstatus';

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

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

@@ -171,3 +175,17 @@ 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");
/**

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

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

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

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

@@ -251,2 +258,49 @@ 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;

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

import { Hub } from '@sentry/hub';
import { Measurements, Transaction as TransactionInterface, TransactionContext } from '@sentry/types';
import { Measurements, Transaction as TransactionInterface, TransactionContext, TransactionMetadata } 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;
private _metadata;
metadata: TransactionMetadata;
private _measurements;

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

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

@@ -17,14 +17,13 @@ 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

@@ -63,3 +62,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);
};

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

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

@@ -108,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 TRACEPARENT_REGEXP: RegExp;
export declare const SENTRY_TRACE_REGEX: RegExp;
/**

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

*
* @param traceparent Traceparent string
* @param header Traceparent string
*
* @returns Object containing data from the header, or undefined if traceparent string is malformed
*/
export declare function extractTraceparentData(traceparent: string): TraceparentData | undefined;
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;
};
/** Grabs active transaction off scope, if any */

@@ -32,2 +42,15 @@ 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");
exports.TRACEPARENT_REGEXP = new RegExp('^[ \\t]*' + // whitespace
var utils_1 = require("@sentry/utils");
exports.SENTRY_TRACE_REGEX = new RegExp('^[ \\t]*' + // whitespace
'([0-9a-f]{32})?' + // trace_id

@@ -8,2 +10,30 @@ '-?([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
'(?:,.+|$)');
/**

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

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

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

}
exports.extractTraceparentData = extractTraceparentData;
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;
/** Grabs active transaction off scope, if any */

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

// so it can be used in manual instrumentation without necessitating a hard dependency on @sentry/utils
var utils_1 = require("@sentry/utils");
exports.stripUrlQueryAndFragment = utils_1.stripUrlQueryAndFragment;
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;
//# sourceMappingURL=utils.js.map

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

/**
* Gets transaction context from a sentry-trace meta.
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
*
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
* @returns Transaction context data or undefined neither tag exists or has valid data
*/
export declare function getHeaderContext(): Partial<TransactionContext> | undefined;
export declare function extractTraceDataFromMetaTags(): 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 { extractTraceparentData, secToMs } from '../utils';
import { extractSentrytraceData, extractTracestateData, 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' ? getHeaderContext() : undefined;
var parentContextFromHeader = context.op === 'pageload' ? extractTraceDataFromMetaTags() : undefined;
var expandedContext = __assign(__assign(__assign({}, context), parentContextFromHeader), { trimEnd: true });

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

/**
* Gets transaction context from a sentry-trace meta.
* Gets transaction context data from `sentry-trace` and `tracestate` <meta> tags.
*
* @returns Transaction context data from the header or undefined if there's no header or the header is malformed
* @returns Transaction context data or undefined neither tag exists or has valid data
*/
export function getHeaderContext() {
var header = getMetaContent('sentry-trace');
if (header) {
return extractTraceparentData(header);
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 } }));
}

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

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

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

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

@@ -96,17 +96,21 @@ import { __assign, __read, __spread } from "tslib";

}
var traceHeaders = span.getTraceHeaders();
if (headers) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof headers.append === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
headers.append('sentry-trace', span.toTraceparent());
if ('append' in headers && typeof headers.append === 'function') {
headers.append('sentry-trace', traceHeaders['sentry-trace']);
if (traceHeaders.tracestate) {
headers.append('tracestate', traceHeaders.tracestate);
}
}
else if (Array.isArray(headers)) {
headers = __spread(headers, [['sentry-trace', span.toTraceparent()]]);
// TODO use the nicer version below once we stop supporting Node 6
// headers = [...headers, ...Object.entries(traceHeaders)];
headers = __spread(headers, [['sentry-trace', traceHeaders['sentry-trace']], ['tracestate', traceHeaders.tracestate]]);
}
else {
headers = __assign(__assign({}, headers), { 'sentry-trace': span.toTraceparent() });
headers = __assign(__assign({}, headers), traceHeaders);
}
}
else {
headers = { 'sentry-trace': span.toTraceparent() };
headers = traceHeaders;
}

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

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

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

@@ -9,15 +9,2 @@ 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 {};
}
/**

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

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

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

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

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

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

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

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

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

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

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

@@ -171,3 +175,17 @@ 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";
import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils';
/* eslint-disable max-lines */
import { getCurrentHub } from '@sentry/hub';
import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils';
import { SpanStatus } from './spanstatus';
import { computeTracestateValue } from './utils';
/**

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

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

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

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

@@ -250,2 +257,49 @@ 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;

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

import { Hub } from '@sentry/hub';
import { Measurements, Transaction as TransactionInterface, TransactionContext } from '@sentry/types';
import { Measurements, Transaction as TransactionInterface, TransactionContext, TransactionMetadata } 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;
private _metadata;
metadata: TransactionMetadata;
private _measurements;

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

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

@@ -16,14 +16,13 @@ /** 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

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

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

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

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

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

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

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

*
* @param traceparent Traceparent string
* @param header Traceparent string
*
* @returns Object containing data from the header, or undefined if traceparent string is malformed
*/
export declare function extractTraceparentData(traceparent: string): TraceparentData | undefined;
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;
};
/** Grabs active transaction off scope, if any */

@@ -32,2 +42,15 @@ 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

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

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

@@ -7,2 +9,30 @@ '-?([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
'(?:,.+|$)');
/**

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

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

@@ -42,2 +72,37 @@ 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 */

@@ -65,2 +130,28 @@ 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.3",
"version": "6.3.0-beta.4",
"description": "Extensions for Sentry AM",

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

"dependencies": {
"@sentry/hub": "6.3.0-beta.3",
"@sentry/minimal": "6.3.0-beta.3",
"@sentry/types": "6.3.0-beta.3",
"@sentry/utils": "6.3.0-beta.3",
"@sentry/hub": "6.3.0-beta.4",
"@sentry/minimal": "6.3.0-beta.4",
"@sentry/types": "6.3.0-beta.4",
"@sentry/utils": "6.3.0-beta.4",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "6.3.0-beta.3",
"@sentry/browser": "6.3.0-beta.3",
"@sentry-internal/eslint-config-sdk": "6.3.0-beta.4",
"@sentry/browser": "6.3.0-beta.4",
"@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