Search code examples
tracegraphql-jsdatadogtelemetryapm

How to filter out (or ignore) users from DataDog APM telemetry?


I'm trying to ignore traces of all requests from a specific user from our DataDog APM. Using dd-trace for Node.JS and also this plugin. I've been looking at the documentation on custom filters, but I can't get it to work. In the tracer, I have the following:

tracer.use('graphql', {
    source: true,
    signature: false,
    hooks: {
        // here, I add some tags, including the user ID 
        // so I tried: 
        if (user.id === 'id-to-ignore') {
            span.addTags({
                'ignoreThis': true,
            });
        }
        // but I can't filter by this tag either. 
        // Ideally, I would completely remove it here in the code,
        // but I could compromise on adding something we could filter in the DD APM UI
    }
}

Has anybody done this type of filtering successfully? Any ideas would be appreciated.


Solution

  • It's possible to drop a trace directly in the tracer by using a tag. However, this tag needs to be set before any propagation occurs, so adding it in a hook won't work as it would be too late. Instead, it should be added to the active span as soon as the user ID is available like so:

    const { MANUAL_DROP } = require('dd-trace/ext/tags')
    const span = tracer.scope().active()
    
    if (user.id === 'id-to-ignore') {
      span.setTag(MANUAL_DROP, true)
    }