Home avatar

Deokgon Kim

Debugging `serverless-offline` with vscode debugger

When using vscode as a IDE and the framework is serverless-offline.
If you try to debug typescript code with breakpoint, it may not work properly.

Set up serverless-esbuild configuration in serverless.yml

custom:
  esbuild:
    bundle: true
    platform: node
    target: node18
    sourcemap: true          # THIS WILL MAKE THE BREAKPOINTS ON TS FILE WORK
    sourcesContent: true
    keepNames: true
  • IDE: vscode
  • Framework: serverless
  • Local runtime: serverless-offline
    • Run local debug server with
      sls offline
  • Development language: typescript
  • Build with: serverless-esbuild

In normal case, any node process can be debugged with vscode with JavaScript Debug Terminal. but, when running sls offline, it seems the debugger session is attached to the process but the breakpoints are not working. After several googling, there were try launch.json configuration, use SLS_DEBUG and etc.

2024 Nov Cloud Project

  • What I first wanted : I want to use Telegram and WhatsApp as order notification channel
  • Originally, I used to use plain Lambda function. This time I will try express(https://expressjs.com/) + serverless lambda

    • serverless yaml : I uses httpApi integration
      functions:
        api:
          handler: src/index.handler
          events:
            - httpApi: '*'
    • index.ts snippet
      const express = require("express");
      const serverless = require("serverless-http");
      
      const app = express();
      
      app.use(express.json());
      app.use(express.urlencoded({ extended: true }));
      
      app.use('/telegram', require('./telegram/route')); // Use the routes
      app.use('/twilio', require('./twilio/route')); // Use the routes
      
      // module.exports.handler = serverless(app);
      module.exports = {
        handler: serverless(app),
        app,
      }
  • Set up the React frontend

Tested Dynatrace

Behind story

I have been using APM since 2006. the first was Jennifer (for java). and Scouter (similar to jennifer x-view)

And the year 2020, I meet elastic apm (half setup). I finished the setup from Python django monitoring, to Vue RUM(with sourcemap).

In the year 2023, I tried Sentry for the first time. It seems new and is specialized for error tracking. I have set up for NestJS(backend), React(web frontend) and ReactNative. It was not that bad with error tracking.