dd-trace-js
dd-trace-js copied to clipboard
How to Exclude `OPTIONS` Requests from Traces?
Discussed in https://github.com/DataDog/dd-trace-js/discussions/3965
Originally posted by Sangdol January 15, 2024
Our Express server receives many OPTIONS requests due to CORS. These OPTIONS traces are not very informative, and I'd like to exclude them. However, I haven't found a way to do so.
- According to the express plugin document, there appears to be no way to exclude requests based on an HTTP method.
- I attempted to exclude them using
MANUAL_DROPas shown below, but it was ineffective because it added the tag to a new child span instead of the root span.
export const excludeOptionsRequests = async (
req: Request,
res: Response,
next: NextFunction
) => {
const span = tracer.scope().active();
if (req?.method === "OPTIONS") {
span?.setTag(MANUAL_DROP, true);
}
next();
};
Can I add the MANUAL_DROP tag to the root span express.request? Or, is there any other way to exclude OPTIONS requests from traces?
I would also like to know if this is possible, but for the fastify plugin.
Looks like you can set up sampling in Datadog to drop the OPTIONS traces.
https://docs.datadoghq.com/tracing/guide/ignoring_apm_resources/?tab=datadogyaml