Google Cloud Run

This guide walks you through instrumenting Google Cloud Run with Middleware APMs (Application Performance Monitoring). These instructions can also be found on the Installation page in your Middleware Account.

Introduction

Middleware Application Performance Monitoring (APMs) with Google Cloud Run enables tracing and monitoring for applications. This integration provides valuable insights into application performance and behavior, enhancing observability in a Cloud Run environment.

Node js
.NET

Prerequisites

  1. Node.js 18 +: Verify with node --version

Features Supported

TracesMetricsApp LogsCustom LogsProfiling

Installation

1 Install Node.js APM Package

Run the following command in your terminal:

Make sure to include this package in your package.json file for Google Cloud Run deployment.

2 Setup Options

Method 1: Direct Code Initialization

Add the following lines to the beginning of your application code base. The access token is your account key, which can be found on the Installation page.

Method 2: Add the tracker with command line arguments

Create a file named instrument.js or instrument.ts in your project root:

To ensure the tracker is initialized before any other code runs, use the --require flag when starting your Node.js application:

If --require doesn't work which means app uses ESM modules, use --import or --loader instead of --require.

3 Add ENV Variables and Deploy to Google Cloud Run

Deploy your application to Google Cloud Run. The APM tracker will start automatically with the application.

Ensure your Dockerfile or deployment script installs the APM package and includes the correct entry point for initialization.

Add this environment variable to allow comprehensive collection of metadata about the application's runtime Environment Add ENV Variables and Deploy to Google Cloud Run

4 Handle missing spans

In serverless environments like Google Cloud Run, you may encounter missing spans due to sudden instance termination. To mitigate this, you have two options:

Environment Setup
Programmatic Setup

This sets the delay to 500 ms (adjust as needed). A lower value means more frequent data exports, potentially reducing missing spans at the cost of slightly increased network usage.

This ensures that all pending telemetry is flushed and connections are closed gracefully before the application shuts down signal SIGTERM or SIGNINT .

5 Add Custom Instrumentation (Optional)

If you need to add custom spans or attributes, you can follow the instructions found here

Troubleshooting

If you encounter any issues, you can visit this link for basic troubleshooting guidelines.

Prerequisites

  1. .NET 6+:

Check your .NET version with the following command:

Features Supported

TracesMetricsApp LogsCustom LogsProfiling

Installation

1 Install the Required Package

CLI
Visual Studio

Add the Middleware package to your .NET project by running the following command using CLI:

If you are using Visual Studio IDE in Windows, then you can install it by going to below given path.

PATH - Tools > Nuget Package Manager > Manage Nuget Packages for Solutions > Browse

Now, search for MW.APM and Install the nuget package.

Installing Nuget Package in Visual Studio

2 Add Code Configuration

Add the following code to your Program.cs file:

3 Configure Your Middleware Account Information

Add the following to your appsettings.json file:

If you want to know more about all 2 methods and its attributes. You can refer this link

This is a one-time configuration. After these configuration changes are made, each time the lambda function deployed, the .NET instrumentation will also run.

Need assistance or want to learn more about Middleware? Contact our support team in Slack.