Created
March 10, 2022 19:32
-
-
Save codekitchen/2645b88a9db54d65dd9eea7ae3c3e80a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const AWSXRay = require('aws-xray-sdk') | |
let app = express() | |
app.use(AWSXRay.express.openSegment('repro')) | |
// middleware between openSegment() and app routes | |
app.use((req, res, next) => { | |
let seg = AWSXRay.getSegment() | |
res.header('X-Amzn-Trace-Id', seg.trace_id) | |
seg.setUser(req.headers['user-agent']) | |
next() | |
}) | |
app.get('/', (req, res) => { | |
res.json({ ok: true }) | |
}) | |
app.use(AWSXRay.express.closeSegment()) | |
app.listen(3131, () => console.log(`Listening on port 3131...`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment