Comparing version 2.3.0 to 2.4.0
@@ -8,5 +8,17 @@ 'use strict'; | ||
var stacktraceJs = require('stacktrace-js'); | ||
var scope = require('./scope'); | ||
class Toucan { | ||
constructor(options) { | ||
/** | ||
* Default maximum number of breadcrumbs added to an event. Can be overwritten | ||
* with {@link Options.maxBreadcrumbs}. | ||
*/ | ||
this.DEFAULT_BREADCRUMBS = 100; | ||
/** | ||
* Absolute maximum number of breadcrumbs added to an event. The | ||
* `maxBreadcrumbs` option cannot be higher than this value. | ||
*/ | ||
this.MAX_BREADCRUMBS = 100; | ||
this.scopes = [new scope.Scope()]; | ||
this.options = options; | ||
@@ -24,3 +36,2 @@ if (!options.dsn || options.dsn.length === 0) { | ||
} | ||
this.user = undefined; | ||
this.request = | ||
@@ -30,6 +41,2 @@ "request" in options.event | ||
: undefined; | ||
this.breadcrumbs = []; | ||
this.tags = undefined; | ||
this.extra = undefined; | ||
this.fingerprint = undefined; | ||
this.beforeSend = this.beforeSend.bind(this); | ||
@@ -60,9 +67,6 @@ /** | ||
* @param key String key of extra | ||
* @param value String value of extra | ||
* @param extra Extra value of extra | ||
*/ | ||
setExtra(key, value) { | ||
if (!this.extra) { | ||
this.extra = {}; | ||
} | ||
this.extra[key] = value; | ||
setExtra(key, extra) { | ||
this.getScope().setExtra(key, extra); | ||
} | ||
@@ -75,3 +79,3 @@ /** | ||
setExtras(extras) { | ||
this.extra = { ...this.extra, ...extras }; | ||
this.getScope().setExtras(extras); | ||
} | ||
@@ -82,9 +86,6 @@ /** | ||
* @param key String key of tag | ||
* @param value String value of tag | ||
* @param value Primitive value of tag | ||
*/ | ||
setTag(key, value) { | ||
if (!this.tags) { | ||
this.tags = {}; | ||
} | ||
this.tags[key] = value; | ||
this.getScope().setTag(key, value); | ||
} | ||
@@ -97,3 +98,3 @@ /** | ||
setTags(tags) { | ||
this.tags = { ...this.tags, ...tags }; | ||
this.getScope().setTags(tags); | ||
} | ||
@@ -106,3 +107,3 @@ /** | ||
setFingerprint(fingerprint) { | ||
this.fingerprint = fingerprint; | ||
this.getScope().setFingerprint(fingerprint); | ||
} | ||
@@ -116,6 +117,11 @@ /** | ||
addBreadcrumb(breadcrumb) { | ||
var _a; | ||
const maxBreadcrumbs = (_a = this.options.maxBreadcrumbs) !== null && _a !== void 0 ? _a : this.DEFAULT_BREADCRUMBS; | ||
const numberOfBreadcrumbs = Math.min(maxBreadcrumbs, this.MAX_BREADCRUMBS); | ||
if (numberOfBreadcrumbs <= 0) | ||
return; | ||
if (!breadcrumb.timestamp) { | ||
breadcrumb.timestamp = this.timestamp(); | ||
} | ||
this.breadcrumbs.push(breadcrumb); | ||
this.getScope().addBreadcrumb(breadcrumb, numberOfBreadcrumbs); | ||
} | ||
@@ -157,3 +163,3 @@ /** | ||
setUser(user) { | ||
this.user = user ? user : undefined; | ||
this.getScope().setUser(user); | ||
} | ||
@@ -176,2 +182,20 @@ /** | ||
/** | ||
* Creates a new scope with and executes the given operation within. The scope is automatically removed once the operation finishes or throws. | ||
* This is essentially a convenience function for: | ||
* | ||
* @example | ||
* pushScope(); | ||
* callback(); | ||
* popScope(); | ||
*/ | ||
withScope(callback) { | ||
const scope = this.pushScope(); | ||
try { | ||
callback(scope); | ||
} | ||
finally { | ||
this.popScope(); | ||
} | ||
} | ||
/** | ||
* Send data to Sentry. | ||
@@ -186,3 +210,3 @@ * | ||
"Content-Type": "application/json", | ||
"User-Agent": "toucan-js/2.3.0", | ||
"User-Agent": "toucan-js/2.4.0", | ||
}; | ||
@@ -237,2 +261,3 @@ // Build headers | ||
: undefined; | ||
const scope = this.getScope(); | ||
// per https://docs.sentry.io/development/sdk-dev/event-payloads/#required-attributes | ||
@@ -245,3 +270,2 @@ const payload = { | ||
environment: this.options.environment, | ||
user: this.user, | ||
timestamp: this.timestamp(), | ||
@@ -255,6 +279,2 @@ level: "error", | ||
: undefined, | ||
breadcrumbs: this.getBreadcrumbs(), | ||
tags: this.tags, | ||
extra: this.extra, | ||
fingerprint: this.fingerprint, | ||
...additionalData, | ||
@@ -264,5 +284,7 @@ request: this.request, | ||
name: "toucan-js", | ||
version: "2.3.0", | ||
version: "2.4.0", | ||
}, | ||
}; | ||
// Type-casting 'breadcrumb' to any because our level type is a union of literals, as opposed to Level enum. | ||
scope.applyToEvent(payload); | ||
const beforeSend = (_a = this.options.beforeSend) !== null && _a !== void 0 ? _a : this.beforeSend; | ||
@@ -469,15 +491,2 @@ return beforeSend(payload); | ||
/** | ||
* Get the breadcrumbs. If the stack size exceeds MAX_BREADCRUMBS, returns the last MAX_BREADCRUMBS breadcrumbs. | ||
*/ | ||
getBreadcrumbs() { | ||
var _a; | ||
const maxBreadcrumbs = (_a = this.options.maxBreadcrumbs) !== null && _a !== void 0 ? _a : 100; | ||
if (this.breadcrumbs.length > maxBreadcrumbs) { | ||
return this.breadcrumbs.slice(this.breadcrumbs.length - maxBreadcrumbs); | ||
} | ||
else { | ||
return this.breadcrumbs; | ||
} | ||
} | ||
/** | ||
* Runs a callback if debug === true. | ||
@@ -537,4 +546,27 @@ * Use this to delay execution of debug logic, to ensure toucan doesn't burn I/O in non-debug mode. | ||
} | ||
/** Returns the scope of the top stack. */ | ||
getScope() { | ||
return this.scopes[this.scopes.length - 1]; | ||
} | ||
/** | ||
* Create a new scope to store context information. | ||
* The scope will be layered on top of the current one. It is isolated, i.e. all breadcrumbs and context information added to this scope will be removed once the scope ends. * Be sure to always remove this scope with {@link this.popScope} when the operation finishes or throws. | ||
*/ | ||
pushScope() { | ||
// We want to clone the content of prev scope | ||
const scope$1 = scope.Scope.clone(this.getScope()); | ||
this.scopes.push(scope$1); | ||
return scope$1; | ||
} | ||
/** | ||
* Removes a previously pushed scope from the stack. | ||
* This restores the state before the scope was pushed. All breadcrumbs and context information added since the last call to {@link this.pushScope} are discarded. | ||
*/ | ||
popScope() { | ||
if (this.scopes.length <= 1) | ||
return false; | ||
return !!this.scopes.pop(); | ||
} | ||
} | ||
module.exports = Toucan; |
@@ -5,6 +5,21 @@ /** | ||
*/ | ||
import { User } from "@sentry/types"; | ||
import { User, Extra, Extras, Primitive } from "@sentry/types"; | ||
import { Options, Breadcrumb, Level } from "./types"; | ||
import { Scope } from "./scope"; | ||
export default class Toucan { | ||
/** | ||
* Default maximum number of breadcrumbs added to an event. Can be overwritten | ||
* with {@link Options.maxBreadcrumbs}. | ||
*/ | ||
private readonly DEFAULT_BREADCRUMBS; | ||
/** | ||
* Absolute maximum number of breadcrumbs added to an event. The | ||
* `maxBreadcrumbs` option cannot be higher than this value. | ||
*/ | ||
private readonly MAX_BREADCRUMBS; | ||
/** | ||
* Is a {@link Scope}[] | ||
*/ | ||
private scopes; | ||
/** | ||
* If an empty DSN is passed, we should treat it as valid option which signifies disabling the SDK. | ||
@@ -22,25 +37,5 @@ */ | ||
/** | ||
* Sentry user object. | ||
*/ | ||
private user?; | ||
/** | ||
* Sentry request object transformed from incoming event.request. | ||
*/ | ||
private request; | ||
/** | ||
* Sentry breadcrumbs array. | ||
*/ | ||
private breadcrumbs; | ||
/** | ||
* Sentry tags object. | ||
*/ | ||
private tags?; | ||
/** | ||
* Sentry extra object. | ||
*/ | ||
private extra?; | ||
/** | ||
* Used to override the Sentry default grouping. | ||
*/ | ||
private fingerprint?; | ||
constructor(options: Options); | ||
@@ -51,5 +46,5 @@ /** | ||
* @param key String key of extra | ||
* @param value String value of extra | ||
* @param extra Extra value of extra | ||
*/ | ||
setExtra(key: string, value: string): void; | ||
setExtra(key: string, extra: Extra): void; | ||
/** | ||
@@ -60,3 +55,3 @@ * Set an object that will be merged sent as extra data with the event. | ||
*/ | ||
setExtras(extras: Record<string, string>): void; | ||
setExtras(extras: Extras): void; | ||
/** | ||
@@ -66,5 +61,5 @@ * Set key:value that will be sent as tags data with the event. | ||
* @param key String key of tag | ||
* @param value String value of tag | ||
* @param value Primitive value of tag | ||
*/ | ||
setTag(key: string, value: string): void; | ||
setTag(key: string, value: Primitive): void; | ||
/** | ||
@@ -75,3 +70,5 @@ * Set an object that will be merged sent as tags data with the event. | ||
*/ | ||
setTags(tags: Record<string, string>): void; | ||
setTags(tags: { | ||
[key: string]: Primitive; | ||
}): void; | ||
/** | ||
@@ -120,2 +117,12 @@ * Overrides the Sentry default grouping. See https://docs.sentry.io/data-management/event-grouping/sdk-fingerprinting/ | ||
/** | ||
* Creates a new scope with and executes the given operation within. The scope is automatically removed once the operation finishes or throws. | ||
* This is essentially a convenience function for: | ||
* | ||
* @example | ||
* pushScope(); | ||
* callback(); | ||
* popScope(); | ||
*/ | ||
withScope(callback: (scope: Scope) => void): void; | ||
/** | ||
* Send data to Sentry. | ||
@@ -188,6 +195,2 @@ * | ||
/** | ||
* Get the breadcrumbs. If the stack size exceeds MAX_BREADCRUMBS, returns the last MAX_BREADCRUMBS breadcrumbs. | ||
*/ | ||
private getBreadcrumbs; | ||
/** | ||
* Runs a callback if debug === true. | ||
@@ -209,3 +212,15 @@ * Use this to delay execution of debug logic, to ensure toucan doesn't burn I/O in non-debug mode. | ||
private logResponse; | ||
/** Returns the scope of the top stack. */ | ||
private getScope; | ||
/** | ||
* Create a new scope to store context information. | ||
* The scope will be layered on top of the current one. It is isolated, i.e. all breadcrumbs and context information added to this scope will be removed once the scope ends. * Be sure to always remove this scope with {@link this.popScope} when the operation finishes or throws. | ||
*/ | ||
private pushScope; | ||
/** | ||
* Removes a previously pushed scope from the stack. | ||
* This restores the state before the scope was pushed. All breadcrumbs and context information added since the last call to {@link this.pushScope} are discarded. | ||
*/ | ||
private popScope; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,5 +6,17 @@ import { API } from '@sentry/core'; | ||
import { fromError } from 'stacktrace-js'; | ||
import { Scope } from './scope'; | ||
class Toucan { | ||
constructor(options) { | ||
/** | ||
* Default maximum number of breadcrumbs added to an event. Can be overwritten | ||
* with {@link Options.maxBreadcrumbs}. | ||
*/ | ||
this.DEFAULT_BREADCRUMBS = 100; | ||
/** | ||
* Absolute maximum number of breadcrumbs added to an event. The | ||
* `maxBreadcrumbs` option cannot be higher than this value. | ||
*/ | ||
this.MAX_BREADCRUMBS = 100; | ||
this.scopes = [new Scope()]; | ||
this.options = options; | ||
@@ -22,3 +34,2 @@ if (!options.dsn || options.dsn.length === 0) { | ||
} | ||
this.user = undefined; | ||
this.request = | ||
@@ -28,6 +39,2 @@ "request" in options.event | ||
: undefined; | ||
this.breadcrumbs = []; | ||
this.tags = undefined; | ||
this.extra = undefined; | ||
this.fingerprint = undefined; | ||
this.beforeSend = this.beforeSend.bind(this); | ||
@@ -58,9 +65,6 @@ /** | ||
* @param key String key of extra | ||
* @param value String value of extra | ||
* @param extra Extra value of extra | ||
*/ | ||
setExtra(key, value) { | ||
if (!this.extra) { | ||
this.extra = {}; | ||
} | ||
this.extra[key] = value; | ||
setExtra(key, extra) { | ||
this.getScope().setExtra(key, extra); | ||
} | ||
@@ -73,3 +77,3 @@ /** | ||
setExtras(extras) { | ||
this.extra = { ...this.extra, ...extras }; | ||
this.getScope().setExtras(extras); | ||
} | ||
@@ -80,9 +84,6 @@ /** | ||
* @param key String key of tag | ||
* @param value String value of tag | ||
* @param value Primitive value of tag | ||
*/ | ||
setTag(key, value) { | ||
if (!this.tags) { | ||
this.tags = {}; | ||
} | ||
this.tags[key] = value; | ||
this.getScope().setTag(key, value); | ||
} | ||
@@ -95,3 +96,3 @@ /** | ||
setTags(tags) { | ||
this.tags = { ...this.tags, ...tags }; | ||
this.getScope().setTags(tags); | ||
} | ||
@@ -104,3 +105,3 @@ /** | ||
setFingerprint(fingerprint) { | ||
this.fingerprint = fingerprint; | ||
this.getScope().setFingerprint(fingerprint); | ||
} | ||
@@ -114,6 +115,11 @@ /** | ||
addBreadcrumb(breadcrumb) { | ||
var _a; | ||
const maxBreadcrumbs = (_a = this.options.maxBreadcrumbs) !== null && _a !== void 0 ? _a : this.DEFAULT_BREADCRUMBS; | ||
const numberOfBreadcrumbs = Math.min(maxBreadcrumbs, this.MAX_BREADCRUMBS); | ||
if (numberOfBreadcrumbs <= 0) | ||
return; | ||
if (!breadcrumb.timestamp) { | ||
breadcrumb.timestamp = this.timestamp(); | ||
} | ||
this.breadcrumbs.push(breadcrumb); | ||
this.getScope().addBreadcrumb(breadcrumb, numberOfBreadcrumbs); | ||
} | ||
@@ -155,3 +161,3 @@ /** | ||
setUser(user) { | ||
this.user = user ? user : undefined; | ||
this.getScope().setUser(user); | ||
} | ||
@@ -174,2 +180,20 @@ /** | ||
/** | ||
* Creates a new scope with and executes the given operation within. The scope is automatically removed once the operation finishes or throws. | ||
* This is essentially a convenience function for: | ||
* | ||
* @example | ||
* pushScope(); | ||
* callback(); | ||
* popScope(); | ||
*/ | ||
withScope(callback) { | ||
const scope = this.pushScope(); | ||
try { | ||
callback(scope); | ||
} | ||
finally { | ||
this.popScope(); | ||
} | ||
} | ||
/** | ||
* Send data to Sentry. | ||
@@ -184,3 +208,3 @@ * | ||
"Content-Type": "application/json", | ||
"User-Agent": "toucan-js/2.3.0", | ||
"User-Agent": "toucan-js/2.4.0", | ||
}; | ||
@@ -235,2 +259,3 @@ // Build headers | ||
: undefined; | ||
const scope = this.getScope(); | ||
// per https://docs.sentry.io/development/sdk-dev/event-payloads/#required-attributes | ||
@@ -243,3 +268,2 @@ const payload = { | ||
environment: this.options.environment, | ||
user: this.user, | ||
timestamp: this.timestamp(), | ||
@@ -253,6 +277,2 @@ level: "error", | ||
: undefined, | ||
breadcrumbs: this.getBreadcrumbs(), | ||
tags: this.tags, | ||
extra: this.extra, | ||
fingerprint: this.fingerprint, | ||
...additionalData, | ||
@@ -262,5 +282,7 @@ request: this.request, | ||
name: "toucan-js", | ||
version: "2.3.0", | ||
version: "2.4.0", | ||
}, | ||
}; | ||
// Type-casting 'breadcrumb' to any because our level type is a union of literals, as opposed to Level enum. | ||
scope.applyToEvent(payload); | ||
const beforeSend = (_a = this.options.beforeSend) !== null && _a !== void 0 ? _a : this.beforeSend; | ||
@@ -467,15 +489,2 @@ return beforeSend(payload); | ||
/** | ||
* Get the breadcrumbs. If the stack size exceeds MAX_BREADCRUMBS, returns the last MAX_BREADCRUMBS breadcrumbs. | ||
*/ | ||
getBreadcrumbs() { | ||
var _a; | ||
const maxBreadcrumbs = (_a = this.options.maxBreadcrumbs) !== null && _a !== void 0 ? _a : 100; | ||
if (this.breadcrumbs.length > maxBreadcrumbs) { | ||
return this.breadcrumbs.slice(this.breadcrumbs.length - maxBreadcrumbs); | ||
} | ||
else { | ||
return this.breadcrumbs; | ||
} | ||
} | ||
/** | ||
* Runs a callback if debug === true. | ||
@@ -535,4 +544,27 @@ * Use this to delay execution of debug logic, to ensure toucan doesn't burn I/O in non-debug mode. | ||
} | ||
/** Returns the scope of the top stack. */ | ||
getScope() { | ||
return this.scopes[this.scopes.length - 1]; | ||
} | ||
/** | ||
* Create a new scope to store context information. | ||
* The scope will be layered on top of the current one. It is isolated, i.e. all breadcrumbs and context information added to this scope will be removed once the scope ends. * Be sure to always remove this scope with {@link this.popScope} when the operation finishes or throws. | ||
*/ | ||
pushScope() { | ||
// We want to clone the content of prev scope | ||
const scope = Scope.clone(this.getScope()); | ||
this.scopes.push(scope); | ||
return scope; | ||
} | ||
/** | ||
* Removes a previously pushed scope from the stack. | ||
* This restores the state before the scope was pushed. All breadcrumbs and context information added since the last call to {@link this.pushScope} are discarded. | ||
*/ | ||
popScope() { | ||
if (this.scopes.length <= 1) | ||
return false; | ||
return !!this.scopes.pop(); | ||
} | ||
} | ||
export default Toucan; |
@@ -24,3 +24,3 @@ /// <reference types="@cloudflare/workers-types" /> | ||
}; | ||
export declare type Level = "fatal" | "error" | "warning" | "info" | "debug"; | ||
export declare type Level = "critical" | "fatal" | "error" | "warning" | "info" | "log" | "debug"; | ||
export declare type Breadcrumb = Compute<Omit<SentryBreadcrumb, "level"> & { | ||
@@ -27,0 +27,0 @@ level?: Level; |
{ | ||
"name": "toucan-js", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Cloudflare Workers client for Sentry", | ||
@@ -28,5 +28,6 @@ "main": "dist/index.cjs.js", | ||
"dependencies": { | ||
"@sentry/core": "5.29.2", | ||
"@sentry/utils": "5.29.2", | ||
"@sentry/types": "5.29.2", | ||
"@sentry/core": "6.2.3", | ||
"@sentry/utils": "6.2.3", | ||
"@sentry/types": "6.2.3", | ||
"@sentry/hub": "6.2.3", | ||
"@types/cookie": "0.4.0", | ||
@@ -39,15 +40,15 @@ "@types/uuid": "8.3.0", | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "2.1.0", | ||
"@rollup/plugin-commonjs": "17.0.0", | ||
"@rollup/plugin-node-resolve": "11.0.1", | ||
"@rollup/plugin-replace": "2.3.4", | ||
"@types/jest": "26.0.20", | ||
"@types/node": "14.14.20", | ||
"@cloudflare/workers-types": "2.2.1", | ||
"@rollup/plugin-commonjs": "18.0.0", | ||
"@rollup/plugin-node-resolve": "11.2.1", | ||
"@rollup/plugin-replace": "2.4.2", | ||
"@types/jest": "26.0.22", | ||
"@types/node": "14.14.37", | ||
"@types/service-worker-mock": "2.0.1", | ||
"jest": "26.6.3", | ||
"rollup": "2.26.1", | ||
"rollup-plugin-typescript2": "0.29.0", | ||
"rollup": "2.43.1", | ||
"rollup-plugin-typescript2": "0.30.0", | ||
"service-worker-mock": "2.0.5", | ||
"ts-jest": "26.4.4", | ||
"typescript": "4.1.3" | ||
"ts-jest": "26.5.4", | ||
"typescript": "4.2.3" | ||
}, | ||
@@ -54,0 +55,0 @@ "author": "robertcepa@icloud.com", |
@@ -78,2 +78,3 @@ <p align="center"> | ||
- setFingerprint: Overrides the Sentry default grouping. | ||
- withScope: Creates a new scope and executes the given operation within. The scope is automatically removed once the operation finishes or throws. | ||
@@ -80,0 +81,0 @@ ## Minimal options |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
72353
11
1440
163
9
1
+ Added@sentry/hub@6.2.3
+ Added@sentry/core@6.2.3(transitive)
+ Added@sentry/hub@6.2.3(transitive)
+ Added@sentry/minimal@6.2.3(transitive)
+ Added@sentry/types@6.2.3(transitive)
+ Added@sentry/utils@6.2.3(transitive)
- Removed@sentry/core@5.29.2(transitive)
- Removed@sentry/hub@5.29.2(transitive)
- Removed@sentry/minimal@5.29.2(transitive)
- Removed@sentry/types@5.29.2(transitive)
- Removed@sentry/utils@5.29.2(transitive)
Updated@sentry/core@6.2.3
Updated@sentry/types@6.2.3
Updated@sentry/utils@6.2.3