const handleError = err => { this.emit('error', request, err); const { message, stack } = err; span.setTag(Tags.ERROR, true); span.log({ message, stack }); if (shouldWriteHead) { shouldWriteHead = false; let statusCode = 500; if (err.code === TEMPLATE_NOT_FOUND) { statusCode = 404; } span.setTag(Tags.HTTP_STATUS_CODE, statusCode); response.writeHead(statusCode, responseHeaders); // To render with custom error template if (typeof err.presentable === 'string') { response.end(`${err.presentable}`); } else { response.end(INTERNAL_SERVER_ERROR); } span.finish(); } else { contentLengthStream.end(); } }
span.setTag(Tags.HTTP_STATUS_CODE, 500); response.writeHead(500, responseHeaders); resultStream.pipe(contentLengthStream).pipe(response);
test('tag: result', setup(function (t) { const tracer = new Tracer(getAgent()) const span = tracer.startSpan() span.setTag('result', 'foo') t.equal(span._span.result, 'foo') t.equal(span._span._labels, null) t.end() }))
const sayHello = helloTo => { const span = tracer.startSpan("say-hello"); span.setTag("hello-to", helloTo); const helloStr = `Hello, ${helloTo}!`; span.log({ event: "string-format", value: helloStr, }); console.log(helloStr); span.log({ event: "print-string" }); span.finish(); }
/* GET readiness probe response. */ router.get('/ready', async function(req, res, next) { const span = tracer.startSpan('redis_ping') try { let pingval = await db.ping() if (pingval) { res.send('yes'); span.setTag("RedisPing", true) span.finish() } else { span.setTag("RedisPing", false) span.finish() res.status(500).json({ error: "redis.ping was false" }) } } catch (error) { span.setTag(Tags.ERROR, error.toString()) span.finish() res.status(500).json({ error: error.toString() }) } });
value: error.toString(), }); span.setTag(Tags.ERROR, true) span.finish(); reject(error);
test('tag: type', setup(function (t) { const tracer = new Tracer(getAgent()) const span = tracer.startSpan() span.setTag('type', 'foo') t.equal(span._span.type, 'foo') t.equal(span._span._labels, null) t.end() }))
test('tag: http.status_code', setup(function (t) { const tracer = new Tracer(getAgent()) const span = tracer.startSpan() span.setTag('http.status_code', 200) t.equal(span._span.result, 'HTTP 2xx') t.equal(span._span._labels, null) t.end() }))