Remove particular type of error from Datadog

Viewed 844

Currently, I see error status for all the authentication errors and it feels like a lot of extra noise in the total errors chart. I looked at https://github.com/DataDog/dd-trace-js/pull/909 and tried to use the custom execute provided for graphql

import ddTrace from 'dd-trace'
let tracer = ddTrace.init({
  debug: false
}) // initialized in a different file to avoid hoisting.

tracer.use('graphql', {
  hooks: {
    execute: (span, args, res) => {
        if (res && res.errors && res.errors[0] && res.errors[0].status !== 403) {
            span?.setTag('error', res.errors)
        }
    }
  }
})
export default tracer

But still, res with only 403 error is going into error status. Please help me with how can I achieve this.

1 Answers

Update: I found this bit of code in the tracing client repo:

tracer.use('graphql', {
  hooks: {
    execute: (span, args, res) => {
        if (res?.errors?.[0]?.status === 403) { // assuming "status" is a number
            span?.setTag('error', null) // remove any error set by the tracer
        }
    }
  }
})

https://github.com/DataDog/dd-trace-js/issues/1249

maybe it would help


Old message:

Never mind. seems like my solution is only for express, graphql doesn't support that property

You probably want to just modify the validateStatus property in the http module:

Callback function to determine if there was an error. It should take a status code as its only parameter and return true for success or false for errors

https://datadoghq.dev/dd-trace-js/interfaces/plugins.http.html#validatestatus

As an example you should be able to mark 403s as not be errors with something like this:

const tracer = require('dd-trace').init();
tracer.use('express', {
  validateStatus: code => code < 400 && code != 403
})
Related