-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Environment
SaaS (https://sentry.io/)
Version
No response
Steps to Reproduce
- Self host
strapi@latest - Add official
@strapi/sentryplugin - Add
@sentry/nodeand@sentry/tracinglatest - Add a sentry middleware at
src/middlewares/sentry.js
const Sentry = require("@sentry/node");
const {
extractTraceparentData,
stripUrlQueryAndFragment,
} = require("@sentry/tracing");
//https://docs.sentry.io/platforms/node/guides/koa/
Sentry.init({
dsn: process.env.DSN,
environment: strapi.config.environment,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
],
tracesSampleRate: 1,
});
const tracingMiddleWare = async (ctx) => {
const reqMethod = (ctx.method || "").toUpperCase();
const reqUrl = ctx.url && stripUrlQueryAndFragment(ctx.url);
// connect to trace of upstream app
let traceparentData;
if (ctx.request.get("sentry-trace")) {
traceparentData = extractTraceparentData(ctx.request.get("sentry-trace"));
}
const transaction = Sentry.startTransaction({
name: `${reqMethod} ${reqUrl}`,
op: "http.server",
...traceparentData,
});
ctx.__sentry_transaction = transaction;
Sentry.getCurrentHub().configureScope((scope) => {
scope.setSpan(transaction);
});
ctx.res.on("finish", () => {
setImmediate(() => {
if (ctx._matchedRoute) {
const mountPath = ctx.mountPath || "";
transaction.setName(`${reqMethod} ${mountPath}${ctx._matchedRoute}`);
}
transaction.setHttpStatus(ctx.status);
transaction.finish();
});
});
};
module.exports = (config, { strapi }) => {
strapi.server.use(async (context, next) => {
try {
await tracingMiddleWare(context, next);
} catch (error) {
Sentry.captureException(error);
throw error;
}
});
};- Initialise
@strapi/sentryatconfig/middlewares.jsasglobal::sentry - Add sentry plugin to
config/plugins.jsas
sentry: {
enabled: true,
config: {
dsn: env("DSN"),
sendMetadata: true,
},
},Expected Result
Sentry should trace the transactions made by the API calls during navigation strapi or doing graphql queries. The exact thing worked for strapi v3 but after upgrading to v4 it broke and in the context request there are no headers for sentry-tracing
Actual Result
Metadata
Metadata
Assignees
Labels
No labels
