diff --git a/appengine/errorreporting/README.md b/appengine/errorreporting/README.md deleted file mode 100644 index ff850097dd..0000000000 --- a/appengine/errorreporting/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Node.js error reporting sample for Google App Engine - -This sample shows how to use Stackdriver Error Reporting on Google App Engine -Node.js [standard environment][appengine-std] and [flexible environment][appengine-flex]. - -## Running locally - -Refer to the [appengine/README.md](../README.md) file for instructions on -running and deploying. - -[appengine-flex]: https://cloud.google.com/appengine/docs/flexible/nodejs -[appengine-std]: https://cloud.google.com/appengine/docs/standard/nodejs \ No newline at end of file diff --git a/appengine/errorreporting/app.flexible.yaml b/appengine/errorreporting/app.flexible.yaml deleted file mode 100644 index 41e9fef5d7..0000000000 --- a/appengine/errorreporting/app.flexible.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# 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. - -runtime: nodejs -env: flex diff --git a/appengine/errorreporting/app.js b/appengine/errorreporting/app.js deleted file mode 100644 index b799a1e9d2..0000000000 --- a/appengine/errorreporting/app.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 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. - */ - -'use strict'; - -const express = require('express'); -const errors = require('@google-cloud/error-reporting')(); - -const app = express(); - -app.get('/', (req, res, next) => { - next(new Error('something is wrong!')); -}); - -app.use((err, req, res) => { - errors.report(err); - res.status(500).send(err.message || 'Something broke!'); -}); - -const PORT = process.env.PORT || 8080; -app.listen(PORT, () => { - console.log(`App listening on port ${PORT}`); - console.log('Press Ctrl+C to quit.'); -}); - -module.exports = app; diff --git a/appengine/errorreporting/app.standard.yaml b/appengine/errorreporting/app.standard.yaml deleted file mode 100644 index 91eeb4be88..0000000000 --- a/appengine/errorreporting/app.standard.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -runtime: nodejs10 diff --git a/appengine/errorreporting/package.json b/appengine/errorreporting/package.json deleted file mode 100644 index 4fb0a68041..0000000000 --- a/appengine/errorreporting/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "appengine-error-reporting", - "description": "Node.js error reporting sample for Google App Engine.", - "version": "0.0.1", - "private": true, - "license": "Apache-2.0", - "author": "Google Inc.", - "repository": { - "type": "git", - "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" - }, - "engines": { - "node": ">=8" - }, - "scripts": { - "start": "node app.js", - "unit-test": "ava --verbose test/*.test.js", - "system-test": "repo-tools test app", - "test": "npm run unit-test && npm run system-test" - }, - "dependencies": { - "@google-cloud/error-reporting": "0.2.3", - "express": "4.16.4" - }, - "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.0.0", - "ava": "0.25.0", - "proxyquire": "2.0.0", - "sinon": "4.4.2", - "supertest": "^3.3.0" - }, - "cloud-repo-tools": { - "test": { - "app": { - "msg": "something is wrong", - "code": 500 - } - }, - "requiresKeyFile": true, - "requiresProjectId": true - } -} diff --git a/appengine/errorreporting/test/app.test.js b/appengine/errorreporting/test/app.test.js deleted file mode 100644 index d2a0a43b02..0000000000 --- a/appengine/errorreporting/test/app.test.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2017, 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. - */ - -'use strict'; - -const express = require(`express`); -const path = require(`path`); -const proxyquire = require(`proxyquire`).noPreserveCache(); -const request = require(`supertest`); -const sinon = require('sinon'); -const test = require('ava'); -const tools = require('@google-cloud/nodejs-repo-tools'); - -const SAMPLE_PATH = path.join(__dirname, `../app.js`); - -function getSample() { - const testApp = express(); - sinon.stub(testApp, `listen`).callsArg(1); - const expressMock = sinon.stub().returns(testApp); - const resultsMock = - JSON.stringify({ - timestamp: `1234`, - userIp: `abcd`, - }) + `\n`; - const reportMock = sinon.stub(); - const errorsMock = sinon.stub().callsFake(function ErrorReporting() { - return { - report: reportMock, - }; - }); - - const app = proxyquire(SAMPLE_PATH, { - express: expressMock, - '@google-cloud/error-reporting': errorsMock, - }); - return { - app: app, - mocks: { - errors: errorsMock, - express: expressMock, - report: reportMock, - results: resultsMock, - }, - }; -} - -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test(`sets up the sample`, t => { - const sample = getSample(); - - t.true(sample.mocks.express.calledOnce); - t.true(sample.mocks.errors.calledOnce); - t.is(sample.mocks.report.callCount, 0); - t.true(sample.app.listen.calledOnce); - t.is(sample.app.listen.firstCall.args[0], process.env.PORT || 8080); -}); - -test.cb(`should throw an error`, t => { - const sample = getSample(); - const expectedResult = `something is wrong!`; - - request(sample.app) - .get(`/`) - .expect(500) - .expect(response => { - t.true(sample.mocks.report.calledOnce); - t.is(response.text, expectedResult); - }) - .end(t.end); -}); diff --git a/error-reporting/README.md b/error-reporting/README.md deleted file mode 100644 index e0e444986a..0000000000 --- a/error-reporting/README.md +++ /dev/null @@ -1,57 +0,0 @@ -Google Cloud Platform logo - -# Stackdriver Error Reporting Node.js Samples - -[![Build](https://storage.googleapis.com/cloud-docs-samples-badges/GoogleCloudPlatform/nodejs-docs-samples/nodejs-docs-samples-logging.svg)]() - -[Stackdriver Error Reporting](https://cloud.google.com/error-reporting/docs/) aggregates and displays errors produced in your running cloud services. - -## Table of Contents - -* [Setup](#setup) -* [Samples](#samples) - * [Examples](#examples) -* [Running the tests](#running-the-tests) - -## Setup - -1. Read [Prerequisites][prereq] and [How to run a sample][run] first. -1. Install dependencies: - - npm install - - -[prereq]: ../README.md#prerequisites -[run]: ../README.md#how-to-run-a-sample - -## Samples - -### Examples - -View the [documentation][snippets_0_docs] or the [source code][snippets_0_code]. - -__Usage:__ `node snippets.js --help` - -``` -Commands: - manual Manually reports errors. - -Options: - --help Show help [boolean] - -Examples: - node snippets.js manual Manually report some errors. - -For more information, see https://cloud.google.com/error-reporting/docs -``` - -[snippets_0_docs]: https://cloud.google.com/error-reporting/docs -[snippets_0_code]: snippets.js - -## Running the tests - -1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. - -1. Run the tests: - - npm test diff --git a/error-reporting/package.json b/error-reporting/package.json deleted file mode 100644 index bacd21adc6..0000000000 --- a/error-reporting/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "nodejs-docs-samples-logging", - "version": "0.0.1", - "private": true, - "license": "Apache-2.0", - "author": "Google Inc.", - "repository": { - "type": "git", - "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" - }, - "engines": { - "node": ">=8" - }, - "scripts": { - "error-test": "repo-tools test app --msg \"Something broke!\" --url \"http://localhost:33332/error\" --port 33332 -- snippets.js express", - "exception-test": "repo-tools test app --code 500 --msg SyntaxError --url \"http://localhost:33333/exception\" --port 33333 -- snippets.js express", - "system-test": "ava -T 1m --verbose system-test/*.test.js", - "all-test": "npm run system-test && npm run error-test && npm run exception-test", - "test": "repo-tools test run --cmd npm -- run all-test" - }, - "dependencies": { - "@google-cloud/error-reporting": "0.2.3", - "express": "4.16.4", - "yargs": "11.0.0" - }, - "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.0.0", - "ava": "0.25.0", - "proxyquire": "2.0.0", - "sinon": "4.4.2" - }, - "cloud-repo-tools": { - "requiresKeyFile": true, - "requiresProjectId": true, - "product": "error_reporting", - "samples": [ - { - "id": "snippets", - "name": "Examples", - "file": "snippets.js", - "docs_link": "https://cloud.google.com/error-reporting/docs", - "usage": "node snippets.js --help" - } - ] - } -} diff --git a/error-reporting/snippets.js b/error-reporting/snippets.js deleted file mode 100644 index fb337d015e..0000000000 --- a/error-reporting/snippets.js +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Copyright 2017, 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. - */ - -'use strict'; - -function setupImplicit() { - // [START error_reporting_setup_implicit] - // [START error_reporting_setup_nodejs_implicit] - // Imports the Google Cloud client library - const ErrorReporting = require('@google-cloud/error-reporting'); - - // Instantiates a client - const errors = ErrorReporting(); - - // Reports a simple error - errors.report('Something broke!'); - // [END error_reporting_setup_nodejs_implicit] - // [END error_reporting_setup_implicit] -} - -function setupExplicit() { - // [START error_reporting_setup_explicit] - // [START error_reporting_setup_nodejs_explicit] - // Imports the Google Cloud client library - const ErrorReporting = require('@google-cloud/error-reporting'); - - // Instantiates a client - const errors = ErrorReporting({ - projectId: 'your-project-id', - keyFilename: '/path/to/key.json', - }); - - // Reports a simple error - errors.report('Something broke!'); - // [END error_reporting_setup_nodejs_explicit] - // [END error_reporting_setup_explicit] -} - -function manual() { - // [START error_reporting_manual] - // [START error_reporting_setup_nodejs_manual] - // Imports the Google Cloud client library - const ErrorReporting = require('@google-cloud/error-reporting'); - - // Instantiates a client - const errors = ErrorReporting(); - - // Use the error message builder to customize all fields ... - const errorEvent = errors.event(); - - // Add error information - errorEvent.setMessage('My error message'); - errorEvent.setUser('root@nexus'); - - // Report the error event - errors.report(errorEvent, () => { - console.log('Done reporting error event!'); - }); - - // Report an Error object - errors.report(new Error('My error message'), () => { - console.log('Done reporting Error object!'); - }); - - // Report an error by provided just a string - errors.report('My error message', () => { - console.log('Done reporting error string!'); - }); - // [END error_reporting_setup_nodejs_manual] - // [END error_reporting_manual] -} - -function express() { - // [START error_reporting_express] - // [START error_reporting_setup_nodejs_express] - const express = require('express'); - - // Imports the Google Cloud client library - const ErrorReporting = require('@google-cloud/error-reporting'); - - // Instantiates a client - const errors = ErrorReporting(); - - const app = express(); - - app.get('/error', (req, res, next) => { - res.send('Something broke!'); - next(new Error('Custom error message')); - }); - - app.get('/exception', () => { - JSON.parse('{"malformedJson": true'); - }); - - // Note that express error handling middleware should be attached after all - // the other routes and use() calls. See the Express.js docs. - app.use(errors.express); - - const PORT = process.env.PORT || 8080; - app.listen(PORT, () => { - console.log(`App listening on port ${PORT}`); - console.log('Press Ctrl+C to quit.'); - }); - // [END error_reporting_express] - // [END error_reporting_setup_nodejs_express] -} - -// The command-line program -const cli = require(`yargs`) - .demand(1) - .command( - 'setup-implicit', - 'Reports a simple error using implicit credentials.', - {}, - setupImplicit - ) - .command( - 'setup-explicit', - 'Reports a simple error using explicit credentials.', - {}, - setupExplicit - ) - .command('manual', 'Manually reports errors.', {}, manual) - .command( - 'express', - 'Starts and Express service with integrated error reporting.', - {}, - express - ) - .example( - 'node $0 setup-implicit', - 'Reports a simple error using implicit credentials.' - ) - .example( - 'node $0 setup-explicit', - 'Reports a simple error using explicit credentials.' - ) - .example('node $0 manual', 'Manually report some errors.') - .example( - 'node $0 express', - 'Starts and Express service with integrated error reporting.' - ) - .wrap(120) - .recommendCommands() - .epilogue( - `For more information, see https://cloud.google.com/error-reporting/docs` - ) - .help() - .strict(); - -if (module === require.main) { - cli.parse(process.argv.slice(2)); -} diff --git a/error-reporting/system-test/snippets.test.js b/error-reporting/system-test/snippets.test.js deleted file mode 100644 index b5b4088c6b..0000000000 --- a/error-reporting/system-test/snippets.test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2017, 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. - */ - -'use strict'; - -const path = require(`path`); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -const cwd = path.join(__dirname, `..`); -const cmd = `node snippets.js`; - -test.before(tools.checkCredentials); - -test.serial(`should setup using implicit credentials`, async t => { - t.plan(0); - // There's no output, the command should just succeed - await tools.runAsync(`${cmd} setup-implicit`, cwd); -}); - -test.serial(`should report errors manually`, async t => { - const output = await tools.runAsync(`${cmd} manual`, cwd); - t.is(output.includes('Done reporting error event!'), true); - t.is(output.includes('Done reporting Error object!'), true); - t.is(output.includes('Done reporting error string!'), true); -});