-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Meta: Help WantedPackage: nodeIssues related to the Sentry Node SDKIssues related to the Sentry Node SDK
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/node
SDK Version
7.1.2
Framework Version
Strapi 4.3.4
Link to Sentry event
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
Meta: Help WantedPackage: nodeIssues related to the Sentry Node SDKIssues related to the Sentry Node SDK
