Skip to content

Instantly share code, notes, and snippets.

@codekitchen
Created March 10, 2022 19:32
Show Gist options
  • Save codekitchen/2645b88a9db54d65dd9eea7ae3c3e80a to your computer and use it in GitHub Desktop.
Save codekitchen/2645b88a9db54d65dd9eea7ae3c3e80a to your computer and use it in GitHub Desktop.
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