This is an example app that uses the New Relic agent in the OpenTelemetry bridge mode to instrument GCP Pub/Sub.
In the PubSub Getting Started guide, follow the steps in the "Before you begin" and "Create a topic and subscription" sections. my-topic is the default topic name and my-sub is the default subscription name (matches the guide), but this can be changed in env-p.sample and env-s.sample respectively.
Requirements:
- Node.js >= 20.6.0
npm install
cp env-p.sample .env-p # Publisher env vars
cp env-s.sample .env-s # Subscriber env vars
# Fill out `NEW_RELIC_LICENSE_KEY` in .env-p and .env-s
npm run subscribe # Start subscriber
npm run publish # Run publisher a few timesIf you already have a GCP Pub/Sub application that you would like to instrument with our agent's OpenTelemetry bridge, here are the steps that you need to do:
- Install
newrelicnormally. Please refer to our installation docs if you need help. - In your
newrelic.jsfile, enable OpenTelemetry bridge w/ traces. insideexports.config:exports.config = { // ... opentelemetry_bridge: { enabled: true, traces: { enabled: true, } }, // ... }
- In every file that instantiates the
PubSubclass, give it the config ofenableOpenTelemetryTracing:true.const { PubSub } = require('@google-cloud/pubsub') const pubsubClient = new PubSub({ enableOpenTelemetryTracing: true })
- Wrap the code that publishes messages in a background transaction. This is not necessary for the subscriber.
const newrelic = require('newrelic') // ... newrelic.startBackgroundTransaction('transaction name', async function handleTransaction() { const txn = newrelic.getTransaction() await publishMessage() // replace with your function txn.end() })