Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clase crashlytics #3

Merged
merged 5 commits into from
Dec 18, 2023
Merged

Conversation

dam788
Copy link

@dam788 dam788 commented Nov 13, 2023

LINK DE TICKET:

https://janiscommerce.atlassian.net/browse/APPSRN-241

DESCRIPCIÓN DEL REQUERIMIENTO:

Contexto:
Al recibir un error en la consola de firebase crashlytics no hay suficiente información del usuario, lo que a veces hace mas difícil reconocer la causa del error o bien cada vez que se utiliza el método tenemos que repetir data innecesariamente

Necesidad:
Crear una clase que contenga todo lo mismo de antes, pero que pueda recibir por el constructor data para ser inicializada una sola vez, y aunque se utilice el método log y no le pases data, siempre tenga la data del usuario de forma predeterminada.

DESCRIPCIÓN DE LA SOLUCIÓN:

  • Se creó una clase Crashlytics pensando en la ventaja de inicializar la clase una sola vez y poder utilizarla en todo el proyecto. Desde el constructor va a setear userData que espera un objeto (pensando en getUserInfo).

  • A la clase Crashlytics se le agregó los métodos ya existentes:

    • crahsThisApp
    • recordError
    • log
  • Se agregaron los test en un solo archivo.

Actualización pedida por Gonzalo:

  • Trackear los attibutos dentro de RecordError para no depender del .log()

CÓMO SE PUEDE PROBAR?

  • linkee crashlytics con el comando yalc push && yalc publish
  • opcional - si quiere puede utilizar la rama clase-crashlytics en la app WMS.
  • agreguelo en su app con: yalc add @janiscommerce/app-crashlytics y npm i

NOTA: puede armarse una rama de pruebas como LINK, donde ya se probó el funcionamiento del desarrollo. Si quiere generar pruebas propias debe generar un google-services.json nuevo y no lleva mucho tiempo LINK

SCREENSHOTS:

DATOS EXTRA A TENER EN CUENTA:

lib/index.js Outdated
* const error = throw Error('params are required');
* recordError(error, 'Required params')
*/
async recordError(error, jsErrorName) {
Copy link

@GonzaFran GonzaFran Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Según lo conversado, se tiene que agregar un 3er parametro opcional que sean los atributos extra que queremos logear junto a este error. En caso de pasarlos se debe validar que lo recibido sea un objeto valido

lib/index.js Outdated
if (!error) throw new Error('error is required');
if (!!jsErrorName && typeof jsErrorName !== 'string')
throw new Error('incorrect type of jsErrorName');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Según lo conversado, se tiene que agregar la función setAttribute, que se utilizará para darle mayor contexto al error y que, inicialmente, debe tener que enviar la información acumulada en userData. Sumado a esta información, y en caso de que sean validos, se debe agregar la data del objeto recibido como 3er parametro opcional.

Recordar que se debe priorizar los valores de userData por sobre los de los atributos opcionales

lib/index.js Outdated
* crash.log('this is a pda error', {info: {name: 'Pedro', email: 'pedro@email.com', age: '38'}})
*/
log(message, attributes = {}) {
const attributesData = {...this.userData, ...attributes};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acá invertir el orden en que se destructuran las propiedades para darle prioridad a los valores de userData.

const attributesData = { ...attributes, ...this.userData}

Copy link

@GonzaFran GonzaFran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se dejaron comentarios en el PR según lo conversado

Copy link

@Maukr Maukr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dam788 Estuve viendo el package de analytics también un poco, y veo que la estructura de los archivos es un toque diferente.
Por ejemplo, en analytics tienen la clase en un file 'analytics.js' y desde el index lo exportan.
Lo mismo con como se manejan las utils.
Nose si es parte de este desarrollo pero estaría bueno unificar esto

lib/index.js Outdated
const setLogAttributes = async (attributes, key) => {
try {
attributes[key]?.constructor === Object
? await setAttributes(attributes[key])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola @dam788 parece que setAttributes y setAttribute quedaron sin el import

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfecto, ya estan las correcciones.

Copy link
Contributor

@christian97dd christian97dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lo dejo marcado como request changes para organizar una call así podemos refinar un poco mas y dejar las clases crashlytics y analytics similares

Copy link
Contributor

@christian97dd christian97dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dejo un comentario de una validación, el resto lo ví bien

lib/crashlytics.js Outdated Show resolved Hide resolved
@christian97dd christian97dd merged commit 66d86f4 into master Dec 18, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants