sematext-agent-express
Advanced tools
Weekly downloads
Changelog
Readme
This is the Express.js monitoring and logging agent for Sematext. The following data is collected and shipped to Sematext Cloud / Enterprise:
console.log
ship all logs directly to Sematext Logs with stLogger
sematext-agent-express
npm moduleAfter you sign up to Sematext here, you need to create Apps to store metrics and logs data.
Install the package from the NPM registry.
npm i sematext-agent-express
Make sure to configure your ENVIRONMENT variables before adding sematext-agent-express
. You can do this either by exporting the variables to your environment or by using dotenv
. We suggest you use dotenv
.
If you are using the US region of Sematext Cloud:
export MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
export LOGS_TOKEN=<YOUR_LOGS_TOKEN>
export INFRA_TOKEN=<YOUR_INFRA_TOKEN>
If you are using the EU region of Sematext Cloud:
export REGION=EU
export MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
export LOGS_TOKEN=<YOUR_LOGS_TOKEN>
export INFRA_TOKEN=<YOUR_INFRA_TOKEN>
npm i dotenv
Create a .env
file in the root of your project.
Add this code if you are using the US region of Sematext Cloud:
MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
LOGS_TOKEN=<YOUR_LOGS_TOKEN>
INFRA_TOKEN=<YOUR_INFRA_TOKEN>
Add this code if you are using the EU region of Sematext Cloud:
REGION=EU
MONITORING_TOKEN=<YOUR_MONITORING_TOKEN>
LOGS_TOKEN=<YOUR_LOGS_TOKEN>
INFRA_TOKEN=<YOUR_INFRA_TOKEN>
Make sure to load the environment variables at the top of your JavaScript entry point file. Then require sematext-agent-express
.
The Agent has 3 parts:
stMonitor
- Monitors metrics and sends to Sematext MonitoringstLogger
- A logger based on winston
, that will send logs directly to Sematext LogsstHttpLoggerMiddleware
- Express.js middleware function that will send all HTTP endpoint logs to Sematext Logs// Load env vars
require('dotenv').config()
// require all agents
const { stMonitor, stLogger, stHttpLoggerMiddleware } = require('sematext-agent-express')
// Start monitoring metrics
stMonitor.start()
// ...
// At the top of your routes add the stHttpLoggerMiddleware to send HTTP logs to Sematext
const express = require('express')
const app = express()
app.use(stHttpLoggerMiddleware)
// ...
// Use the stLogger to send all types of logs directly to Sematext
app.get('/api', (req, res, next) => {
stLogger.info('Hello World.')
stLogger.error('Some error.')
res.status(200).send('Hello World.')
})
You can use all parts of the Agent of use them separately. It's all up to you.
The Agents will capture both metrics, logs, and HTTP logs per API endpoint.
Check out our documentation for more information.
Apache 2 - see the LICENSE file.
FAQs
Express.js Monitoring and Logging Agent by Sematext.
The npm package sematext-agent-express receives a total of 174 weekly downloads. As such, sematext-agent-express popularity was classified as not popular.
We found that sematext-agent-express demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.