Hello everyone. I have been trying to implement Se...
# help
m
Hello everyone. I have been trying to implement Sentry on my project following this guide: https://serverless-stack.com/examples/how-to-use-sentry-to-monitor-your-serverless-app.html. I am trying to implement the wrapper onto my handler.js main function like this:
Copy code
import * as debug from "./debug";
import Sentry from "@sentry/serverless";

const handler = Sentry.AWSLambda.wrapHandler((lambda) => {
  return async function (event, context) {
    let body;
    let statusCode;

    // Start debugger
    debug.init(event);

    try {
      // Run the Lambda
      body = await lambda(event, context);
      statusCode = body.statusCode || 200;
    } catch (e) {
      // Print debug messages
      debug.flush(e);

      body = { error: e.message };
      statusCode = 500;
    }

    // Return HTTP response
    return {
      statusCode,
      body: JSON.stringify(body),
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': '*',
        // "Access-Control-Allow-Credentials": true,
        // "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE, HEAD, OPTIONS",
      },
    };
  };
})

export default handler
This function is used by other lambda's to handle API calls, and my problem is that currently It's just sending the REQUEST's but it doesn't return any RESPONSE. Maybe it's something minor that I am missing. If you need any more info I would happily supply.
t
based on what this is I think you want to move the
wrapHandler
INSIDE the function
return wrapHandler(async function() { ... })
m
@thdxr will try it out and come back with the result
@thdxr it did not fix my problem 😕. I changed it per your instructions:
Copy code
import * as debug from "./debug";
import Sentry from "@sentry/serverless";

  export default function handler(lambda) {
  return Sentry.AWSLambda.wrapHandler(async function (event, context) {
    let body;
    let statusCode;

    // Start debugger
    debug.init(event);

    try {
      // Run the Lambda
      body = await lambda(event, context);
      statusCode = body.statusCode || 200;
    } catch (e) {
      // Print debug messages
      debug.flush(e);

      body = { error: e.message };
      statusCode = 500;
    }

    // Return HTTP response
    return {
      statusCode,
      body: JSON.stringify(body),
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': '*',
        // "Access-Control-Allow-Credentials": true,
        // "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE, HEAD, OPTIONS",
      },
    };
  }
  )
}
t
how are you using this handler function?
m
@thdxr
t
it works if you remove the sentry wrapper?
m
yes
t
I'm not really sure, nothing is sticking out to me
I use sentry myself and I don't have an issue
f
@Meris Tarhanis
It’s just sending the REQUEST’s but it doesn’t return any RESPONSE
Does this happen on
sst start
or
sst deploy
?
m
@Frank I have just now seen your question. The problem happens in the
sst deploy
f
Can you share the full lambda log from CloudWatch?
m
Copy code
{
  "requestTime": "10/May/2022:19:34:56 +0000",
  "requestId": "R7KvGhE-liAEMRw=",
  "httpMethod": "GET",
  "path": "/appointments/patients/59EB6565-DCD2-4676-831C-C0B5F67F6FD2",
  "routeKey": "GET /appointments/patients/{person_guid}",
  "status": 500,
  "responseLatency": 465,
  "integrationRequestId": "4600c62d-5ac3-437c-b175-3a17795c5f08",
  "integrationStatus": "500",
  "integrationLatency": "457",
  "integrationServiceStatus": "200",
  "ip": "87.116.165.251",
  "userAgent": "PostmanRuntime/7.28.4",
  "cognitoIdentityId": "-"
}
the usual response, do you need more insight?
@Frank