This repository was archived by the owner on Mar 14, 2020. It is now read-only.
forked from newrelic/node-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (53 loc) · 2.16 KB
/
index.js
File metadata and controls
61 lines (53 loc) · 2.16 KB
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
'use strict';
var path = require('path')
, logger = require(path.join(__dirname, 'lib', 'logger'))
, shimmer = require(path.join(__dirname, 'lib', 'shimmer'))
, Agent = require(path.join(__dirname, 'lib', 'agent'))
, API = require(path.join(__dirname, 'api'))
;
try {
logger.debug("Process was running %s seconds before agent was loaded.",
process.uptime());
if (process.version && process.version.split('.')[1] < 6) {
var message = "The New Relic agent requires a version of Node equal to or " +
"greater than 0.6.0. Not starting!";
logger.error(message);
console.error(message);
return;
}
logger.debug("Current working directory at agent load is %s.", process.cwd());
logger.debug("Process title is %s.", process.title);
logger.debug("Application was invoked as %s.", process.argv.join(' '));
var agent = new Agent();
/*
* Don't set up the rest of the agent if it didn't successfully load its
* configuration.
*/
if (agent.config) {
if (agent.config.applications().length < 1) {
console.error("New Relic requires that you name this application!");
console.error("Set app_name in your newrelic.js file or set environment variable");
console.error("NEW_RELIC_APP_NAME. Not starting!");
logger.error("No application name set. Not starting!");
return;
}
/* In order to ensure all user code is using instrumented versions of
* modules, instrumentation must be loaded at startup regardless of whether
* or not the agent is enabled in the config. It should be possible for
* users to switch the agent on and off at runtime.
*
* This also requires the agent to be a singleton, or else module loading
* will be patched multiple times, with undefined results.
*/
shimmer.patchModule(agent);
shimmer.bootstrapInstrumentation(agent);
agent.start();
}
module.exports = new API(agent);
}
catch (error) {
logger.error(error,
"The New Relic Node.js agent was unable to start due to an error:");
console.error("The New Relic Node.js agent was unable to start due to an error:");
console.error(error.stack);
}