Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 14 additions & 65 deletions forge/forge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cookie = require('@fastify/cookie')
const csrf = require('@fastify/csrf-protection')
const helmet = require('@fastify/helmet')
const { ProfilingIntegration } = require('@sentry/profiling-node')
const Sentry = require('@sentry/node')
const fastify = require('fastify')

const auditLog = require('./auditLog')
Expand Down Expand Up @@ -139,6 +139,15 @@ module.exports = async (options = {}) => {
}
}
}
if (runtimeConfig.telemetry.backend?.sentry?.dsn) {
Sentry.init({
dsn: runtimeConfig.telemetry.backend.sentry.dsn,
sendClientReports: true,
environment: process.env.SENTRY_ENV ?? (process.env.NODE_ENV ?? 'unknown'),
release: `flowfuse@${runtimeConfig.version}`
})
}

const server = fastify({
forceCloseConnections: true,
bodyLimit: 10485760, // 10mb max payload size, set to allow for VERY large flows
Expand All @@ -151,75 +160,15 @@ module.exports = async (options = {}) => {
pluginTimeout: 20000
})

if (runtimeConfig.telemetry.backend?.sentry?.dsn) {
Sentry.setupFastifyErrorHandler(server)
}

if (runtimeConfig.telemetry.backend?.prometheus?.enabled) {
const metricsPlugin = require('fastify-metrics')
await server.register(metricsPlugin, { endpoint: '/metrics' })
}

if (runtimeConfig.telemetry.backend?.sentry?.dsn) {
const environment = process.env.SENTRY_ENV ?? (process.env.NODE_ENV ?? 'unknown')
const sentrySampleRate = environment === 'production' ? 0.1 : 0.5
server.register(require('@immobiliarelabs/fastify-sentry'), {
dsn: runtimeConfig.telemetry.backend.sentry.dsn,
sendClientReports: true,
environment,
release: `flowfuse@${runtimeConfig.version}`,
profilesSampleRate: sentrySampleRate, // relative to output from tracesSampler
integrations: [
new ProfilingIntegration()
],
extractUserData (request) {
const user = request.session?.User || request.user
if (!user) {
return {}
}
const extractedUser = {
id: user.hashid,
username: user.username,
email: user.email,
name: user.name
}

return extractedUser
},
tracesSampler: (samplingContext) => {
// Adjust sample rates for routes with high volumes, sorted descending by volume

// Used for mosquitto auth
if (samplingContext?.transactionContext?.name === 'POST /api/comms/auth/client' || samplingContext?.transactionContext?.name === 'POST /api/comms/auth/acl') {
return 0.001
}

// Used by nr-launcher and for nr-auth
if (samplingContext?.transactionContext?.name === 'GET POST /account/token') {
return 0.01
}

// Common endpoints in app (list devices by team, list devices by project)
if (samplingContext?.transactionContext?.name === 'GET /api/v1/teams/:teamId/devices' || samplingContext?.transactionContext?.name === 'GET /api/v1/projects/:instanceId/devices') {
return 0.01
}

// Used by device editor device tunnel
if (samplingContext?.transactionContext?.name === 'GET /api/v1/devices/:deviceId/editor/proxy/*') {
return 0.01
}

// Prometheus scraping
if (samplingContext?.transactionContext?.name === 'GET /metrics') {
return 0.01
}

// OAuth check
if (samplingContext?.transactionContext?.name === 'GET /account/check/:ownerType/:ownerId') {
return 0.01
}

return sentrySampleRate
}
})
}

server.addHook('onError', async (request, reply, error) => {
// Useful for debugging when a route goes wrong
// console.error(error.stack)
Expand Down
58 changes: 3 additions & 55 deletions forge/housekeeper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { captureCheckIn, captureException } = require('@sentry/node')
const { captureException } = require('@sentry/node')
const { scheduleTask } = require('cronosjs')
const fp = require('fastify-plugin')

Expand Down Expand Up @@ -41,56 +41,7 @@ module.exports = fp(async function (app, _opts) {
clearInterval(voteInterval)
})

function reportTask (name, schedule) {
try {
return captureCheckIn({
monitorSlug: name,
status: 'in_progress'
},
{
schedule: {
type: 'crontab',
value: schedule
},
checkinMargin: 5,
maxRuntime: 5,
timezone: 'Etc/UTC'
})
} catch (error) {
app.log.warn('Failed to report to Sentry', error)
}
}

function reportTaskComplete (checkInId, name) {
if (!checkInId) {
return
}

try {
captureCheckIn({
checkInId,
monitorSlug: name,
status: 'ok'
})
} catch (error) {
app.log.warn('Failed to report task complete to Sentry', error)
}
}

function reportTaskFailure (checkInId, name, errorMessage) {
if (checkInId) {
try {
captureCheckIn({
checkInId,
monitorSlug: name,
status: 'error',
errorMessage
})
} catch (error) {
app.log.warn('Failed to report task failure to Sentry', error)
}
}

function reportTaskFailure (errorMessage) {
try {
captureException(new Error(errorMessage))
} catch (error) {
Expand Down Expand Up @@ -119,16 +70,13 @@ module.exports = fp(async function (app, _opts) {
if (checkVote()) {
app.log.trace(`Running task '${task.name}'`)

const checkInId = reportTask(task.name, task.schedule)

return task
.run(app)
.then(reportTaskComplete.bind(this, checkInId, task.name))
.catch(err => {
const errorMessage = `Error running task '${task.name}: ${err.toString()}`

app.log.error(errorMessage)
reportTaskFailure(checkInId, task.name, errorMessage)
reportTaskFailure(errorMessage)
}).then(() => {
app.log.trace(`Completed task '${task.name}'`)
return null
Expand Down
4 changes: 4 additions & 0 deletions forge/routes/auth/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const Sentry = require('@sentry/node')

/**
* Routes related to session handling, login/out etc
*
Expand Down Expand Up @@ -72,6 +74,7 @@ async function init (app, opts) {
const mfaMissing = request.session.User.mfa_enabled && !request.session.mfa_verified

if (emailVerified && passwordNotExpired && !suspended && !mfaMissing) {
Sentry.setUser({ id: request.session.User.hashid, username: request.session.User.username, email: request.session.User.email, name: request.session.User.name })
return
}
if (request.routeOptions.config.allowAnonymous) {
Expand Down Expand Up @@ -116,6 +119,7 @@ async function init (app, opts) {
reply.code(401).send({ code: 'unauthorized', error: 'unauthorized' })
return
}
Sentry.setUser({ id: request.session.User.hashid, username: request.session.User.username, email: request.session.User.email, name: request.session.User.name })
if (accessToken.name) {
// Temp hack to give token full user scope
delete request.session.scope
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/PageHeader.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="ff-header" data-sentry-unmask>
<div class="ff-header">
<!-- Mobile: Toggle(Team & Team Admin Options) -->
<i v-if="!hiddenLeftDrawer && !editorImmersiveDrawer.active" class="ff-header--mobile-toggle">
<transition name="mobile-menu-fade" mode="out-in">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SectionNavigationHeader.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="ff-page-header border-b text-gray-500 justify-between px-7 pt-3 gap-y-4 items-center" data-sentry-unmask>
<div class="ff-page-header border-b text-gray-500 justify-between px-7 pt-3 gap-y-4 items-center">
<div class="flex flex-wrap justify-between pb-3 gap-y-2">
<div class="flex-1 flex items-center md:w-auto mr-8 gap-x-2">
<slot name="hero">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/dialogs/EducationModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div v-if="isOpen" class="ff-dialog-box education-modal">
<div class="ff-dialog-header text-center" data-sentry-unmask>
<div class="ff-dialog-header text-center">
Welcome to FlowFuse!
</div>
<div class="ff-dialog-content">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const app = createApp(App)
const servicesOrchestrator = getServicesOrchestrator()

// Error tracking
setupSentry(app, router)
setupSentry(app)

// Boot all services before mounting
servicesOrchestrator.init(app, router)
Expand Down
37 changes: 2 additions & 35 deletions frontend/src/services/error-tracking.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {
BrowserTracing,
Replay,
init,
vueRouterInstrumentation
} from '@sentry/vue'
import { init } from '@sentry/vue'

export const setupSentry = (app, router) => {
export const setupSentry = (app) => {
if (!window.sentryConfig) {
return
}
Expand All @@ -15,40 +10,12 @@ export const setupSentry = (app, router) => {
init({
app,
dsn,
integrations: [
new BrowserTracing({
routingInstrumentation: vueRouterInstrumentation(router),
shouldCreateSpanForRequest: (url) => {
// Exclude broker status polling (fires every 5s). PUT/DELETE on
// the same URL pattern are also excluded — acceptable trade-off.
if (/\/brokers\/[^/]+$/.test(url)) {
return false
}
return true
}
}),
new Replay()
],
sendClientReports: true,

// Current build info
release: window.sentryConfig.version,
environment: window.sentryConfig.environment,

// Performance Monitoring
tracesSampleRate: window.sentryConfig.production ? 0.05 : 0.5,

// Which URLs distributed tracing should be enabled
tracePropagationTargets: [
/app\.flow(forge|fuse).com\/api/,
/forge\.flow(forge|fuse).dev\/api/,
/^\//
],

// Session Replay
replaysSessionSampleRate: window.sentryConfig.production ? 0.01 : 0.1,
replaysOnErrorSampleRate: 0.1,

// PostHog rrweb noise on cross-origin iframe teardown — see #7052
ignoreErrors: [
/bufferBelongsToIframe/
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ui-components/components/DialogBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
v-bind="$attrs"
>
<div class="ff-dialog-box" :class="boxClass">
<div class="ff-dialog-header" :class="{ 'ff-dialog-header--light': headerVariant === 'light' }" data-sentry-unmask>
<div class="ff-dialog-header" :class="{ 'ff-dialog-header--light': headerVariant === 'light' }">
<slot name="header">
{{ header }}
<span v-if="subHeader" class="ff-dialog-subheader">{{ subHeader }}</span>
Expand Down
Loading
Loading