segmentio / analytics-node

The hassle-free way to integrate analytics into any node application.

Home Page:https://segment.com/libraries/node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: the options.axiosInstance is no longer used

kylezeeuwen opened this issue · comments

Courteous Hello

Thanks for the code and for segment ! Great product, been using it on a team plan for years at https://www.console.com.au/

Special Hello to Pooya

Hi @pooyaj we studied in the same research lab at UBC many years ago. Hope things are well 👍

Bug Overview

The issue is that the optional axiosInstance passed as an option in the constructor is no longer being used, so a callee can no longer configure a custom axios instance.

I will not include steps to reproduce as you can pick out the bug by looking at the code in the constructor.

It looks like this issue was introduced in this recent commit : 5d925f6.

Details

We have this code that allows the callee to pass in an axiosInstance and/or some axiosConfig:

https://github.com/segmentio/analytics-node/blob/master/index.js#L41

let axiosInstance = options.axiosInstance
    if (axiosInstance == null) {
      axiosInstance = axios.create(options.axiosConfig)
    }
    this.axiosInstance = axiosInstance

A few lines later we setup this.axiosClient

https://github.com/segmentio/analytics-node/blob/master/index.js#L56

this.axiosClient = axios.create()
    axiosRetry(this.axiosClient, {
      retries: options.retryCount || 3,
      retryCondition: this._isErrorRetryable,
      retryDelay: axiosRetry.exponentialDelay
    })

When we actually make network requests we use this.axiosClient not the configurable this.axiosInstance
https://github.com/segmentio/analytics-node/blob/master/index.js#L282

    this.axiosClient(req)
      .then(() => done())
      .catch(err => {
        if (err.response) {
          const error = new Error(err.response.statusText)
          return done(error)
        }

        done(err)
      })
  }

look like someone has already picked this up https://github.com/segmentio/analytics-node/pull/271/files

@kylezeeuwen Hello old friend 🙌 Good to see you here after all these years and glad that you are enjoying the Segment product. Let me merge the above PR and push a new release!

Yup. Already tackled :)

released 4.0.1 💥 Thanks @pbassut for the fix!