title: Datadog TypeError: Cannot set property 'error' of undefined
body: <p>I am getting infinite error logs from dd-trace If the code throws any exception.</p>
  <p>App.js</p>
  <pre><code>const tracer = require('dd-trace');
  if(process.env.TRACE_REQUIRED === &quot;true&quot;){
      tracer.init();
      tracer.use('http', {
          blocklist: ['/health', '/ping']
      })
  }
  const express = require('express');
  const app = express();
  ...
  </code></pre>
  <p>Express.js middleware function:</p>
  <pre><code>function checkUser(req, res){
          let user = await db.users.findOne({_id: &quot;xyz&quot;});
          if(!user) {
              errorUtils.throwError('User not found', 400);
          }
          req.user = user;
      }
  
      next();
  }
  </code></pre>
  <p>errorUtils.js</p>
  <pre><code>exports.throwError = throwError;
  function throwError(message, code) {
      let error = new Error(message);
      if (code) {
          error.code = code;
      }
      throw error;
  }
  </code></pre>
  <p>When there is no user found in the MongoDB query, dd-trace is started throwing lot error logs infinitely like <code>Cannot set property 'error' of undefined</code> etc.
  The problem is not only in the middleware function, but wherever I am using the errorUtils.throwError('XYZ', 400); I am getting the same errors.</p>
  <p>NodeJS version : 12.x</p>
  <p>dd-trace version: tried 2.8.0 as well as 2.12.0 But same errors.</p>
  <p>Could anyone help me to resolve this?</p>
  <p><a href="https://i.stack.imgur.com/u5a3o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u5a3o.png" alt="enter image description here" /></a></p>