diff --git a/CHANGELOG.md b/CHANGELOG.md index 01d9d6d5f48e..5dff43fc09d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ since we removed some methods from the public API and removed some classes from - **breaking** [utils] ref: Rename `safeNormalize` to `normalize` and rewrite its internals - **breaking** [utils] ref: Remove `serialize`, `deserialize`, `clone` and `serializeObject` functions - **breaking** [utils] ref: Rewrite normalization functions by removing most of them and leaving just `normalize` and `normalizeToSize` +- [core] feat: Add `maxValueLength` option to adjust max string length for values, default is 250. ## 4.6.3 diff --git a/packages/browser/src/integrations/globalhandlers.ts b/packages/browser/src/integrations/globalhandlers.ts index ca97b3bcf600..65d25890d20e 100644 --- a/packages/browser/src/integrations/globalhandlers.ts +++ b/packages/browser/src/integrations/globalhandlers.ts @@ -114,7 +114,12 @@ export class GlobalHandlers implements Integration { }, }; - const fallbackValue = stacktrace.original ? truncate(JSON.stringify(normalize(stacktrace.original)), 300) : ''; + const client = getCurrentHub().getClient(); + const maxValueLength = (client && client.getOptions().maxValueLength) || 250; + + const fallbackValue = stacktrace.original + ? truncate(JSON.stringify(normalize(stacktrace.original)), maxValueLength) + : ''; const fallbackType = stacktrace.mechanism === 'onunhandledrejection' ? 'UnhandledRejection' : 'Error'; // This makes sure we have type/value in every exception diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 87da0ef8751d..3da40105d284 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -9,11 +9,6 @@ import { Backend, BackendClass } from './basebackend'; import { Dsn } from './dsn'; import { IntegrationIndex, setupIntegrations } from './integration'; -/** - * By default, truncates URL values to 250 chars - */ -const MAX_URL_LENGTH = 250; - /** * Base implementation for all JavaScript SDK clients. * @@ -178,7 +173,7 @@ export abstract class BaseClient implement * @returns A new event with more information. */ protected prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise { - const { environment, release, dist } = this.getOptions(); + const { environment, release, dist, maxValueLength = 250 } = this.getOptions(); const prepared: Event = { ...event }; if (prepared.environment === undefined && environment !== undefined) { @@ -193,17 +188,17 @@ export abstract class BaseClient implement } if (prepared.message) { - prepared.message = truncate(prepared.message, MAX_URL_LENGTH); + prepared.message = truncate(prepared.message, maxValueLength); } const exception = prepared.exception && prepared.exception.values && prepared.exception.values[0]; if (exception && exception.value) { - exception.value = truncate(exception.value, MAX_URL_LENGTH); + exception.value = truncate(exception.value, maxValueLength); } const request = prepared.request; if (request && request.url) { - request.url = truncate(request.url, MAX_URL_LENGTH); + request.url = truncate(request.url, maxValueLength); } if (prepared.event_id === undefined) { diff --git a/packages/hub/src/hub.ts b/packages/hub/src/hub.ts index 8cc225356c28..9cc8986e78d7 100644 --- a/packages/hub/src/hub.ts +++ b/packages/hub/src/hub.ts @@ -158,7 +158,7 @@ export class Hub { } /** Returns the client of the top stack. */ - public getClient(): any | undefined { + public getClient(): Client | undefined { return this.getStackTop().client; } @@ -298,8 +298,12 @@ export class Hub { /** Returns the integration if installed on the current client. */ public getIntegration(integration: IntegrationClass): T | null { + const client = this.getClient(); + if (!client) { + return null; + } try { - return this.getClient().getIntegration(integration); + return client.getIntegration(integration); } catch (_oO) { logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`); return null; diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index bfa46e737be0..3ec87bd5c913 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -138,30 +138,31 @@ function emitWrapper(origEmit: EventListener): (event: string, response: http.Se return origEmit.apply(this, arguments); } - const dsn = getCurrentHub() - .getClient() - .getDsn(); - - const isInterestingEvent = event === 'response' || event === 'error'; - const isNotSentryRequest = dsn && this.__ravenBreadcrumbUrl && !this.__ravenBreadcrumbUrl.includes(dsn.host); - - if (isInterestingEvent && isNotSentryRequest && getCurrentHub().getIntegration(Http)) { - getCurrentHub().addBreadcrumb( - { - category: 'http', - data: { - method: this.method, - status_code: response.statusCode, - url: this.__ravenBreadcrumbUrl, + const client = getCurrentHub().getClient(); + if (client) { + const dsn = client.getDsn(); + + const isInterestingEvent = event === 'response' || event === 'error'; + const isNotSentryRequest = dsn && this.__ravenBreadcrumbUrl && !this.__ravenBreadcrumbUrl.includes(dsn.host); + + if (isInterestingEvent && isNotSentryRequest && getCurrentHub().getIntegration(Http)) { + getCurrentHub().addBreadcrumb( + { + category: 'http', + data: { + method: this.method, + status_code: response.statusCode, + url: this.__ravenBreadcrumbUrl, + }, + type: 'http', }, - type: 'http', - }, - { - event, - request: this, - response, - }, - ); + { + event, + request: this, + response, + }, + ); + } } return origEmit.apply(this, arguments); diff --git a/packages/types/src/dsn.ts b/packages/types/src/dsn.ts index 117b900064b2..c697c275e553 100644 --- a/packages/types/src/dsn.ts +++ b/packages/types/src/dsn.ts @@ -23,7 +23,7 @@ export interface DsnComponents { export type DsnLike = string | DsnComponents; /** The Sentry Dsn, identifying a Sentry instance and project. */ -export interface Dsn { +export interface Dsn extends DsnComponents { /** * Renders the string representation of this Dsn. * diff --git a/packages/types/src/options.ts b/packages/types/src/options.ts index 56af609c37a6..f652b25698e2 100644 --- a/packages/types/src/options.ts +++ b/packages/types/src/options.ts @@ -78,6 +78,9 @@ export interface Options { /** Attaches stacktraces to pure capture message / log integrations */ attachStacktrace?: boolean; + /** Maxium number of chars a single value can have before it will be truncated. */ + maxValueLength?: number; + /** * A callback invoked during event submission, allowing to optionally modify * the event before it is sent to Sentry.