forked from coldbox-modules/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleConfig.cfc
More file actions
145 lines (129 loc) · 4.18 KB
/
Copy pathModuleConfig.cfc
File metadata and controls
145 lines (129 loc) · 4.18 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
*********************************************************************************
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* Module Config.
*/
component {
// Module Properties
this.title = 'sentry';
this.author = 'Ortus Solutions';
this.webURL = 'https://www.ortussolutions.com';
this.description = 'A module to log and send bug reports to Sentry';
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = true;
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = true;
this.cfmapping = "sentry";
this.dependencies = [ 'funclinenums' ];
// STATIC SCRUB FIELDS
variables.SCRUB_FIELDS = [ 'passwd', 'password', 'password_confirmation', 'secret', 'confirm_password', 'secret_token', 'APIToken', 'x-api-token', 'fwreinit' ];
variables.SCRUB_HEADERS = [ 'x-api-token', 'Authorization' ];
/**
* Configure
*/
function configure(){
settings = {
// Sentry token
'ServerSideToken' = '',
// Enable the Sentry LogBox Appender Bridge
'enableLogBoxAppender' = true,
'async' = true,
// Min/Max levels for appender
'levelMin' = 'FATAL',
'levelMax' = 'ERROR',
// Enable/disable error logging
'enableExceptionLogging' = true,
// Data sanitization, scrub fields and headers, replaced with "[Filtered]" at runtime
'scrubFields' = [],
'scrubHeaders' = [],
'release' = '',
'environment' = controller.getSetting( 'environment' ),
'DSN' = '',
'publicKey' = '',
'privateKey' = '',
'projectID' = 0,
'sentryUrl' = 'https://sentry.io',
'serverName' = cgi.server_name,
'appRoot' = expandPath('/'),
'sentryVersion' = 7,
// This is not arbityrary but must be a specific value. Leave as "cfml"
// https://docs.sentry.io/development/sdk-dev/attributes/
'platform' = 'cfml',
'logger' = controller.getSetting( 'appName' ),
'userInfoUDF' = ''
};
// Try to look up the release based on a box.json
var boxJSONPath = expandPath( '/' & appmapping & '/box.json' );
if( fileExists( boxJSONPath ) ) {
var boxJSONRaw = fileRead( boxJSONPath );
if( isJSON( boxJSONRaw ) ) {
var boxJSON = deserializeJSON( boxJSONRaw );
if( boxJSON.keyExists( 'version' ) ) {
settings.release = boxJSON.version;
if( boxJSON.keyExists( 'slug' ) ) {
settings.release = boxJSON.slug & '@' & settings.release;
} else if( boxJSON.keyExists( 'name' ) ) {
settings.release = boxJSON.name & '@' & settings.release;
}
}
}
}
}
/**
* Fired when the module is registered and activated.
*/
function onLoad(){
// Incorporate defaults into settings
settings.scrubFields.addAll( SCRUB_FIELDS );
settings.scrubHeaders.addAll( SCRUB_HEADERS );
// Load the LogBox Appenders
if( settings.enableLogBoxAppender ){
loadAppenders();
}
}
/**
* Fired when the module is unregistered and unloaded
*/
function onUnload(){
}
/**
* Trap exceptions and send them to Sentry
*/
function onException( event, interceptData, buffer ){
if( !settings.enableExceptionLogging ){
return;
}
var sentryService = wirebox.getInstance( 'SentryService@sentry' );
sentryService.captureException(
exception = interceptData.exception,
level = 'error'
);
}
//**************************************** PRIVATE ************************************************//
/**
* Load LogBox Appenders
*/
private function loadAppenders(){
// Get config
var logBoxConfig = controller.getLogBox().getConfig();
var rootConfig = '';
// Register tracer appender
rootConfig = logBoxConfig.getRoot();
logBoxConfig.appender(
name = 'sentry_appender',
class = '#moduleMapping#.models.SentryAppender',
levelMin = settings.levelMin,
levelMax = settings.levelMax
);
logBoxConfig.root(
levelMin = rootConfig.levelMin,
levelMax = rootConfig.levelMax,
appenders= listAppend( rootConfig.appenders, 'sentry_appender')
);
// Store back config
controller.getLogBox().configure( logBoxConfig );
}
}