4.12.6 • Published 9 months ago

@lytix/client v4.12.6

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Environment Variables

The following environment variables are required to run the Lytix client.

  • LX_API_KEY: The API key for the Lytix API. This is required to send data to the Lytix API.

The followig environment variables are optional.

  • LX_BASE_URL: The base URL for the Lytix API. This is required to send data to the Lytix API.

Configuration

There are multiple ways to use MM. Please follow the instructions relevent to what you'd like to setup.

Express Middleware

First make sure you have setup your httpContext middleware. This should be at the towards the top of your middleware stack, before authentication.

/**
 * HTTP Context middlware
 */
app.use(httpContext.middleware);

Then you can use the ErrorRequestHandler middleware.

/**
 * Lytix middleware
 */
app.use(ErrorRequestHandler);

But wait, there's more. You can define a logger, that can be passed to our middleware that can be used to trace a users request.

import { MMLogger, ErrorRequestHandler } from "@lytix/client";

export const logger = new MMLogger("main");

/**
 * Your custom auth middleware unrelated to lytix
 */
app.use(async (req, res, next) => {
  logger.info(`New request for path: ${req.path} with method: ${req.method}`);

  /**
   * Set metadata for the logger
   */
  logger.setMetadata({
    userId: "1234",
    authed: false,
  });
  next();
});

app.get(
  "/randomEndpoint",
  async (req, res) => {
    ...
    logger.info(`We are deeply nested in some functions`);
    throw new Error(`Uh oh`);
  }
);

/**
 * Lytix middleware
 */
app.use(ErrorRequestHandler);

Not only will you get alerts on the error, but you'll also automatically log the userId whenever you call logger.info/debug/error/warn

> [userId=1234;authed=false] We are deeply nested in some functions

This uses the http context to maintain the metadata state. This means as long as you use the exported logger, no matter where you are logging you'll always have the userId and authed flag (in this example).

4.12.3

9 months ago

4.12.4

9 months ago

4.12.5

9 months ago

4.12.6

9 months ago

4.12.0

9 months ago

4.12.1

9 months ago

4.12.2

9 months ago

4.10.0

10 months ago

4.11.0

10 months ago

4.11.1

10 months ago

4.11.2

10 months ago

4.11.3

10 months ago

4.9.3

10 months ago

4.9.0

10 months ago

4.9.2

10 months ago

4.9.1

10 months ago

4.8.0

10 months ago

4.7.1

10 months ago

4.7.0

10 months ago

4.6.1

10 months ago

4.6.0

10 months ago

4.4.2

10 months ago

4.5.0

10 months ago

4.5.2

10 months ago

4.5.1

10 months ago

4.1.8

11 months ago

4.1.7

11 months ago

4.1.9

11 months ago

2.0.0

1 year ago

3.0.0

1 year ago

4.4.1

11 months ago

4.0.5

12 months ago

4.4.0

11 months ago

4.0.4

12 months ago

4.0.6

12 months ago

4.0.1

12 months ago

4.0.0

12 months ago

4.0.3

12 months ago

4.2.0

11 months ago

4.0.2

12 months ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.3

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.7

1 year ago

2.1.0

1 year ago

3.1.0

1 year ago

4.3.2

11 months ago

4.1.4

12 months ago

4.1.3

12 months ago

4.3.4

11 months ago

4.1.6

12 months ago

4.3.3

11 months ago

4.1.5

12 months ago

4.1.0

12 months ago

4.3.0

11 months ago

4.1.2

12 months ago

4.1.1

12 months ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago