amqplib

Appsignal for Node.jsThis feature requires version 3.4.2 or higher.

Advanced Message Queuing Protocol (AMQP) is an open standard protocol that facilitates messaging interoperability across systems, regardless of the message broker vendor or platform they utilize, for example between STOMP and MQTT brokers.

The AppSignal for Node.js integration for amqplib and compatibles such as Rascal allows you to instrument the sending and receiving of messages in your application.

Installation

The amqplib package is instrumented automatically by the AppSignal for Node.js package.

Features

When using the amqplib integration, AppSignal will create a child span for each message that is sent or received.

Note that if the messages are received/sent outside the context of a web request, it's required to manually create a span to wrap the message processing.

Below is an example for Rascal using the simplest example found on their repository, with manual instrumentation added to wrap the message processing in a span.

javascript
let Rascal = require("../.."); let config = require("./config"); const trace = require("@opentelemetry/api"); const tracer = trace.getTracer("example-tracer"); Rascal.Broker.create(Rascal.withDefaultConfig(config), function (err, broker) { if (err) throw err; broker.subscribe("demo_sub", function (err, subscription) { if (err) throw err; subscription.on("message", function (message, content, ackOrNack) { tracer.startActiveSpan("received message demo_sub", (span) => { // Process the message ackOrNack(); span.end(); }); }); }); broker.on("error", console.error); setInterval(function () { broker.publish( "demo_pub", new Date().toISOString() + ": hello world", function (err, publication) { tracer.startActiveSpan("sent message demo_pub", (span) => { if (err) throw err; span.end(); }); } ); }, 1000); });

For more information about manual instrumentation, see the custom instrumentation guide.