Skip to content

Commit

Permalink
Merge pull request #2903 from FlowFuse/chore-enable-sentry-tracing
Browse files Browse the repository at this point in the history
Error Tracking: Tweaks
  • Loading branch information
Pezmc authored Oct 6, 2023
2 parents 8ab0141 + 1606927 commit 94ad6d7
Show file tree
Hide file tree
Showing 6 changed files with 1,155 additions and 70 deletions.
22 changes: 21 additions & 1 deletion forge/forge.js
Original file line number Diff line number Diff line change
@@ -1,6 +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 fastify = require('fastify')

const auditLog = require('./auditLog')
Expand Down Expand Up @@ -87,7 +88,26 @@ module.exports = async (options = {}) => {
server.register(require('@immobiliarelabs/fastify-sentry'), {
dsn: runtimeConfig.telemetry.backend.sentry.dsn,
environment: process.env.NODE_ENV,
release: `flowforge@${runtimeConfig.version}`
release: `flowfuse@${runtimeConfig.version}`,
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
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
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion forge/routes/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = async function (app) {
}

if (telemetry.frontend?.sentry?.dsn) {
injection += `<script>window.sentryConfig = { dsn: "${telemetry.frontend.sentry.dsn}", production_mode: "${telemetry.frontend.sentry.production_mode ?? true}" }</script>`
injection += `<script>window.sentryConfig = { dsn: "${telemetry.frontend.sentry.dsn}", production_mode: ${telemetry.frontend.sentry.production_mode ?? true}, version: "flowfuse@${config.version}", }</script>`
}

// inject into index.html
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/services/error-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Replay,
init,
vueRouterInstrumentation

} from '@sentry/vue'

export const setupSentry = (app, router) => {
Expand All @@ -18,16 +17,19 @@ export const setupSentry = (app, router) => {
dsn,
integrations: [
new BrowserTracing({
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
tracePropagationTargets: [/^https:\/\/forge.flowforge.dev\/api/, /^https:\/\/app.flowforge.com\//],
routingInstrumentation: vueRouterInstrumentation(router)
}),
new Replay()
],

release: window.sentryConfig.version,

// Performance Monitoring
tracesSampleRate: window.sentryConfig.production ? 1.0 : 0.1,

// Which URLs distributed tracing should be enabled
tracePropagationTargets: [/^https:\/\/forge.flowforge.dev\/api/, /^https:\/\/app.flowforge.com\//],

// Session Replay
replaysSessionSampleRate: window.sentryConfig.production ? 0.1 : 0.5,
replaysOnErrorSampleRate: 1.0,
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/services/product.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { setUser } from '@sentry/vue'

/**
*
* @param {String} userId - the unique identifier for the user
Expand All @@ -6,6 +8,12 @@
*/
function identify (userId, set, setonce) {
window.posthog?.identify(userId, set, setonce)
if (window.sentryConfig) {
setUser({
...set,
...setonce
})
}
}

/**
Expand Down
Loading

0 comments on commit 94ad6d7

Please sign in to comment.