Removed Sentry span creation from get helper

- this didn't really end up being useful and it just forces us to
  require the `@sentry/node` dependency, so we can remove it
This commit is contained in:
Daniel Lockyer 2024-10-10 09:01:12 +01:00 committed by Daniel Lockyer
parent 2a5ba1c13c
commit e1da082329

View File

@ -7,7 +7,6 @@ const {hbs, SafeString} = require('../services/handlebars');
const logging = require('@tryghost/logging');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const Sentry = require('@sentry/node');
const _ = require('lodash');
const jsonpath = require('jsonpath');
@ -292,53 +291,37 @@ module.exports = async function get(resource, options) {
// Parse the options we're going to pass to the API
apiOptions = parseOptions(ghostGlobals, this, apiOptions);
let apiOptionsString = Object.entries(apiOptions)
.map(([key, value]) => ` ${key}="${value}"`)
.join('');
apiOptions.context = {member: data.member};
try {
const spanName = `{{#get "${resource}"${apiOptionsString}}} ${data.member ? 'member' : 'public'}`;
const result = await Sentry.startSpan({
op: 'frontend.helpers.get',
name: spanName,
tags: {
resource,
...apiOptions,
context: data.member ? 'member' : 'public'
}
}, async (span) => {
const response = await makeAPICall(resource, controllerName, action, apiOptions);
const response = await makeAPICall(resource, controllerName, action, apiOptions);
// prepare data properties for use with handlebars
if (response[resource] && response[resource].length) {
response[resource].forEach(prepareContextResource);
}
// prepare data properties for use with handlebars
if (response[resource] && response[resource].length) {
response[resource].forEach(prepareContextResource);
}
// used for logging details of slow requests
returnedRowsCount = response[resource] && response[resource].length;
span?.setTag('returnedRows', returnedRowsCount);
// used for logging details of slow requests
returnedRowsCount = response[resource] && response[resource].length;
// block params allows the theme developer to name the data using something like
// `{{#get "posts" as |result pageInfo|}}`
const blockParams = [response[resource]];
if (response.meta && response.meta.pagination) {
response.pagination = response.meta.pagination;
blockParams.push(response.meta.pagination);
}
// block params allows the theme developer to name the data using something like
// `{{#get "posts" as |result pageInfo|}}`
const blockParams = [response[resource]];
if (response.meta && response.meta.pagination) {
response.pagination = response.meta.pagination;
blockParams.push(response.meta.pagination);
}
// Call the main template function
const rendered = options.fn(response, {
data: data,
blockParams: blockParams
});
if (response['@@ABORTED_GET_HELPER@@']) {
return new SafeString(`<span data-aborted-get-helper>Could not load content</span>` + rendered);
} else {
return rendered;
}
// Call the main template function
const rendered = options.fn(response, {
data: data,
blockParams: blockParams
});
return result;
if (response['@@ABORTED_GET_HELPER@@']) {
return new SafeString(`<span data-aborted-get-helper>Could not load content</span>` + rendered);
} else {
return rendered;
}
} catch (error) {
logging.error(error);
data.error = error.message;