Setting Up Stackdriver Trace

App Engine standard environment

Stackdriver Trace is automatically enabled for all applications running on App Engine standard environment. App Engine standard environment applications do not require any additional instrumentation libraries or SDKs.

VMs or containers (Compute Engine, Container Engine, App Engine flexible, non-Google services)

Applications running on VMs or containers (including Google Compute Engine, App Engine flexible environment, and Google Container Engine, as well as non-Google services) are not automatically traced. Use the SDKs listed below, or the Stackdriver Trace API, to send traces to the service.


To enable Stackdriver Trace for Node.js applications running on App Engine flexible environment, import the Node.js Stackdriver Trace agent at the start of your application.

Stackdriver Trace is compatible with Node.js version 0.12 or greater. Node.js version 5+ is recommended.


  1. Install with npm or add to your package.json:

    npm install --save @google/cloud-trace

  2. Import the agent at the top of your main script:


Sample application

if (process.env.NODE_ENV === 'production') {

const express = require('express');
const got = require('got');

const app = express();
const DISCOVERY_URL = '';

// This incoming HTTP request should be captured by Trace
app.get('/', (req, res) => {
  // This outgoing HTTP request should be captured by Trace
  got(DISCOVERY_URL, { json: true })
    .then((response) => {
      const names = =>;

    .catch((err) => {

// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');


The Google Cloud Trace SDK for Java is available on GitHub:


The Stackdriver Trace SDK for Go is available on GitHub. Usage instructions are included in the code comments.


The Stackdriver Trace SDK for Ruby is available on GitHub.

Viewing traces

After deployment, you can view recorded traces and inspect the RPCs in your application.

Send feedback about...

Stackdriver Trace Documentation