Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

OpenTelemetry Example PubSub App

This is an example app that uses the New Relic agent in the OpenTelemetry bridge mode to instrument GCP Pub/Sub.

Example App Setup

Setup GCP PubSub

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.

Run Example

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 times

Instrumenting your Application

If 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:

  1. Install newrelic normally. Please refer to our installation docs if you need help.
  2. In your newrelic.js file, enable OpenTelemetry bridge w/ traces. inside exports.config:
    exports.config = {
         // ...
         opentelemetry_bridge: {
             enabled: true,
             traces: {
                 enabled: true,
             }
         },
         // ...
    }
  3. In every file that instantiates the PubSub class, give it the config of enableOpenTelemetryTracing:true.
    const { PubSub } = require('@google-cloud/pubsub')
    const pubsubClient = new PubSub({ enableOpenTelemetryTracing: true })
  4. 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()
    })