This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
103 lines (94 loc) · 3.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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';
// Check if Koa is usable
var useKoa = true;
try {
eval('(function *() {})');
} catch (e) {
useKoa = false;
}
var Configuration = require('./lib/configuration.js');
var AuthClient = require('./lib/google-apis/auth-client.js');
// Begin error reporting interfaces
var koa = useKoa ? require('./lib/interfaces/koa.js') : null;
var hapi = require('./lib/interfaces/hapi.js');
var manual = require('./lib/interfaces/manual.js');
var express = require('./lib/interfaces/express.js');
var restify = require('./lib/interfaces/restify');
var uncaughtException = require('./lib/interfaces/uncaught.js');
var createLogger = require('./lib/logger.js');
/**
* @typedef ConfigurationOptions
* @type Object
* @property {String} [projectId] - the projectId of the project deployed
* @property {String} [keyFilename] - path to a key file to use for an API key
* @property {String|Number} logLevel - a integer between and including 0-5 or a
* decimal representation of an integer including and between 0-5 in String
* form
* @property {String} [key] - API key to use for communication with the service
* @property {uncaughtHandlingEnum}
* [onUncaughtException=uncaughtHandlingEnum.ignore] - one of the uncaught
* handling options
* @property {Object} [serviceContext] - the service context of the application
* @property {String} [serviceContext.service] - the service the application is
* running on
* @property {String} [serviceContext.version] - the version the hosting
* application is currently labelled as
* @property {Boolean} [ignoreEnvironmentCheck] - flag indicating whether or not
* to communicate errors to the Stackdriver service even if NODE_ENV is not set
* to production
*/
/**
* @typedef ApplicationErrorReportingInterface
* @type Object
* @property {Object} hapi - The hapi plugin for Stackdriver Error Reporting
* @property {Function} report - The manual interface to report Errors to the
* Stackdriver Error Reporting Service
* @property {Function} express - The express plugin for Stackdriver Error
* Reporting
*/
/**
* The entry point for initializing the Error Reporting Middleware. This
* function will invoke configuration gathering and attempt to create a API
* client which will send errors to the Error Reporting Service. Invocation of
* this function will also return an interface which can be used manually via
* the `report` function property, with hapi via the `hapi` object property or
* with express via the `express` function property.
* @function initConfiguration
* @param {ConfigurationOptions} initConfiguration - the desired project/error
* reporting configuration
* @returns {ApplicationErrorReportingInterface} - The error reporting interface
*/
function initializeClientAndInterfaces (initConfiguration) {
var logger = createLogger(initConfiguration);
var config = new Configuration(initConfiguration, logger);
var client = new AuthClient(config, logger);
// Setup the uncaught exception handler
uncaughtException(client, config);
// Return the application interfaces for use by the hosting application
var result = {
hapi: hapi(client, config),
report: manual(client, config),
express: express(client, config),
restify: restify(client, config)
};
if (koa) {
result.koa = koa(client, config);
}
return result;
}
module.exports = {start: initializeClientAndInterfaces};