-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathModuleConfig.cfc
175 lines (158 loc) · 5.53 KB
/
ModuleConfig.cfc
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
*********************************************************************************
* 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";
this.version = "@build.version@[email protected]@";
// 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,
// Sentry recommends not sending cookie and form data by default
"sendCookies" : false,
"sendPostData" : false,
// Data sanitization, scrub fields and headers, replaced with "[Filtered]" at runtime
"scrubFields" : [],
"scrubHeaders" : [],
"release" : "",
"environment" : ( !isNull( controller ) ? controller.getSetting( "environment" ) : "" ),
"DSN" : "",
"publicKey" : "",
"privateKey" : "",
"projectID" : 0,
"sentryUrl" : "https://sentry.io",
// posting to "#sentryUrl#/api/#projectID#/store" is deprecated, but backward compatible
// set to "envelope" to send events to modern "#sentryUrl#/api/#projectID#/envelope"
"sentryEventEndpoint" : "store",
"serverName" : cgi.server_name,
"appRoot" : expandPath( "/" ),
"sentryVersion" : 7,
// This is not arbitrary but must be a specific value. Leave as "cfml"
// https://docs.sentry.io/development/sdk-dev/attributes/
"platform" : "cfml",
"logger" : ( !isNull( controller ) ? controller.getSetting( "appName" ) : "sentry" ),
"userInfoUDF" : "",
"extraInfoUDFs" : {}
};
// Try to look up the release based on a box.json
if ( !isNull( appmapping ) ) {
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;
}
}
}
}
}
interceptorSettings = { customInterceptionPoints : [ "onSentryEventCapture" ] };
}
/**
* 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;
}
if ( wirebox.containsInstance( "SentryService@sentry" ) ) {
var sentryService = wirebox.getInstance( "SentryService@sentry" );
sentryService.captureException( exception = interceptData.exception, level = "error" );
}
}
// **************************************** PRIVATE ************************************************//
/**
* Load LogBox Appenders
*/
private function loadAppenders(){
// Get config
/*var logBoxConfig = logBox.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
logBox.configure( logBoxConfig );*/
logBox.registerAppender(
name = "sentry_appender",
class = "#moduleMapping#.models.SentryAppender",
levelMin = logBox.logLevels[ settings.levelMin ],
levelMax = logBox.logLevels[ settings.levelMax ]
);
var appenders = logBox.getAppendersMap( "sentry_appender" );
// Register the appender with the root loggger, and turn the logger on.
var root = logBox.getRootLogger();
root.addAppender( appenders[ "sentry_appender" ] );
}
}