-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add small StackDriver Trace and Debugger samples. (#141)
- Loading branch information
Showing
11 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |