forked from OpenNeo/impress-2020
Huh, well, I can't figure out what in our production env stopped working with Honeycomb's automatic instrumentation… so, oh well! Let's try disabling it for now and see if it works. This means our Honeycomb logs will no longer include _super helpful_ visualizations of how HTTP requests and MySQL queries create a request dependency waterfall… but I haven't opened Honeycomb in a while, and this bug is blocking all of prod, so if this fixes the site then I'm okay with that as a stopgap! Btw the error message was: ``` Unhandled rejection: TypeError: Cannot read property 'id' of undefined at exports.instrumentLoad (/var/task/node_modules/honeycomb-beeline/lib/instrumentation.js:80:14) at Function._load (/var/task/node_modules/honeycomb-beeline/lib/instrumentation.js:164:16) at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29) at ModuleJob.run (internal/modules/esm/module_job.js:169:25) at Loader.import (internal/modules/esm/loader.js:177:24) ``` Oh also, this is the first time eslint has looked at scripts/build-cached-data.js I guess, so I fixed some lint errors in there.
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
const beeline = require("honeycomb-beeline")({
|
|
writeKey: process.env["HONEYCOMB_WRITE_KEY"],
|
|
dataset:
|
|
process.env["NODE_ENV"] === "production"
|
|
? "Dress to Impress (2020)"
|
|
: "Dress to Impress (2020, dev)",
|
|
serviceName: "impress-2020-gql-server",
|
|
enabledInstrumentations: [],
|
|
});
|
|
import sendgridMail from "@sendgrid/mail";
|
|
|
|
sendgridMail.setApiKey(process.env.SENDGRID_API_KEY);
|
|
|
|
async function handle(req, res) {
|
|
const { content, email } = req.body;
|
|
if (!content) {
|
|
return res.status(400).send("Content must not be empty");
|
|
}
|
|
|
|
let contentSummary = content.trim();
|
|
if (contentSummary.length > 60) {
|
|
contentSummary = contentSummary.slice(0, 40) + "…";
|
|
}
|
|
|
|
const senderText = email || "<anonymous>";
|
|
|
|
console.info(`Sending from ${senderText}:\n${content}`);
|
|
|
|
const body = `${content}\n\nSent by ${senderText}`;
|
|
|
|
try {
|
|
await sendgridMail.send({
|
|
to: "matchu1993@gmail.com",
|
|
from: "impress-2020-feedback@openneo.net",
|
|
subject: `DTI feedback: ${contentSummary}`,
|
|
replyTo: email || undefined,
|
|
text: body,
|
|
});
|
|
} catch (e) {
|
|
console.error(e);
|
|
if (e.response && e.response.body && e.response.body.errors) {
|
|
console.error(e.response.body.errors);
|
|
}
|
|
return res.status(500).send("Error sending message, see logs");
|
|
}
|
|
|
|
return res.status(200).send();
|
|
}
|
|
|
|
async function handleWithBeeline(req, res) {
|
|
beeline.withTrace(
|
|
{ name: "api/sendFeedback", operation_name: "api/sendFeedback" },
|
|
() => handle(req, res)
|
|
);
|
|
}
|
|
|
|
export default handleWithBeeline;
|