@lytix/client v4.12.6
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).
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
11 months ago
12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
12 months ago
12 months ago
11 months ago
12 months ago
11 months ago
12 months ago
12 months ago
11 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago