Skip to content

Commit 9a499ae

Browse files
committed
Integrate Rollbar some more
1 parent 664362c commit 9a499ae

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

bin/deploy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ TARGET_FILE="${SOURCE_DIRECTORY}/etc/deploy-targets.csv"
99
TARGET_ENV=""
1010
SKIP_COMPOSER=0
1111
SKIP_CONFIRM=0
12+
ROLLBAR_ACCESS_TOKEN="$(cat ${SOURCE_DIRECTORY}/etc/.rollbar-token)"
1213

1314
# Parameter handling
1415
OPTIND=1
@@ -69,7 +70,7 @@ fi
6970
# Break on non-success exit codes
7071
set -e
7172

72-
printf "[1/4] Running composer update...\n"
73+
printf "[1/5] Running composer update...\n"
7374
if [ "${SKIP_COMPOSER}" -ne 1 ]; then
7475
if [ "${TARGET_ENV}" == "production" ]; then
7576
composer update -o --no-dev
@@ -80,7 +81,7 @@ else
8081
printf "skipping step as requested...\n"
8182
fi
8283

83-
printf "[2/4] Generating version information...\n"
84+
printf "[2/5] Generating version information...\n"
8485
# Version identifier
8586
printf "$(git describe --always --tags)\n" \
8687
> ${SOURCE_DIRECTORY}/etc/.rsync-version
@@ -94,7 +95,14 @@ printf "$(git log -n 1 --pretty='%aI' HEAD)\n" \
9495
printf "$(git log -n 1 --pretty='%h %aI' ./LICENSE.txt)" \
9596
>> ${SOURCE_DIRECTORY}/etc/.rsync-version
9697

97-
printf "[3/4] Syncing project to target...\n"
98+
printf "[3/5] Notifying application monitors...\n"
99+
/usr/bin/env curl https://api.rollbar.com/api/1/deploy/ \
100+
-F access_token="${ROLLBAR_ACCESS_TOKEN}" \
101+
-F environment="${TARGET_ENV}" \
102+
-F revision="$(git describe --always --tags)" \
103+
-F local_username="$(id -nu ${UID})"
104+
105+
printf "[4/5] Syncing project to target...\n"
98106
pushd "${SOURCE_DIRECTORY}" >/dev/null
99107
OIFS=$IFS; IFS=,
100108
for host in ${TARGET_HOST}; do
@@ -106,7 +114,7 @@ done
106114
IFS=$OIFS
107115
popd >/dev/null
108116

109-
printf "[4/4] Post-deploy clean up...\n"
117+
printf "[5/5] Post-deploy clean up...\n"
110118
rm ${SOURCE_DIRECTORY}/etc/.rsync-version
111119

112120
printf "Operation complete!\n"

etc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/.rollbar-token
12
/config.phoenix.json
23
/config.redux.json

src/libraries/Logger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ class Logger extends LoggerMVCLib {
1717
protected static $event_types = null;
1818
protected static $rollbar_available = false;
1919

20+
public static function getTimingHeader($tags = true) {
21+
$buffer = parent::getTimingHeader($tags);
22+
if (self::$rollbar_available) {
23+
ob_start();
24+
require('./templates/rollbar.inc.js.phtml');
25+
$buffer .= ob_get_clean();
26+
}
27+
return $buffer;
28+
}
29+
2030
public static function initialize() {
2131
parent::initialize();
2232
if (Common::$config->rollbar->access_token) {

src/templates/rollbar.inc.js.phtml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php namespace BNETDocs\Templates; use CarlBennett\MVC\Libraries\Common; ?>
2+
<script>
3+
var _rollbarConfig = {
4+
accessToken: "<?php echo Common::$config->rollbar->access_token; ?>",
5+
captureUncaught: true,
6+
captureUnhandledRejections: true,
7+
payload: {
8+
environment: "<?php echo Common::$config->rollbar->environment; ?>"
9+
}
10+
};
11+
// Rollbar Snippet
12+
!function(r){function e(t){if(o[t])return o[t].exports;var n=o[t]={exports:{},id:t,loaded:!1};return r[t].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var o={};return e.m=r,e.c=o,e.p="",e(0)}([function(r,e,o){"use strict";var t=o(1).Rollbar,n=o(2);_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://d37gvrvc0wt4s1.cloudfront.net/js/v1.9/rollbar.min.js";var a=t.init(window,_rollbarConfig),i=n(a,_rollbarConfig);a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,i)},function(r,e){"use strict";function o(r){return function(){try{return r.apply(this,arguments)}catch(e){try{console.error("[Rollbar]: Internal error",e)}catch(o){}}}}function t(r,e,o){window._rollbarWrappedError&&(o[4]||(o[4]=window._rollbarWrappedError),o[5]||(o[5]=window._rollbarWrappedError._rollbarContext),window._rollbarWrappedError=null),r.uncaughtError.apply(r,o),e&&e.apply(window,o)}function n(r){var e=function(){var e=Array.prototype.slice.call(arguments,0);t(r,r._rollbarOldOnError,e)};return e.belongsToShim=!0,e}function a(r){this.shimId=++c,this.notifier=null,this.parentShim=r,this._rollbarOldOnError=null}function i(r){var e=a;return o(function(){if(this.notifier)return this.notifier[r].apply(this.notifier,arguments);var o=this,t="scope"===r;t&&(o=new e(this));var n=Array.prototype.slice.call(arguments,0),a={shim:o,method:r,args:n,ts:new Date};return window._rollbarShimQueue.push(a),t?o:void 0})}function l(r,e){if(e.hasOwnProperty&&e.hasOwnProperty("addEventListener")){var o=e.addEventListener;e.addEventListener=function(e,t,n){o.call(this,e,r.wrap(t),n)};var t=e.removeEventListener;e.removeEventListener=function(r,e,o){t.call(this,r,e&&e._wrapped?e._wrapped:e,o)}}}var c=0;a.init=function(r,e){var t=e.globalAlias||"Rollbar";if("object"==typeof r[t])return r[t];r._rollbarShimQueue=[],r._rollbarWrappedError=null,e=e||{};var i=new a;return o(function(){if(i.configure(e),e.captureUncaught){i._rollbarOldOnError=r.onerror,r.onerror=n(i);var o,a,c="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(o=0;o<c.length;++o)a=c[o],r[a]&&r[a].prototype&&l(i,r[a].prototype)}return e.captureUnhandledRejections&&(i._unhandledRejectionHandler=function(r){var e=r.reason,o=r.promise,t=r.detail;!e&&t&&(e=t.reason,o=t.promise),i.unhandledRejection(e,o)},r.addEventListener("unhandledrejection",i._unhandledRejectionHandler)),r[t]=i,i})()},a.prototype.loadFull=function(r,e,t,n,a){var i=function(){var e;if(void 0===r._rollbarPayloadQueue){var o,t,n,i;for(e=new Error("rollbar.js did not load");o=r._rollbarShimQueue.shift();)for(n=o.args,i=0;i<n.length;++i)if(t=n[i],"function"==typeof t){t(e);break}}"function"==typeof a&&a(e)},l=!1,c=e.createElement("script"),p=e.getElementsByTagName("script")[0],d=p.parentNode;c.crossOrigin="",c.src=n.rollbarJsUrl,c.async=!t,c.onload=c.onreadystatechange=o(function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){c.onload=c.onreadystatechange=null;try{d.removeChild(c)}catch(r){}l=!0,i()}}),d.insertBefore(c,p)},a.prototype.wrap=function(r,e){try{var o;if(o="function"==typeof e?e:function(){return e||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._wrapped){r._wrapped=function(){try{return r.apply(this,arguments)}catch(e){throw"string"==typeof e&&(e=new String(e)),e._rollbarContext=o()||{},e._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=e,e}},r._wrapped._isWrap=!0;for(var t in r)r.hasOwnProperty(t)&&(r._wrapped[t]=r[t])}return r._wrapped}catch(n){return r}};for(var p="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError,unhandledRejection".split(","),d=0;d<p.length;++d)a.prototype[p[d]]=i(p[d]);r.exports={Rollbar:a,_rollbarWindowOnError:t}},function(r,e){"use strict";r.exports=function(r,e){return function(o){if(!o&&!window._rollbarInitialized){var t=window.RollbarNotifier,n=e||{},a=n.globalAlias||"Rollbar",i=window.Rollbar.init(n,r);i._processShimQueue(window._rollbarShimQueue||[]),window[a]=i,window._rollbarInitialized=!0,t.processPayloads()}}}}]);
13+
// End Rollbar Snippet
14+
</script>

0 commit comments

Comments
 (0)