-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.48.0
Framework Version
Node v18.20.4
Link to Sentry event
No response
Reproduction Example/SDK Setup
const Sentry = require("@sentry/node");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
Sentry.init({
dsn: "our-dsn-string",
integrations: [
nodeProfilingIntegration(),
],
tracesSampler: (samplingContext) => {
try {
// Ensure headers and referer are defined before accessing them
const headers = samplingContext?.normalizedRequest?.headers;
const referer = headers?.referer;
if (referer) {
if (referer.includes('frontend-url')) {
return 1.0; // Capture 100% of transactions for this referer
} else {
return 0.0; // Ignore transactions for other referers
}
}
// Default to 1.0 if referer is undefined
return 1.0;
} catch (error) {
console.error('Error in tracesSampler:', error);
return 0.0; // Safely ignore errors by defaulting to 0.0
}
},
// Tracing
tracesSampleRate: 1.0, // Capture 100% of the transactions
beforeSend(event){
// console.log(JSON.stringify(event.request.headers, null, 2));
if (event.request?.headers?.["referer"]?.includes("frontend-url")) {
console.log(`SENDING THIS REQUEST`)
return event;
}
return null;
}
});
// Manually call startProfiler and stopProfiler
// to profile the code in between
Sentry.profiler.startProfiler();
// Starts a transaction that will also be profiled
Sentry.startSpan({
name: "My First Transaction",
}, () => {
// the code executing inside the transaction will be wrapped in a span and profiled
});
// Calls to stopProfiling are optional - if you don't stop the profiler, it will keep profiling
// your application until the process exits or stopProfiling is called.
Sentry.profiler.stopProfiler();
Steps to Reproduce
- Hit an error from frontend ("frontend-url").
- Hit an error from another frontend to the same backend.
- Only the error originated from "frontend-url" gets logged onto Sentry.
- The problem is with CPU usage. Earlier, when we first integrated Sentry into our backend, our EC2 instances CPU usage shot through the roof and we had to disable it.
- We then implemented the above checks to make sure that the errors that are not being originated from "frontend-url" don't even get sampled, thus reducing the CPU usage.
- But
tracesSampler
alone doesn't stop errors from going to Sentry, so I implementedbeforeSend()
with a check to not send the errors and it worked. - But the problem with this is the CPU usage hasn't reduced and when we deployed it again, the CPU usage shot through the roof again.
- I am guessing that
beforeSend()
is not stopping the errors that are not originated from the "frontend-url" from getting sampled but it is filtering them out after sampling them which explains why the CPU usage is still high even after this.
FYI: The incoming requests from the "frontend-url" are 10 out of 1000 total requests so, if we are only sampling those then CPU usage should have been reduced.
This is the only thing stopping us from deploying Sentry onto production which is very important and urgent for us.
Expected Result
- We only need the errors originated from "frontend-url" to be sampled, reducing the CPU usage.
Actual Result
Metadata
Metadata
Assignees
Labels
Projects
Status
Waiting for: Community