weixin_39634067
weixin_39634067
2020-12-25 22:11

node_modules/zipkin-transport-http/src/HttpLogger.js.

Running a Node application works fine for sending traces. However if I compile this to a minified file in Webpack, we lose the 'this' context after the interval when trying to do the fetch call for HttpLogger.


TypeError: this.fetchImplementation is not a function
    at HttpLogger.processQueue (/Users/shaun/nutmeg/nm-node-poc-web/build/api.bundle.js:51368:16)
    at Timeout._onTimeout (/Users/shaun/nutmeg/nm-node-poc-web/build/api.bundle.js:51301:13)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at unrefdHandle (timers.js:520:7)
    at Timer.processTimers (timers.js:222:12)
Waiting for the debugger to disconnect...
[nodemon] app crashed - waiting for file changes before starting...

    var timer = setInterval(function () {
      _this.processQueue();
    }, httpInterval);

 key: "processQueue",
    value: function processQueue() {
      var _this2 = this;

      var self = this;

      if (self.queue.length > 0) {
        var postBody = "[".concat(self.queue.join(','), "]");
        var fetchOptions = {
          method: 'POST',
          body: postBody,
          headers: self.headers,
          timeout: self.timeout,
          agent: self.agent
        };
        this.fetchImplementation(self.endpoint, fetchOptions).then(function (response) {
          if (response.status !== 202 && response.status !== 200) {
            var err = 'Unexpected response while sending Zipkin data, status:' + "".concat(response.status, ", body: ").concat(postBody);
            if (self.errorListenerSet) _this2.emit('error', new Error(err));else _this2.log.error(err);
          } else {
            _this2.emit('success', response);
          }
        })["catch"](function (error) {
          var err = "Error sending Zipkin data ".concat(error);
          if (self.errorListenerSet) _this2.emit('error', new Error(err));else _this2.log.error(err);
        });
        self.queue.length = 0;
        self.queueBytes = 0;
      }
    }
  }]);

该提问来源于开源项目:openzipkin/zipkin-js

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39634067 weixin_39634067 4月前

    Suggested solution

    
    
          const fetchImpl = this.fetchImplementation || defaultFetchImpl;
    
          fetchImpl(self.endpoint, fetchOptions).then((response) => {
    
    点赞 评论 复制链接分享
  • weixin_39657575 weixin_39657575 4月前

    Would you please come up with a PR for this?

    点赞 评论 复制链接分享
  • weixin_39657575 weixin_39657575 4月前

    cc -anachoreta

    点赞 评论 复制链接分享
  • weixin_39657575 weixin_39657575 4月前

    Got a question, does this mean we will fallback to the default after the first send even if a valid fetch implementation has been passed? If that is the case then maybe it is worth to add a note to it or just use the default impl when compiling to webpack? cc

    点赞 评论 复制链接分享

相关推荐