Skip to content

feat: Add maxValueLength option #1928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -178,7 +173,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
* @returns A new event with more information.
*/
protected prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
const { environment, release, dist } = this.getOptions();
const { environment, release, dist, maxValueLength = 250 } = this.getOptions();

const prepared: Event = { ...event };
if (prepared.environment === undefined && environment !== undefined) {
Expand All @@ -193,17 +188,17 @@ export abstract class BaseClient<B extends Backend, O extends Options> 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) {
Expand Down
8 changes: 6 additions & 2 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -298,8 +298,12 @@ export class Hub {

/** Returns the integration if installed on the current client. */
public getIntegration<T extends Integration>(integration: IntegrationClass<T>): 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;
Expand Down
47 changes: 24 additions & 23 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/dsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down