Skip to content

Commit

Permalink
Add small StackDriver Trace and Debugger samples. (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored Jun 29, 2016
1 parent 8152610 commit 93381d4
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ on Google Cloud Platform.
* [Google Container Engine](#google-container-engine)
* [Google BigQuery](#google-bigquery)
* [Google Cloud Datastore (Beta)](#google-cloud-datastore-beta)
* [Stackdriver Debugger (Beta)](#stackdriver-debugger-beta)
* [Google Cloud Functions (Alpha)](#google-cloud-functions-alpha)
* [Stackdriver Logging (Beta)](#stackdriver-logging-beta)
* [Stackdriver Monitoring (Beta)](#stackdriver-monitoring-beta)
* [Google Cloud Prediction API](#google-cloud-prediction-api)
* [Google Cloud Pub/Sub](#google-cloud-pubsub)
* [Google Cloud Speech API (Alpha)](#google-cloud-speech-api-alpha)
* [Google Cloud Storage](#google-cloud-storage)
* [Stackdriver Trace (Beta)](#stackdriver-trace-beta)
* [Google Cloud Vision API](#google-cloud-vision-api)
* [Other sample applications](#other-sample-applications)
* [Bookshelf tutorial app](#bookshelf-tutorial-app)
Expand Down Expand Up @@ -235,6 +237,16 @@ View the [Cloud Datastore Node.js samples][datastore_samples].
[datastore_docs]: https://cloud.google.com/datastore/docs/
[datastore_samples]: datastore

### Stackdriver Debugger (Beta)

[Stackdriver Debugger][debugger_docs] makes it easier to view the application
state without adding logging statements.

View the [Stackdriver Debugger Node.js sample][debugger_sample].

[debugger_docs]: https://cloud.google.com/debugger/docs/
[debugger_sample]: debugger

### Google Cloud Functions (Alpha)

[Sign up for the Alpha][functions_signup].
Expand Down Expand Up @@ -316,6 +328,17 @@ View the [Cloud Storage Node.js samples][storage_samples].
[storage_docs]: https://cloud.google.com/storage/docs/
[storage_samples]: storage

### Stackdriver Trace (Beta)

[Stackdriver Trace][trace_docs] is a distributed tracing system for Google Cloud
Platform that collects latency data from App Engine applications and displays it
in near real time in the Google Cloud Platform Console.

View the [Stackdriver Trace Node.js sample][trace_sample].

[trace_docs]: https://cloud.google.com/trace/docs/
[trace_sample]: trace

### Google Cloud Vision API

The [Cloud Vision API][vision_docs] allows developers to easily integrate vision
Expand Down
32 changes: 32 additions & 0 deletions debugger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# StackDriver Debugger sample for Node.js

This sample demonstrates [StackDriver Debugger](https://cloud.google.com/debugger/) with Node.js.

## Deploy and test

Where appropriate, replace `[YOUR_PROJECT_ID]` with the ID of your Cloud project.

1. `git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git`
1. `cd nodejs-docs-samples/debugger`
1. Initialize a new git repository:

git init

1. Configure git to use gcloud SDK:

git config credential.helper gcloud.sh

1. Add your Cloud Source Repository as a git remote:

git remote add google https://source.developers.google.com/p/[YOUR_PROJECT_ID]/r/default

1. Commit and push the code into the Cloud Source Repository:

git add -A && git commit -m "Initial commit" && git push --all google

1. Deploy the app:

gcloud preview app deploy

1. View the deployed app at https://[YOUR_PROJECT_ID].appspot.com/.
1. Use the [StackDriver Debugger dashboard](https://console.cloud.google.com/debug) to inspect runtime data of the app.
35 changes: 35 additions & 0 deletions debugger/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2015-2016, Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// [START app]
'use strict';

if (process.env.GCLOUD_PROJECT) {
require('@google/cloud-debug');
}

var express = require('express');
var app = express();

app.get('/', function (req, res) {
// Try using the StackDriver Debugger dashboard to inspect the "req" object
res.status(200).send('Hello, world!');
});

// Start the server
var server = app.listen(process.env.PORT || '8080', function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
17 changes: 17 additions & 0 deletions debugger/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2015-2016, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START app_yaml]
runtime: nodejs
vm: true
# [END app_yaml]
18 changes: 18 additions & 0 deletions debugger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "stackdriver-debugger",
"description": "StackDriver Debugger sample for Node.js",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "~4.2"
},
"scripts": {
"start": "node app.js"
},
"dependencies": {
"@google/cloud-debug": "^0.8.3",
"express": "^4.13.4"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@
"deps_bigquery": "cd bigquery; npm i; cd ../",
"deps_computeengine": "cd computeengine; npm i; cd ../",
"deps_datastore": "cd datastore; npm i; cd ../",
"deps_debugger": "cd debugger; npm i; cd ../",
"deps_functions": "cd functions/uuid; npm i; cd ../..",
"deps_logging": "cd logging; npm i; cd ../",
"deps_monitoring": "cd monitoring; npm i; cd ../",
"deps_prediction": "cd prediction; npm i; cd ../",
"deps_pubsub": "cd pubsub; npm i; cd ../",
"deps_speech": "cd speech; npm i; cd ../",
"deps_storage": "cd storage; npm i; cd ../",
"deps_trace": "cd trace; npm i; cd ../",
"deps_vision": "cd vision; npm i; cd ../",
"lint": "semistandard \"**/*.js\"",
"pretest_geddy": "cd appengine/geddy; npm i geddy; GEDDY_SECRET=config/secrets.json; [[ -f $GEDDY_SECRET ]] || echo '{}' > $GEDDY_SECRET && node node_modules/.bin/geddy gen secret; cd ../..;",
"pretest": "npm run deps_vision; npm run deps_computeengine; npm run deps_bigquery; npm run deps_datastore; npm run deps_monitoring; npm run deps_storage; npm run deps_pubsub; npm run deps_prediction; npm run deps_logging; npm run deps_functions; npm run deps_speech; npm run pretest_geddy;",
"pretest": "npm run deps_trace; npm run deps_debugger; npm run deps_vision; npm run deps_computeengine; npm run deps_bigquery; npm run deps_datastore; npm run deps_monitoring; npm run deps_storage; npm run deps_pubsub; npm run deps_prediction; npm run deps_logging; npm run deps_functions; npm run deps_speech; npm run pretest_geddy;",
"report": "nyc report --reporter=lcov | codecov",
"report-html": "nyc report --reporter=html",
"test": "npm run lint && npm run cover"
Expand Down
12 changes: 12 additions & 0 deletions test/appengine/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ var sampleTests = [
cmd: 'node',
args: ['server.js'],
msg: 'Hello Kubernetes!'
},
{
dir: 'debugger',
cmd: 'node',
args: ['app.js'],
msg: 'Hello, world!'
},
{
dir: 'trace',
cmd: 'node',
args: ['app.js'],
msg: 'acceleratedmobilepageurl'
}
];

Expand Down
16 changes: 16 additions & 0 deletions trace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# StackDriver Trace sample for Node.js

This sample demonstrates [StackDriver Trace](https://cloud.google.com/trace/) with Node.js.

## Deploy and test

Where appropriate, replace `[YOUR_PROJECT_ID]` with the ID of your Cloud project.

1. `git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git`
1. `cd nodejs-docs-samples/trace`
1. Deploy the app:

gcloud preview app deploy

1. Visit the deployed app at https://[YOUR_PROJECT_ID].appspot.com/.
1. Use the [StackDriver Trace dashboard](https://console.cloud.google.com/traces/traces) to inspect recorded traces.
49 changes: 49 additions & 0 deletions trace/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2015-2016, Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// [START app]
'use strict';

if (process.env.NODE_ENV === 'production') {
require('@google/cloud-trace').start();
}

var request = require('request');
var express = require('express');
var app = express();
var DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis';

// This incoming HTTP request should be captured by Trace
app.get('/', function (req, res) {
// This outgoing HTTP request should be captured by Trace
request({
url: DISCOVERY_URL,
json: true
}, function (err, response, body) {
if (err) {
return res.status(500).end();
}
var names = body.items.map(function (item) {
return item.name;
});
return res.status(200).send(names.join('\n'));
});
});

// Start the server
var server = app.listen(process.env.PORT || '8080', function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
17 changes: 17 additions & 0 deletions trace/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2015-2016, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START app_yaml]
runtime: nodejs
vm: true
# [END app_yaml]
19 changes: 19 additions & 0 deletions trace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "stackdriver-trace",
"description": "StackDriver Trace sample for Node.js",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "~6"
},
"scripts": {
"start": "node app.js"
},
"dependencies": {
"@google/cloud-trace": "^0.5.3",
"express": "^4.13.4",
"request": "^2.72.0"
}
}

0 comments on commit 93381d4

Please sign in to comment.