Skip to content

Commit

Permalink
continue checking sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
inikoo committed Jan 5, 2025
1 parent cf92c20 commit 711ea54
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
2 changes: 2 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Http;

use App\Http\Middleware\AddSentryBrowserProfilingHeader;
use App\Http\Middleware\ApiBindGroupInstance;
use App\Http\Middleware\HandlePupilInertiaRequests;
use App\Http\Middleware\RetinaPreparingAccount;
Expand Down Expand Up @@ -64,6 +65,7 @@ class Kernel extends HttpKernel
ValidatePostSize::class,
TrimStrings::class,
ConvertEmptyStringsToNull::class,
AddSentryBrowserProfilingHeader::class
];

protected $middlewareGroups = [
Expand Down
22 changes: 22 additions & 0 deletions app/Http/Middleware/AddSentryBrowserProfilingHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/*
* Author: Raul Perusquia <raul@inikoo.com>
* Created: Sun, 05 Jan 2025 23:58:53 Malaysia Time, Kuala Lumpur, Malaysia
* Copyright (c) 2025, Raul A Perusquia Flores
*/

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class AddSentryBrowserProfilingHeader
{

public function handle(Request $request, Closure $next)
{
$response = $next($request);
$response->headers->set('Document-Policy', 'js-profiling');
return $response;
}
}
61 changes: 32 additions & 29 deletions resources/js/app-grp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./bootstrap";
import "../css/app.css";

import { createApp, h } from "vue";
import { createInertiaApp , router} from "@inertiajs/vue3";
import { createInertiaApp, router } from "@inertiajs/vue3";
import { ZiggyVue } from "../../vendor/tightenco/ziggy/dist/vue.m";
import { i18nVue } from "laravel-vue-i18n";
import Notifications from "@kyvg/vue3-notification";
Expand All @@ -17,7 +17,6 @@ import Aura from "@primevue/themes/aura";
import { definePreset } from "@primevue/themes";
import ConfirmationService from "primevue/confirmationservice";


const appName = capitalize(
window.document.getElementsByTagName("title")[0]?.innerText) ||
"Aiku";
Expand All @@ -40,7 +39,6 @@ const MyPreset = definePreset(Aura, {
}
});


createInertiaApp(
{
title : (title) => `${title} - ${appName}`,
Expand All @@ -59,17 +57,20 @@ createInertiaApp(
dsn : import.meta.env.VITE_SENTRY_DSN,
environment : import.meta.env.VITE_APP_ENV,
release : import.meta.env.VITE_RELEASE,
debug : true,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
profilesSampleRate : 1.0,
integrations : [
new Sentry.BrowserTracing({
// Helps to send page load and navigation OPs to Sentry for InertiaJS
routingInstrumentation: inertiaRoutingInstrumentation,
enableInp: true,
enableInp: true
}),
Sentry.browserProfilingIntegration(),
Sentry.replayIntegration(),
Sentry.httpClientIntegration(),
Sentry.browserTracingIntegration(),
Sentry.browserProfilingIntegration()

]
});
}
Expand All @@ -85,8 +86,8 @@ createInertiaApp(
preset : MyPreset,
options: {
darkModeSelector: ".my-app-dark" // dark mode of Primevue
// depends .my-add-dark in
// <html>
// depends .my-add-dark in
// <html>
}
}
}).
Expand All @@ -108,53 +109,55 @@ createInertiaApp(
//https://github.com/getsentry/sentry-javascript/issues/11362
function inertiaRoutingInstrumentation(
customStartTransaction,
startTransactionOnPageLoad = true,
startTransactionOnLocationChange = true,
startTransactionOnPageLoad = true,
startTransactionOnLocationChange = true
) {
console.info('inertiaRoutingInstrumentation Started');
console.info("inertiaRoutingInstrumentation Started");

let activeTransaction;
let name;
if (startTransactionOnPageLoad) {
console.info('Start transaction on page load');
name = '/'+route().current();
console.info("Start transaction on page load");
name = "/" + route().current();

activeTransaction = customStartTransaction({
name,
op: 'pageload',
op : "pageload",
metadata: {
source: 'route',
},
source: "route"
}
});
}

if (startTransactionOnLocationChange) {
console.info('Start transaction on location change');
router.on('before', (_to, _from) => {
console.info("Start transaction on location change");

router.on("before", (_to, _from) => {
if (activeTransaction) {
activeTransaction.finish();
}

const newName = '/'+route().current();
console.info('Old name: '+name+'. New name: '+newName)
const newName = "/" + route().current();
console.info("Old name: " + name + ". New name: " + newName);

if (newName !== name) {
console.info('Old name is not equal to new name!');
console.info("Old name is not equal to new name!");
activeTransaction = customStartTransaction({
name: newName,
op: 'navigation',
name : newName,
op : "navigation",
metadata: {
source: 'route',
},
source: "route"
}
});
}
});

router.on('finish', () => {
console.info('Router on finish. Route: '+'/'+route().current())
activeTransaction.setName('/'+route().current(), 'route');
router.on("finish", () => {
console.info("Router on finish. Route: " + "/" + route().current());
activeTransaction.setName("/" + route().current(), "route");
});
}
console.info('inertiaRoutingInstrumentation Finished');
console.info("inertiaRoutingInstrumentation Finished");
}


0 comments on commit 711ea54

Please sign in to comment.