node-express-metrics
Express middleware to log metrics traces
This express middleware gathers the metrics information from a metrics object stored in the process domain: process.domain.metrics.
For each request, the middleware initializes the metrics object and, at the end of the response, logs the information stored in the metrics object. It is responsibility of the service logic to enrich this metrics object.
Installation
npm install node-express-metrics
Basic usage
var express = logger = expressDomain = expressTracking = expressMetrics = ; var app = ;app;app;app; app; app;
Options
The express middleware may receive an object with optional settings:
Option | Type | Default | Description |
---|---|---|---|
logger | Object | null | logger module ({info: function(msg, metricsObject)}) |
Full example
It is recommended to use this express middleware in combination with:
- express-domaining. Express middleware to automatically create and destroy a domain.
- express-logging. Express middleware to log each request and response.
- express-tracking. Express middleware to track the request and response storing in the domain the operation, transactionId and correlator.
var express = expressDomain = expressTracking = expressLogging = expressMetrics = logger = ; logger { return processdomain && processdomaintracking;}; var app = ;app;app;app;app; app; app; app;
After launching the previous server, each HTTP request generates 2 log entries to trace the request and response and another log entry with the metrics information:
License
Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.