-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
Hello, and thank you for simplifying our world on managing details sent to Sentry! I have a question about how the data is managed before sent.
The problem
In very simple words, our use-case is about filtering + performance optimisations.
- We expected to have details returned as object, within apply Sentry Filters (example, filtering
userId)- But we got a string that gets entirely filtered
- Library serializes data, that internally we deserialize before sending them
- wasting precious computational time
Our workaround
In order to "fix" this, in our code we are wasting some computational time to deserialize previously serialized data, with context and variables keys.
function parseData(breadcrumb: Breadcrumb, key: string) {
const breadcrumbData = breadcrumb.data;
if (!breadcrumbData || !(key in breadcrumbData)) {
// No interesting data, just return breadcrumb
return breadcrumb;
}
// Extract data "as object" or fail silently
try {
breadcrumbData[key] = JSON.parse(breadcrumbData[key]);
} catch {}
return breadcrumb;
}
function parseVariables(breadcrumb: Breadcrumb) {
return parseData(breadcrumb, 'variables');
}
function parseContext(breadcrumb: Breadcrumb) {
return parseData(breadcrumb, 'context');
}
Sentry.init({
beforeBreadcrumb: (breadcrumb, _) => {
// Drop meaningless breadcrumbs before sending to sentry
if (breadcrumbToIgnore(breadcrumb)) {
return null;
}
// Parse context and variables before sending breadcrumb
return parseVariables(parseContext(breadcrumb));
}
});Analyzing the code
Exploring the code I saw that breadcrumbs are added with attachBreadcrumbToSentry(operation, breadcrumb, options);
- https://github.com/DiederikvandenB/apollo-link-sentry/blob/master/src/SentryLink.ts#L80
- https://github.com/DiederikvandenB/apollo-link-sentry/blob/master/src/SentryLink.ts#L103
Why we need to stringify the object here?
...
transformed.data = stringifyObjectKeys(
transformed.data as Record<string, unknown>,
);
...The question
Why this is necessary? Am I missing some point on serializing data? Is there a way to disable serializing in order to remove our "workaround"?
Metadata
Metadata
Assignees
Labels
No labels
