Gathering detailed insights and metrics for @google-cloud/error-reporting
Gathering detailed insights and metrics for @google-cloud/error-reporting
Gathering detailed insights and metrics for @google-cloud/error-reporting
Gathering detailed insights and metrics for @google-cloud/error-reporting
google-cloud-report-error
Report error to Google Cloud Error Reporting if it meets certain criteria.
@relaycorp/pino-cloud
Pino integration for cloud logging services like Google Cloud Logging
node-red-contrib-gcp-error-reporting
A NodeRED plugin, written in Node.js, enables the rules engine to report exceptions to GCP Error Reporting.
error-reporting-client
JavaScript client for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting/docs/grouping-errors).
Node.js client for Stackdriver Error Reporting: Count, analyze and aggregate the crashes in your running cloud services.
npm install @google-cloud/error-reporting
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (98.4%)
JavaScript (1.03%)
Python (0.57%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
88 Stars
518 Commits
28 Forks
45 Watchers
113 Branches
145 Contributors
Updated on Jun 18, 2025
Latest Version
3.0.5
Package Id
@google-cloud/error-reporting@3.0.5
Unpacked Size
190.83 kB
Size
42.91 kB
File Count
42
NPM Version
6.14.16
Node Version
12.22.12
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
30
Node.js idiomatic client for Error Reporting.
Error Reporting aggregates and displays errors produced in your running cloud services.
A comprehensive list of changes in each version may be found in the CHANGELOG.
Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
1npm install @google-cloud/error-reporting
This module provides custom Error Reporting support for Node.js applications. Error Reporting is a feature of Google Cloud Platform that allows in-depth monitoring and viewing of errors reported by applications running in almost any environment.
However, note that @google-cloud/logging-winston and @google-cloud/logging-bunyan automatically integrate with the Error Reporting service for Error objects logged at severity error
or higher, for applications running on Google Cloud Platform.
Thus, if you are already using Winston or Bunyan in your application, and don't need custom error reporting capabilities, you do not need to use the @google-cloud/error-reporting
library directly to report errors to the Error Reporting Console.
Here's an introductory video that provides some more details:
The reportMode
configuration option is used to specify when errors are reported to the Error Reporting Console. It can have one of three values:
'production'
(default): Only report errors if the NODE_ENV environment variable is set to "production".'always'
: Always report errors regardless of the value of NODE_ENV.'never'
: Never report errors regardless of the value of NODE_ENV.The reportMode
configuration option replaces the deprecated ignoreEnvironmentCheck
configuration option. If both the reportMode
and ignoreEnvironmentCheck
options are specified, the reportMode
configuration option takes precedence.
The ignoreEnvironmentCheck
option should not be used. However, if it is used, and the reportMode
option is not specified, it can have the values:
false
(default): Only report errors if the NODE_ENV environment variable is set to "production".true
: Always report errors regardless of the value of NODE_ENV.See the Configuration section to learn how to specify configuration options.
The following code snippet lists available configuration options. All configuration options are optional.
1const {ErrorReporting} = require('@google-cloud/error-reporting');
2
3// Using ES6 style imports via TypeScript or Babel
4// import {ErrorReporting} from '@google-cloud/error-reporting';
5
6// Instantiates a client
7const errors = new ErrorReporting({
8 projectId: 'my-project-id',
9 keyFilename: '/path/to/keyfile.json',
10 credentials: require('./path/to/keyfile.json'),
11 // Specifies when errors are reported to the Error Reporting Console.
12 // See the "When Errors Are Reported" section for more information.
13 // Defaults to 'production'
14 reportMode: 'production',
15 // Determines the logging level internal to the library; levels range 0-5
16 // where 0 indicates no logs should be reported and 5 indicates all logs
17 // should be reported.
18 // Defaults to 2 (warnings)
19 logLevel: 2,
20 serviceContext: {
21 service: 'my-service',
22 version: 'my-service-version'
23 }
24});
1const {ErrorReporting} = require('@google-cloud/error-reporting'); 2 3// Using ES6 style imports via TypeScript or Babel 4// import {ErrorReporting} from '@google-cloud/error-reporting'; 5 6// Instantiates a client 7const errors = new ErrorReporting(); 8 9// Use the error message builder to customize all fields ... 10const errorEvt = errors.event() 11 .setMessage('My error message') 12 .setUser('root@nexus'); 13errors.report(errorEvt, () => console.log('done!')); 14 15// or just use a regular error ... 16errors.report(new Error('My error message'), () => console.log('done!')); 17 18// or one can even just use a string. 19errors.report('My error message');
The stack trace associated with an error can be viewed in the error reporting console.
errors.report
method is given an ErrorMessage
object built using the errors.event
method, the stack trace at the point where the error event was constructed will be used.errors.report
method is given an Error
object, the stack trace where the error was instantiated will be used.errors.report
method is given a string, the stack trace at the point where errors.report
is invoked will be used.1const express = require('express'); 2 3const {ErrorReporting} = require('@google-cloud/error-reporting'); 4 5// Using ES6 style imports via TypeScript or Babel 6// import {ErrorReporting} from '@google-cloud/error-reporting'; 7 8// Instantiates a client 9const errors = new ErrorReporting(); 10 11const app = express(); 12 13app.get('/error', (req, res, next) => { 14 res.send('Something broke!'); 15 next(new Error('Custom error message')); 16}); 17 18app.get('/exception', () => { 19 JSON.parse('{\"malformedJson\": true'); 20}); 21 22// Note that express error handling middleware should be attached after all 23// the other routes and use() calls. See [express docs][express-error-docs]. 24app.use(errors.express); 25 26app.listen(3000);
1const hapi = require('hapi'); 2const {ErrorReporting} = require('@google-cloud/error-reporting'); 3 4// Using ES6 style imports via TypeScript or Babel 5// import {ErrorReporting} from '@google-cloud/error-reporting'; 6 7// Instantiates a client 8const errors = new ErrorReporting(); 9 10const server = new hapi.Server(); 11server.connection({ port: 3000 }); 12server.start(); 13 14server.route({ 15 method: 'GET', 16 path: '/error', 17 handler: (request, reply) => { 18 reply('Something broke!'); 19 throw new Error('Custom error message'); 20 } 21}); 22 23server.register(errors.hapi);
1const Koa = require('koa'); 2const {ErrorReporting} = require('@google-cloud/error-reporting'); 3 4// Using ES6 style imports via TypeScript or Babel 5// import {ErrorReporting} from '@google-cloud/error-reporting'; 6 7// Instantiates a client 8const errors = new ErrorReporting(); 9 10const app = new Koa(); 11 12app.use(errors.koa); 13 14app.use(function *(next) { 15 //This will set status and message 16 this.throw('Error Message', 500); 17}); 18 19// response 20app.use(function *(){ 21 this.body = 'Hello World'; 22}); 23 24app.listen(3000);
1const restify = require('restify'); 2const {ErrorReporting} = require('@google-cloud/error-reporting'); 3 4// Using ES6 style imports via TypeScript or Babel 5// import {ErrorReporting} from '@google-cloud/error-reporting'; 6 7// Instantiates a client 8const errors = new ErrorReporting(); 9 10function respond(req, res, next) { 11 next(new Error('this is a restify error')); 12} 13 14const server = restify.createServer(); 15 16server.use(errors.restify(server)); 17server.get('/hello/:name', respond); 18server.head('/hello/:name', respond); 19 20server.listen(3000);
Unhandled Rejections are not reported by default. The reporting of unhandled rejections can be enabled using the reportUnhandledRejections
configuration option. See the Configuration section for more details.
If unhandled rejections are set to be reported, then, when an unhandled rejection occurs, a message is printed to standard out indicated that an unhandled rejection had occurred and is being reported, and the value causing the rejection is reported to the error-reporting console.
Uncaught exceptions are not reported by default. It is recommended to process uncaughtException
s for production-deployed applications.
Note that uncaught exceptions are not reported by default because to do so would require adding a listener to the uncaughtException
event. Adding such a listener without knowledge of other uncaughtException
listeners can cause interference between the event handlers or prevent the process from terminating cleanly. As such, it is necessary for uncaughtException
s to be reported manually.
1const {ErrorReporting} = require('@google-cloud/error-reporting'); 2 3// Using ES6 style imports via TypeScript or Babel 4// import {ErrorReporting} from '@google-cloud/error-reporting'; 5 6// Instantiates a client 7const errors = new ErrorReporting(); 8 9process.on('uncaughtException', (e) => { 10 // Write the error to stderr. 11 console.error(e); 12 // Report that same error the Cloud Error Service 13 errors.report(e); 14});
More information about uncaught exception handling in Node.js and what it means for your application can be found here.
You may use an API key in lieu of locally-stored credentials. Please see this document on how to set up an API key if you do not already have one.
Once you have obtained an API key, you may provide it as part of the Error Reporting instance configuration:
1const {ErrorReporting} = require('@google-cloud/error-reporting');
2
3// Using ES6 style imports via TypeScript or Babel
4// import {ErrorReporting} from '@google-cloud/error-reporting';
5
6// Instantiates a client
7const errors = new ErrorReporting({
8 projectId: '{your project ID}',
9 key: '{your api key}'
10});
If a key is provided, the module will not attempt to authenticate using the methods associated with locally-stored credentials. We recommend using a file, environment variable, or another mechanism to store the API key rather than hard-coding it into your application's source.
Note: The Error Reporting instance will check if the provided API key is invalid shortly after it is instantiated. If the key is invalid, an error-level message will be logged to stdout.
The longjohn module can be used with this library to enable long-stack-traces and updates an Error
object's stack trace, by adding special line, to indicate an async jump. In longjohn
version 0.2.12
, for example, a single line of dashes is included in a stack trace, by default, to indicate an async jump.
Before reporting an Error
object using the report
method of the @google-cloud/error-reporting
module, the stack trace needs to modified to remove this special line added by longjohn
. Since the longjohn
module can be configured to have a custom line indicating an async jump, the process of removing the custom line should be handled by the user of the longjohn
module.
The following code illustrates how to update an Error
's stack trace, to remove the default line of dashes added by longjohn
to indicate an async jump, before reporting the error.
1const {ErrorReporting} = require('@google-cloud/error-reporting'); 2 3// Instantiates a client 4const errors = new ErrorReporting(); 5 6const err = new Error('Some Error'); 7err.stack = (err.stack || '').split('\n') 8 .filter(line => !!line.replace(/-/g, '').trim()) 9 .join('\n'); 10errors.report(err);
The Error Reporting Node.js Client API Reference documentation also contains samples.
Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.
Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:
Client libraries targeting some end-of-life versions of Node.js are available, and
can be installed through npm dist-tags.
The dist-tags follow the naming convention legacy-(version)
.
For example, npm install @google-cloud/error-reporting@legacy-8
installs client libraries
for versions compatible with Node.js 8.
This library follows Semantic Versioning.
This library is considered to be stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against stable libraries are addressed with the highest priority.
More Information: Google Cloud Platform Launch Stages
Contributions welcome! See the Contributing Guide.
Please note that this README.md
, the samples/README.md
,
and a variety of configuration files in this repository (including .nycrc
and tsconfig.json
)
are generated from a central template. To edit one of these files, make an edit
to its templates in
directory.
Apache Version 2.0
See LICENSE
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More