npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

talend-log

v0.111.0

Published

Small wrapper over TraceKit, that allows to inject error reporting as redux-logger middleware

Downloads

52

Readme

Talend-log - error logging library

A small library that provides redux-logger middleware for error logging to be applied as errorTransformer.

Exports redux-logger compatible error logging middleware.

Minimum-config usage:

your configStore.js file:

import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import promise from 'redux-promise-middleware';
import createLogger from 'redux-logger';
import LOGGING_SERVER_URL from 'somewhere';
import initErrorTransformer, { TraceKit } from 'talend-log';

// important part:
const logger = createLogger({ errorTransformer: initErrorTransformer(LOGGING_SERVER_URL) });
// :end of important part

const createStoreWithMiddleware = applyMiddleware(thunkMiddleware, promise(), logger)(createStore);
export default function configureStore(reducer, initialState) {
    const store = createStoreWithMiddleware(reducer, initialState);
    // drop a reference to store instance for later use in errorLogging reportMiddleware
    TraceKit.store = store;
    return store;
}

Advanced config

Look in ./src/errorTransformer.js for jsDoc on each parameter

import LOGGING_SERVER_URL from 'somewhere';
import initErrorTransformer from 'talend-log';

const logger = createLogger({
    errorTransformer: initErrorTransformer(
        LOGGING_SERVER_URL, {
            send: (payload, fetchOptions) => fetch(LOGGING_SERVER_URL, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    '@message': payload
                }),
                ...fetchOptions,
            }),
            payloadMiddleware: payload => Object.assign({
                state: TraceKit.store.getState()
            }, payload),
            fetchOptions: {
                headers: {
                    'Content-Type': 'application/json',
                    custom: 'customData'
                }
            },
            successHandler: (responseText) => {
                alert('yay! ' + responseText)
            },
            retryCount: 5,
            retryTimeout: 3000,
            failedTryHandler: function failedTry(error, payload, transportOpts, attempt) {
                alert('Oh no! ' + error);
                transportOpts.send(transportOpts.payloadMiddleware(payload), transportOpts.fetchOptions, attempt + 1);
            },
            failedReportHandler: (errorResponse) => {
                alert('oh no! ' + errorResponse)
            },
        }, {
            stackTraceLimit: 100,
            linesOfContext: 13,
            rethrowErrorHandler: () => {},
            remoteFetching: true,
            collectWindowErrors: true,
        }
    )
});

Notable details:

  • Once initErrorTransformer is called, listener function is created and registered in TraceKit, then returned.
  • Depending on the parameters you provide, TraceKit.report function may be patched to rethrow no error.
  • transport.send is called with fetchOptions defined on transport.fetchOptions
  • TraceKit.store should be defined in your configStore.js file if you want to attach state to report
  • fetchOptions are merged with Object.assign to default options, so don't expect deepMerge
  • that is also true for default transport and default options objects

Log warnings

If you have some non-critical exceptions that should be reported, but should not break application, then use a possibility to provide handler for better microcontrol:

in your config file:

import LOGGING_SERVER_URL from 'somewhere';
import initErrorTransformer from 'talend-log';
import transportConfig from 'somewhere';

// this:
initErrorTransformer(LOGGING_SERVER_URL, transportConfig, {
    rethrowErrorHandler: (e) => { if (e.type === 'critical') { throw e; } else { console.error(e); } },
})

somewhere in your application:

import { TraceKit } from 'talend-log';

fetch('google.com').catch(errorResponse => TraceKit.report(new Error(errorResponse)));

Under the hood

TraceKit - Cross browser stack traces. https://github.com/csnover/TraceKit