question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: decorateRequest is REMOVED

See original GitHub issue

According to https://www.npmjs.com/package/express-http-proxy

Upgrade to 1.0, transition guide and breaking changes

decorateRequest has been REMOVED, and will generate an error when called. See proxyReqOptDecorator and proxyReqBodyDecorator.
Error: decorateRequest is REMOVED; use proxyReqOptDecorator and proxyReqBodyDecorator instead.  see README.md
   at resolveOptions (/usr/src/app/node_modules/express-http-proxy/lib/resolveOptions.js:21:11)
   at new Container (/usr/src/app/node_modules/express-http-proxy/lib/scopeContainer.js:27:14)
   at handleProxy (/usr/src/app/node_modules/express-http-proxy/index.js:39:21)
   at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:312:13)
   at /usr/src/app/node_modules/express/lib/router/index.js:280:7
   at param (/usr/src/app/node_modules/express/lib/router/index.js:349:14)
   at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
   at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
   at next (/usr/src/app/node_modules/express/lib/router/index.js:271:10)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eirslettcommented, Nov 9, 2017

I guess it should be possible to detect if the function exists or not - and then decide which API to use.

0reactions
DarkBitzcommented, Nov 23, 2019

That would be the update for v1.16.0. For all who are waiting for a fix. I’ve avoided function definitions in functions as well as possible, this is terrible to read.

const {Request, Annotation} = require('zipkin');
const url = require('url');

class ExpressHttpProxyInstrumentation {

  constructor({tracer, serviceName = tracer.localEndpoint.serviceName, remoteServiceName}) {
    this.tracer = tracer;
    this.serviceName = serviceName;
    this.remoteServiceName = remoteServiceName;
  }

  decorateAndRecordRequest(serverReq, proxyReq, serverTraceId) {

    return this.tracer.letId(serverTraceId, () => {
      const clientTraceId = this.tracer.createChildId();
      this.tracer.setId(clientTraceId);

      const proxyReqWithZipkinHeaders = Request.addZipkinHeaders(proxyReq, clientTraceId);
      Object.defineProperty(
        serverReq, 
        '_trace_id_proxy',
        {
          configurable: false, 
          get: () => clientTraceId
        }
      );
      this._recordRequest(proxyReqWithZipkinHeaders);

      return proxyReqWithZipkinHeaders;
    });
  }

  _recordRequest(proxyReq) {
    this.tracer.recordServiceName(this.serviceName);
    this.tracer.recordRpc(proxyReq.method.toUpperCase());
    this.tracer.recordBinary('http.path', url.parse(proxyReq.path).pathname);
    this.tracer.recordAnnotation(new Annotation.ClientSend());
    if (this.remoteServiceName) {
      this.tracer.recordAnnotation(new Annotation.ServerAddr({
        serviceName: this.remoteServiceName,
        port: parseInt(proxyReq.port)
      }));
    }
  }

  recordResponse(rsp, clientTraceId) {
    this.tracer.letId(clientTraceId, () => {
      this.tracer.recordBinary('http.status_code', rsp.statusCode.toString());
      this.tracer.recordAnnotation(new Annotation.ClientRecv());
    });
  }
}

const wrapProxyReqOptDecorator = (instrumentation, proxyReqOptDecorator) => {

  return (proxyReqOpts, serverReq) => {
    const serverTraceId = serverReq._trace_id;
    let wrappedProxyReqOpts = proxyReqOpts;

    if (typeof proxyReqOptDecorator === 'function') {
      tracer.letId(serverTraceId, () => {
          wrappedProxyReqOpts = proxyReqOptDecorator(proxyReqOpts, serverReq);
      });
    }

    return instrumentation.decorateAndRecordRequest(serverReq, wrappedProxyReqOpts, serverTraceId);
  };
}

const wrapUserResHeaderDecorator = (instrumentation, userResHeaderDecorator) => {

  return (headers, userReq, userRes, proxyReq, proxyRes) => {
    const serverTraceId = userReq._trace_id;
    let wrappedHeaders = headers;

    if (typeof userResHeaderDecorator === 'function') {
      tracer.letId(serverTraceId, () => {
        wrappedHeaders = userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes)
      }); 
    }
    instrumentation.recordResponse(proxyRes, userReq._trace_id_proxy);

    return wrappedHeaders;
  };
}

const wrapProxy = (proxy, {tracer, serviceName, remoteServiceName}) => {

  return function zipkinProxy(host, options = {}) {

    const instrumentation = new ExpressHttpProxyInstrumentation({tracer, serviceName, remoteServiceName});
    const wrappedOptions = options;

    const {proxyReqOptDecorator} = wrappedOptions;
    wrappedOptions.proxyReqOptDecorator = wrapProxyReqOptDecorator(instrumentation, proxyReqOptDecorator);

    const {userResHeaderDecorator} = wrappedOptions;
    wrappedOptions.userResHeaderDecorator = wrapUserResHeaderDecorator(instrumentation, userResHeaderDecorator);

    return proxy(host, wrappedOptions);
  };
}

module.exports = wrapProxy;
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript - Fastify
¶Errors. fastify.FastifyError. src. FastifyError is a custom error object that includes status code and validation results. It extends the Node.js ...
Read more >
express-http-proxy - npm
decorateRequest has been REMOVED, and will generate an error when called. See proxyReqOptDecorator and decorateProxyReqBody .
Read more >
NestJS/Fastify Cookie Unhandled Promise Rejection Warning
I'm trying to get fastify-cookie working on my NestJS project and I am receiving the following error:.
Read more >
Express-http-proxy NPM - npm.io
By default, express-http-proxy will pass any errors except ECONNRESET to next, ... decorateRequest has been REMOVED, and will generate an error when called....
Read more >
Getting Started with Fastify Node.js Framework and Faunadb
Add folder and a file as errors/FaunaError.js and paste the following ... decorateRequest() method which lets Fastify know that our request ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found