Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit fc5a387

Browse files
chore: add samples code (#633)
Fixes: #577
1 parent 9bda238 commit fc5a387

File tree

8 files changed

+180
-23
lines changed

8 files changed

+180
-23
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
"scripts": {
8181
"changelog": "npm run compile && ./bin/run-changelog.sh",
8282
"prepare": "npm run compile",
83+
"presamples-test": "npm run compile",
84+
"samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../",
8385
"presystem-test": "npm run compile",
8486
"system-test": "mocha build/system-test",
8587
"test-no-cover": "cross-env CLOUD_DEBUG_ASSERTIONS=1 mocha build/test --require source-map-support/register --timeout 4000 --R spec",
@@ -96,7 +98,6 @@
9698
"license-check": "jsgl --local .",
9799
"lint": "npm run check",
98100
"docs": "compodoc src/",
99-
"samples-test": "mocha samples/system-test",
100101
"docs-test": "linkinator docs -r --skip www.googleapis.com",
101102
"predocs-test": "npm run docs"
102103
},

samples/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# StackDriver Debugger sample for Node.js
2+
3+
This sample demonstrates [StackDriver Debugger][debugger] with Node.js.
4+
5+
* [Setup](#setup)
6+
* [Running locally](#running-locally)
7+
* [Deploying to App Engine](#deploying-to-app-engine)
8+
* [Running the tests](#running-the-tests)
9+
10+
## Setup
11+
12+
Before you can run or deploy the sample, you need to do the following (where
13+
appropriate, replace `YOUR_PROJECT_ID` with the ID of your Cloud project):
14+
15+
1. Refer to the `@google-cloud/debug-agent` [README][readme] for instructions on
16+
running and deploying.
17+
18+
1. Set the `GCLOUD_PROJECT` environment variable:
19+
20+
Linux:
21+
22+
export GCLOUD_PROJECT=your-project-id
23+
24+
Windows:
25+
26+
set GCLOUD_PROJECT=your-project-id
27+
28+
Windows (PowerShell):
29+
30+
$env:GCLOUD_PROJECT="your-project-id"
31+
32+
1. Acquire local credentials for authenticating with Google Cloud Platform APIs:
33+
34+
gcloud auth application-default login
35+
36+
1. Configure git to use gcloud SDK:
37+
38+
git config credential.helper gcloud.sh
39+
40+
1. Add your Cloud Source Repository as a git remote:
41+
42+
git remote add google https://source.developers.google.com/p/YOUR_PROJECT_ID/r/default
43+
44+
1. Commit and push the code into the Cloud Source Repository:
45+
46+
git add -A && git commit -m "Initial commit" && git push --all google
47+
48+
1. Install dependencies:
49+
50+
npm install
51+
52+
## Running locally
53+
54+
npm start
55+
56+
57+
## Deploying to App Engine
58+
59+
npm run deploy
60+
61+
62+
Use the [Stackdriver Debugger dashboard](https://console.cloud.google.com/debug) to inspect runtime data of the app.
63+
64+
## Running the tests
65+
66+
See [Contributing][contributing].
67+
68+
[debugger]: https://cloud.google.com/debugger/
69+
[readme]: ../README.md
70+
[contributing]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/CONTRIBUTING.md

samples/app.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2017, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// [START debugger_app]
17+
'use strict';
18+
19+
// [START debugger_setup_implicit]
20+
require('@google-cloud/debug-agent').start();
21+
// [END debugger_setup_implicit]
22+
23+
const express = require('express');
24+
const app = express();
25+
26+
app.enable('trust proxy');
27+
28+
app.get('/', (req, res) => {
29+
// Try using the StackDriver Debugger dashboard to inspect the "req" object
30+
res.status(200).send('Hello, world!');
31+
});
32+
33+
// Start the server
34+
if (module === require.main) {
35+
const PORT = process.env.PORT || 8080;
36+
app.listen(PORT, () => {
37+
console.log(`App listening on port ${PORT}`);
38+
console.log('Press Ctrl+C to quit.');
39+
});
40+
}
41+
// [END debugger_app]
42+
43+
module.exports = app;

samples/app.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2015-2016, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
# [START app_yaml]
15+
runtime: nodejs10
16+
# [END app_yaml]

samples/package.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
{
2-
"description": "Samples for the googleapis/cloud-debug-nodejs npm module.",
2+
"name": "nodejs-docs-samples-debugger",
3+
"description": "Sample for Google Stackdriver Trace on Google App Engine Flexible Environment.",
4+
"version": "0.0.1",
5+
"private": true,
36
"license": "Apache-2.0",
4-
"author": "Google LLC",
7+
"author": "Google Inc.",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
11+
},
512
"engines": {
613
"node": ">=8"
714
},
8-
"repository": "googleapis/cloud-debug-nodejs",
9-
"private": true,
1015
"scripts": {
11-
"test": "mocha system-test"
16+
"deploy": "gcloud app deploy",
17+
"start": "node app.js",
18+
"system-test": "repo-tools test app",
19+
"test": "npm run system-test",
20+
"e2e-test": "repo-tools test deploy"
1221
},
1322
"dependencies": {
14-
"@google-cloud/debug-agent": "^3.0.1"
23+
"@google-cloud/debug-agent": "3.0.1",
24+
"express": "4.16.4"
1525
},
1626
"devDependencies": {
27+
"@google-cloud/nodejs-repo-tools": "^3.0.0",
1728
"mocha": "^6.0.0"
29+
},
30+
"cloud-repo-tools": {
31+
"test": {
32+
"app": {
33+
"msg": "Hello, world!"
34+
}
35+
},
36+
"requiresKeyFile": true,
37+
"requiresProjectId": true
1838
}
1939
}

samples/quickstart.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

samples/snippets.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2017, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
// [START debugger_setup_explicit]
19+
require('@google-cloud/debug-agent').start({
20+
projectId: 'your-project-id',
21+
keyFilename: '/path/to/key.json',
22+
});
23+
// [END debugger_setup_explicity]

samples/system-test/test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)