Install

Install the JavaScript SDK.

Terminal
npm install @getpolaris.ai/sdk

Optionally, install the React integration

Polaris is framework-agnostic

The Polaris JavaScript SDK is framework-agnostic. For an easier integration path we do provide additional helpers for integrating with React and Angular applications.

Learn more about our React integration

Connect your application to Polaris

Next, connect your application to Polaris. If you're using our React integration, you can skip this step and follow the instructions in the React integration guide.

Terminal
import { createConnection } from '@getpolaris.ai/sdk';

createConnection({ apiKey: API_KEY }).catch(console.error);

Now, verify that the connection was successful by checking the console. If there is an error connecting to Polaris you will see an error message in the console. If there is not an error, then you're good to go! 🎉

Setup Axios interceptors

Now that you've connected your application to Polaris, you can start sending request measurements to Polaris. To do this, you'll need to setup Axios interceptors.

TS
import axios from 'axios';
import { measure, Instrument } from '@getpolaris.ai/sdk';

let instrument: Instrument;
axios.interceptors.request.use((config) => {
  instrument = measure('request');
  return config;
});

axios.interceptors.response.use(
  (response) => {
    instrument.done();
    return response;
  },
  (error) => {
    instrument.fail({ error });
    return Promise.reject(error);
});

Now, you can use Axios to make requests. All requests made with Axios will send measurements to Polaris.