From 2c97c7f1c2485605987cbfe3bfea5044140c519d Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Mon, 9 Dec 2024 13:42:33 -0500 Subject: [PATCH] Enable sourcemaps for legible stack traces in lambdas Fixes #2769. --- app/email-incoming/circulars/index.ts | 1 + app/email-incoming/support/index.ts | 1 + app/scheduled/ads/index.ts | 1 + app/scheduled/circulars/index.ts | 2 ++ app/table-streams/circulars/index.ts | 1 + app/table-streams/synonyms/index.ts | 1 + esbuild.js | 3 ++- package.json | 2 +- server.ts | 3 +-- 9 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/email-incoming/circulars/index.ts b/app/email-incoming/circulars/index.ts index f11ec70d3..61f637e2f 100644 --- a/app/email-incoming/circulars/index.ts +++ b/app/email-incoming/circulars/index.ts @@ -6,6 +6,7 @@ * SPDX-License-Identifier: Apache-2.0 */ import { tables } from '@architect/functions' +import 'source-map-support/register' import { bodyIsValid, diff --git a/app/email-incoming/support/index.ts b/app/email-incoming/support/index.ts index 0f9561814..fd2c18753 100644 --- a/app/email-incoming/support/index.ts +++ b/app/email-incoming/support/index.ts @@ -11,6 +11,7 @@ import { transformRecipients, /* @ts-expect-error: aws-lambda-ses-forwarder does not have type definitions */ } from 'aws-lambda-ses-forwarder' +import 'source-map-support/register' import { createEmailIncomingMessageHandler } from '../handler' import { getEnvOrDie, hostname } from '~/lib/env.server' diff --git a/app/scheduled/ads/index.ts b/app/scheduled/ads/index.ts index 0973fc9be..b837653da 100644 --- a/app/scheduled/ads/index.ts +++ b/app/scheduled/ads/index.ts @@ -7,6 +7,7 @@ */ import { tables } from '@architect/functions' import { ConditionalCheckFailedException } from '@aws-sdk/client-dynamodb' +import 'source-map-support/register' import { getEnvOrDie } from '~/lib/env.server' diff --git a/app/scheduled/circulars/index.ts b/app/scheduled/circulars/index.ts index 9cb923446..6bbbd4ff3 100644 --- a/app/scheduled/circulars/index.ts +++ b/app/scheduled/circulars/index.ts @@ -5,6 +5,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ +import 'source-map-support/register' + import { forAllCirculars } from './actions' import { sitemapAction } from './actions/sitemap' import { statsAction } from './actions/stats' diff --git a/app/table-streams/circulars/index.ts b/app/table-streams/circulars/index.ts index e1f191482..d7fedf312 100644 --- a/app/table-streams/circulars/index.ts +++ b/app/table-streams/circulars/index.ts @@ -8,6 +8,7 @@ import { search as getSearchClient } from '@nasa-gcn/architect-functions-search' import { errors } from '@opensearch-project/opensearch' import type { DynamoDBRecord } from 'aws-lambda' +import 'source-map-support/register' import { unmarshallTrigger } from '../utils' import { send as sendKafka } from '~/lib/kafka.server' diff --git a/app/table-streams/synonyms/index.ts b/app/table-streams/synonyms/index.ts index 98b38f81e..3888b8ede 100644 --- a/app/table-streams/synonyms/index.ts +++ b/app/table-streams/synonyms/index.ts @@ -8,6 +8,7 @@ import { search as getSearchClient } from '@nasa-gcn/architect-functions-search' import { errors } from '@opensearch-project/opensearch' import type { DynamoDBRecord } from 'aws-lambda' +import 'source-map-support/register' import { unmarshallTrigger } from '../utils' import { createTriggerHandler } from '~/lib/lambdaTrigger.server' diff --git a/esbuild.js b/esbuild.js index 6ee2bad67..31b8792db 100644 --- a/esbuild.js +++ b/esbuild.js @@ -24,7 +24,8 @@ const options = { platform: 'node', target: ['node20'], minify: !dev, - sourcemap: dev, + sourcemap: true, + sourcesContent: false, metafile: true, loader: { '.node': 'empty' }, plugins: [ diff --git a/package.json b/package.json index e51b39004..150aa021a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "license": "Apache-2.0", "scripts": { - "build:remix": "remix build && mv build/server/metafile.* build/", + "build:remix": "remix build --sourcemap && mv build/server/metafile.* build/", "build:sass": "sass -Inode_modules/nasawds/src/theme -Inode_modules/@uswds -Inode_modules/@uswds/uswds/packages app:app", "build:esbuild": "node esbuild.js", "build:website": "run-s build:sass build:remix", diff --git a/server.ts b/server.ts index efe4d2859..a9c2e3d4e 100644 --- a/server.ts +++ b/server.ts @@ -2,9 +2,8 @@ import { type RequestHandler, createRequestHandler } from '@remix-run/architect' import * as build from '@remix-run/dev/server-build' import { installGlobals } from '@remix-run/node' import { type APIGatewayProxyStructuredResultV2 } from 'aws-lambda' -import sourceMapSupport from 'source-map-support' +import 'source-map-support/register' -sourceMapSupport.install() installGlobals({ nativeFetch: true }) const remixHandler = createRequestHandler({