CEC-287, CEC-279 Fix car connections and add logger (#61)

* Display cars if connection statuses call errors

* Fix connection error
Add logger
This commit is contained in:
John Wu
2021-06-23 16:33:35 -07:00
committed by GitHub
parent a3b6b01bf3
commit f4e4261d01
4 changed files with 170 additions and 113 deletions

View File

@@ -1,4 +1,5 @@
import React, { useContext, useState } from "react";
import { logger } from "../../services/monitoring";
import api from "../../services/vehicles";
const VehicleContext = React.createContext();
@@ -97,15 +98,19 @@ export const VehicleProvider = ({ children }) => {
};
const addConnections = async (cars, token) => {
const vins = cars.map((car) => car.vin);
const result = await api.getConnections(vins, token);
try {
const vins = cars.map((car) => car.vin);
const result = await api.getConnections(vins, token);
if (result.error) {
throw new Error(`Get connections error. ${result.message}`);
if (result.error) {
throw new Error(`Get connections error. ${result.message}`);
}
cars.forEach((car) => {
car.connected = result[car.vin] || false;
});
} catch (e) {
logger.error(e.stack);
}
cars.forEach((car) => {
car.connected = result[car.vin] || false;
});
};
const getConnections = async (vins, token) => {

View File

@@ -1,12 +1,28 @@
import { datadogRum } from '@datadog/browser-rum';
import { datadogLogs } from "@datadog/browser-logs";
const applicationId = '8ecd160c-ad5c-4e06-8d88-3a6b89833246';
const clientToken = 'pubeb25449bb91773fc993855c7378e375a';
const site = 'datadoghq.com';
datadogRum.init({
applicationId: '8ecd160c-ad5c-4e06-8d88-3a6b89833246',
clientToken: 'pubeb25449bb91773fc993855c7378e375a',
site: 'datadoghq.com',
applicationId,
clientToken,
site,
service:'ota-portal',
// Specify a version number to identify the deployed version of your application in Datadog
// version: '1.0.0',
sampleRate: 100,
trackInteractions: true
});
});
datadogLogs.init({
clientToken,
site,
forwardErrorsToLogs: true,
sampleRate: 100,
});
const logger = datadogLogs.logger;
export { logger };