-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (24 loc) · 905 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const express = require("express");
const cors = require('cors')
const PORT = process.env.PORT || "5555";
const app = express();
const { trace, SpanStatusCode } = require("@opentelemetry/api");
app.use(cors());
app.use(express.json())
app.all("/", (req, res) => {
// Get the current span from the tracer
const span = trace.getActiveSpan();
err = new Error("This is a test error");
// recordException converts the error into a span event.
span.recordException(err);
span.setAttribute('attribute1', 'value1');
// Update the span status to failed.
span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
res.json({ method: req.method, message: "Hello World", ...req.body });
});
app.get('/404', (req, res) => {
res.sendStatus(404);
})
app.listen(parseInt(PORT, 10), () => {
console.log(`Listening for requests on http://localhost:${PORT}`);
});