How to use the captureMessage function from raven

Find comprehensive JavaScript raven.captureMessage code examples handpicked from public code repositorys.

raven.captureMessage is a method provided by the Raven.js library that allows capturing and reporting non-error messages to a monitoring service.

57
58
59
60
61
62
63
64
65
66
 * @param {string} message
 * @param {object} kwargs
 * @returns {Promise<unknown>}
 */
function captureMessage(message, kwargs) {
  return new Promise(res => Raven.captureMessage(message, kwargs, res));
}

/**
 * Sentry's implementation of wrap does not trow an exception
fork icon5
star icon9
watch icon5

132
133
134
135
136
137
138
139
140
141

this._capturedMessages.push(message);

// eslint-disable-next-line consistent-return
return new Promise((resolve, reject) => {
  Raven.captureMessage(
    message,
    (err, result) => {
      if (err) return reject(err);
      return resolve(result);
fork icon5
star icon4
watch icon8

+ 2 other calls in file

How does raven.captureMessage work?

raven.captureMessage is a method provided by the raven-js library that allows you to capture and send a message as a sentry event, with an optional level and additional context. The message can be any string, object, or error instance, and is sent to the sentry service for debugging and monitoring purposes. When called, it generates a new event with the given message and sends it to the configured sentry server.

13
14
15
16
17
18
19
20
21
22
exports.log = (msg, meta) => {
  if (sentryEnabled) {
    if (meta.level === 'error' || meta.level === 'fatal') {
      Raven.captureException(msg, meta);
    }
    Raven.captureMessage(msg, meta);
  }
};

exports.parseRequest = Raven.parsers.parseRequest;
fork icon20
star icon0
watch icon2

58
59
60
61
62
63
64
65
66
67
  extra,
  fingerprint,
  level,
  callback // = _defaultCaptureExceptionCallback
}) {
  Raven.captureMessage(msg, {
    request,
    user,
    tags,
    extra,
fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
const Raven = require("raven");

Raven.config("YOUR_SENTRY_DSN").install();

// Somewhere in your application code:
try {
  // Do something that might throw an exception
} catch (e) {
  Raven.captureMessage("An error occurred: " + e.message);
}

In this example, the try block is used to attempt some operation that might result in an error. If an error is thrown, the catch block is executed and the Raven.captureMessage method is called with a custom message string that includes the error message. This message will be sent to Sentry and can be used to help diagnose and debug the error.

0
1
2
3
4
5
6
7
8
9
10
11
const config = require('../../../infra/configs/global_config');
const raven = require('raven');


const sendError = async (errorMessage) => {
  raven.config(config.get('/dsnSentryUrl')).install();
  raven.captureMessage(errorMessage);
};


module.exports = {
  sendError
fork icon0
star icon0
watch icon0