Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gadget-trace-middleware

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gadget-trace-middleware - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

34

index.js

@@ -5,3 +5,6 @@ const axios = require('axios')

module.exports = function (config) {
const baseUrl = `http${config.https ? 's' : ''}://${config.host}:${config.port || 4368}`
const publicUrl = `http${config.https ? 's' : ''}://${config.publicHost || config.host}:${config.port || 4368}`
return function (req, res, next) {
const secretKeys = req.get('x-gt-secret-keys') ? req.get('x-gt-secret-keys').split(',') : []
const requestId = req.requestId || res.locals.requestId || req.get('x-request-id') || uuid()

@@ -19,4 +22,20 @@ const requestUid = req.requestUid || res.locals.requestUid || uuid()

if (config.secret && !secretKeys.includes(config.secret)) {
req.gt.wrap = () => {}
req.gt.log = () => {}
return next()
}
res.setHeader('x-gt-host', publicUrl)
const startTime = process.hrtime()
req.gt.vars = function gadgetTraceVars (vars) {
let variables = []
for (let name in vars) {
variables.push({ name, value: vars[name] })
}
req.gt.log({ variables }, requestUid)
}
req.gt.log = function gadgetTraceLog (data, requestUid = null) {

@@ -33,7 +52,12 @@ if (!requestUid) {

}
if (config.secret) {
data.secret = config.secret
}
axios({
method: 'post',
url: `http://${config.host}:${config.port || 4368}/request/${requestId}`,
url: `${baseUrl}/request/${requestId}`,
data: data
}).catch(() => {})
}).catch(() => {
// TODO log the failure
})
}

@@ -63,7 +87,9 @@

req.gt.wrap = function (fn, name, depth = 0, maxDepth = 4) {
req.gt.wrap = function (fn, name, options = {}, maxDepth = 4, depth = 0) {
if (fn !== null && typeof fn === 'object') {
if (depth >= maxDepth) return
Object.keys(fn).forEach(key => {
const wrapped = req.gt.wrap(fn[key], `${name}.${key}`, depth + 1, maxDepth)
if (options.blacklist && new RegExp(options.blacklist).test(key)) return
if (options.whitelist && !(new RegExp(options.whitelist).test(key))) return
const wrapped = req.gt.wrap(fn[key], `${name}.${key}`, options, maxDepth, depth + 1)
if (typeof fn[key] === 'function') {

@@ -70,0 +96,0 @@ fn[key] = wrapped

2

package.json
{
"name": "gadget-trace-middleware",
"version": "1.0.0",
"version": "1.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc