dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

How to Exclude `OPTIONS` Requests from Traces?

Open BridgeAR opened this issue 6 months ago • 1 comments

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_DROP as 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?

BridgeAR avatar May 05 '25 12:05 BridgeAR

I would also like to know if this is possible, but for the fastify plugin.

SenneDirkx avatar Jun 11 '25 14:06 SenneDirkx

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

jbaute avatar Aug 18 '25 09:08 jbaute