How to use @google-cloud/debug-agent - 10 common examples

To help you get started, we’ve selected a few @google-cloud/debug-agent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HowNetWorks / uriteller / src / backend / lib / gcloud.js View on Github external
let errorHandler = {
  report(err) {
    // eslint-disable-next-line no-console
    console.error(err);
  },
  express(req, res, next) {
    next();
  }
};

if (process.env.NODE_ENV === "production") {
  require("@google-cloud/trace-agent").start();
  require("@google-cloud/debug-agent").start();
  errorHandler = require("@google-cloud/error-reporting")();
}

module.exports = {
  pubsub() {
    return require("@google-cloud/pubsub")();
  },
  datastore() {
    return require("@google-cloud/datastore")();
  },
  errors: errorHandler
};
github googleapis / cloud-debug-nodejs / samples / app.js View on Github external
//
// 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';

require('@google-cloud/debug-agent').start();

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

app.enable('trust proxy');

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

// 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.');
github UnaBiz / sigfox-gcloud / main / index.js View on Github external
//  Helper for main function
/*  eslint-disable max-len,camelcase,import/no-extraneous-dependencies,import/no-unresolved,global-require,import/newline-after-import */

process.on('uncaughtException', err => console.error('uncaughtException', err.message, err.stack));  //  Display uncaught exceptions.
process.on('unhandledRejection', (reason, p) => console.error('unhandledRejection', reason, p));  //  Display uncaught promises.

//  Read .env file to set any environment variables.
const dotenv = require('dotenv');
dotenv.load();

const isGoogleCloud = !!process.env.FUNCTION_NAME || !!process.env.GAE_SERVICE;
if (isGoogleCloud) {  //  Start agents for Google Cloud.
  // eslint-disable-next-line import/no-extraneous-dependencies
  if (!process.env.DISABLE_DNSCACHE) require('dnscache')({ enable: true });  //  Enable DNS cache in case we hit the DNS quota for Google Cloud Functions.
  if (!process.env.DISABLE_TRACE) require('@google-cloud/trace-agent').start();  //  Must enable Google Cloud Tracing before other require()
  if (!process.env.DISABLE_DEBUG) require('@google-cloud/debug-agent').start();  //  Must enable Google Cloud Debug before other require()
}
const scloud = isGoogleCloud ? require('sigfox-gcloud') : null;

function getMainFunction(wrapper, wrap, package_json) {
  //  Return the Google Cloud startup function main(), if defined in the wrap() function.
  //  If the wrap() function defines task(), return the main() function
  //  from sigfox-iot-cloud, after passing task() to main().
  //  For Google Cloud, select the 2-para or 1-para version of main()
  //  depending on the call mode: HTTP or PubSub Queue.
  if (!isGoogleCloud) throw new Error('getMainFunction is for Google Cloud only');
  if (!wrapper || !wrap) throw new Error('Missing wrapper or wrap function');
  if (!wrapper.main && !wrapper.task) Object.assign(wrapper, wrap(scloud, package_json));
  const mainFunc = wrapper.main ? wrapper.main.bind(wrapper) : scloud.main.bind(wrapper);
  const taskFunc = wrapper.task ? wrapper.task.bind(wrapper) : null;
  if (process.env.FUNCTION_TRIGGER_TYPE === 'HTTP_TRIGGER') {
    //  Return the 2-para main function for HTTP mode.
github UnaBiz / sigfox-gcloud / routeMessage / index.js View on Github external
//  under heavy load.  High availability of this Cloud Function is
//  essential in order to route every Sigfox message properly.

//  //////////////////////////////////////////////////////////////////////////////////////////
//  Begin Common Declarations

/* eslint-disable camelcase, no-console, no-nested-ternary, import/no-dynamic-require,
 import/newline-after-import, import/no-unresolved, global-require, max-len */
//  Enable DNS cache in case we hit the DNS quota for Google Cloud Functions.
require('dnscache')({ enable: true });
process.on('uncaughtException', err => console.error(err.message, err.stack));  //  Display uncaught exceptions.
if (process.env.FUNCTION_NAME) {
  //  Load the Google Cloud Trace and Debug Agents before any require().
  //  Only works in Cloud Function.
  require('@google-cloud/trace-agent').start();
  require('@google-cloud/debug-agent').start();
}
const stringify = require('json-stringify-safe');

//  A route is an array of strings.  Each string indicates the next processing step,
//  e.g. ['decodeStructuredMessage', 'logToGoogleSheets'].

//  The route is stored in this key in the Google Cloud Metadata store.
const defaultRouteKey = 'sigfox-route';
const routeExpiry = 10 * 1000;  //  Routes expire in 10 seconds.

let defaultRoute = null;        //  The cached route.
let defaultRouteExpiry = null;  //  Cache expiry timestamp.

//  End Common Declarations
//  //////////////////////////////////////////////////////////////////////////////////////////
github JustinBeckwith / cloudcats / web / server.js View on Github external
'use strict';

require('@google-cloud/trace-agent').start();
require('@google-cloud/debug-agent').start({
	allowExpressions: true
});

const path = require('path');
const Hapi = require('hapi');

process.on('unhandledRejection', (reason, p) => {
	console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});

// Set up the server
const server = new Hapi.Server({
	host: '0.0.0.0',
	port: process.env.PORT || 8080
});
github GoogleCloudPlatform / training-data-analyst / courses / developingapps / v1.2 / nodejs / stackdriver-trace-monitoring / start / frontend / app.js View on Github external
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';

const config = require('./config');

// TODO: Load the trace-agent and start it
// Trace must be started before any other code in the 
// application.




// END TODO

require('@google-cloud/debug-agent').start({
	allowExpressions: true
});

const path = require('path');
const express = require('express');
const scores = require('./gcp/spanner');

const {ErrorReporting} = require('@google-cloud/error-reporting');
const errorReporting = new ErrorReporting({
	projectId: config.get('GCLOUD_PROJECT')
});

const app = express();

// Static files
app.use(express.static('frontend/public/'));
github GoogleCloudPlatform / nodejs-getting-started / 5-logging / app.js View on Github external
//
//    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';

// [START debug]
// Activate Google Cloud Trace and Debug when in production
if (process.env.NODE_ENV === 'production') {
  require('@google-cloud/trace-agent').start();
  require('@google-cloud/debug-agent').start();
}
// [END debug]

const path = require('path');
const express = require('express');
const session = require('express-session');
const passport = require('passport');
const config = require('./config');
const logging = require('./lib/logging');
const {Datastore} = require('@google-cloud/datastore');
const DatastoreStore = require('@google-cloud/connect-datastore')(session);

const app = express();

app.disable('etag');
app.set('views', path.join(__dirname, 'views'));
github GoogleCloudPlatform / dlp-cloud-functions-tutorials / gcs-dlp-classification / src / index.js View on Github external
* 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';

// Start the debug agent. Remove or comment out if not required
require('@google-cloud/debug-agent').start();


// User-configurable constants:

// The minimum likelihood required before returning a match
const MIN_LIKELIHOOD = 'LIKELIHOOD_UNSPECIFIED';

// The maximum number of findings to report (0 = server maximum)
const MAX_FINDINGS = 0;

// The infoTypes of information to match
const INFO_TYPES = [
  { name: 'PHONE_NUMBER' },
  { name: 'EMAIL_ADDRESS' },
  { name: 'US_SOCIAL_SECURITY_NUMBER' }
];
github GoogleCloudPlatform / nodejs-serverless-microservices-demo / screenshot / server.js View on Github external
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';

// the following is a workaround:
// Cloud Storage library tries to write in /home/ when uploading a buffer
process.env.HOME = '/tmp';

// Stackdriver APM
const traceApi = require('@google-cloud/trace-agent').start();
require('@google-cloud/debug-agent').start({allowExpressions: true});
require('@google-cloud/profiler').start();

const bodyParser = require('body-parser');
const express = require('express');
const puppeteer = require('puppeteer');
const Storage = require('@google-cloud/storage');

const logger = require('./logger');

const storage = new Storage();

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// Ignore Favicon
github GoogleCloudPlatform / training-data-analyst / courses / developingapps / nodejs / appengine / end / frontend / app.js View on Github external
// 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';
require('@google-cloud/debug-agent').start({ allowExpressions: true });
const ErrorReporting = require('@google-cloud/error-reporting');
const path = require('path');
const express = require('express');
const config = require('./config');

const errorReporting = ErrorReporting({
  projectId: config.get('GCLOUD_PROJECT')
});
const app = express();

// Static files
app.use(express.static('public/'));

app.disable('etag');
app.set('views', path.join(__dirname, 'web-app/views'));
app.set('view engine', 'pug');

@google-cloud/debug-agent

Stackdriver Debug Agent for Node.js

Apache-2.0
Latest version published 4 months ago

Package Health Score

59 / 100
Full package analysis

Popular @google-cloud/debug-agent functions