Query error monitoring and Slack notifications

Ever thought about error monitoring for your failing queries? Me too, this is what I came up with after going down the rabbit hole.

This is best solution I could come up with:

  • 1 main JS Query acting as the router for all failing query data
  • 1 main Slack Query that sends that data to a channel

The drawback is that you need to explicitly reference the queries you want to listen to in your main JS query so their payload is available to you on execution as currently all queries get sandboxed only with the data that is referenced in the query for performance reasons.

tldr; You need to add all queries you want to monitor to the file.

This is how my router looks like:

var triggerQueryId = triggeredById

var triggerQuery = {
  get_users: get_users.data,
  get_vacations_for_user: get_vacations_for_user.data,
  get_user_attributes: get_user_attributes.data

// meta info
var userEmail = current_user.email
var isPreview = triggerQuery.queryExecutionMetadata.isPreview
var appName = app_info.value.name
var appUrl = app_info.value.url
var exactDateTime = moment().tz('America/Chicago').format('MM/DD/YY hh:mma')

// device info
var browserName, os
var userAgent = window.navigator.userAgent
var platform = window.navigator.platform
var macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
var windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']
var iosPlatforms = ['iPhone', 'iPad', 'iPod']

if(userAgent.match(/chrome|chromium|crios/i)) {
 browserName = "Chrome";
} else if(userAgent.match(/firefox|fxios/i)) {
 browserName = "Firefox";
}  else if(userAgent.match(/safari/i)) {
 browserName = "Safari";
} else if(userAgent.match(/opr\//i)) {
 browserName = "Opera";
} else if(userAgent.match(/edg/i)) {
 browserName = "Edge";
} else {
 browserName = "No browser detected";

if (macosPlatforms.indexOf(platform) !== -1) {
  os = 'Mac OS';
} else if (iosPlatforms.indexOf(platform) !== -1) {
  os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
  os = 'Windows';
} else if (/Android/.test(userAgent)) {
  os = 'Android';
} else if (!os && /Linux/.test(platform)) {
  os = 'Linux';

// error info
var errorMessage = triggerQuery.message
var errorPosition = triggerQuery.position
var errorSource = triggerQuery.source
var errorResourceType = triggerQuery.queryExecutionMetadata.resourceType
var errorResourceTimeMs = triggerQuery.queryExecutionMetadata.resourceTimeTakenMs

// only send notifications when in preview mode
if (isPreview) {
    additionalScope: {
      message: errorMessage,
} else {
    userEmail: userEmail,
    appName: appName,
    appUrl: appUrl,
    errorMessage: errorMessage,
    errorSource: errorSource,
    errorResourceType: errorResourceType,
    errorPosition: errorPosition,
    errorResourceTimeMs: errorResourceTimeMs,
    exactDateTime: exactDateTime,
    browserName: browserName,
    os: os,
    triggerQuery: triggerQueryId

That's it, very open to feedback to improve this!

Update: I'm continuing to build this out over here