Skip to content

Instantly share code, notes, and snippets.

@ericmustin
Created April 29, 2020 11:41
Show Gist options
  • Save ericmustin/041a127b5bdea282ad0d4e8d3f4fc8c8 to your computer and use it in GitHub Desktop.
Save ericmustin/041a127b5bdea282ad0d4e8d3f4fc8c8 to your computer and use it in GitHub Desktop.
example_http_request
// cd into root of this directory
// npm install
// npm install -g http-echo-server
// different terminal window from run `http-echo-server`
// node index.js
const tracer = require('dd-trace').init({debug: false})
const axios = require('axios')
const express = require('express')
async function init(req, res) {
var axresponse = await axios.post('http://localhost:3000?ok=ok', {
firstName: 'Fred',
lastName: 'Flintstone'
})
console.log('response', axresponse.status)
res.status(200).send('Hello World!')
}
const app = express()
const port = 5000
app.get('/', init)
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
// Text Extraction, set debug to true to see extracted context:
// curl -H "X-Datadog-Trace-Id: 3238677264721744442" -H "x-datadog-parent-id: 0" -H "x-datadog-sampling-priority: 1" -H "x-datadog-origin: synthetics" localhost:5000
{
"name": "example_http_request",
"version": "1.0.0",
"description": "",
"main": "example_http_request.js",
"scripts": {
"start": "node example_http_request.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.1",
"express": "^4.17.1",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment