https://serverless-stack.com/ logo
#help
Title
# help
m

Meris Tarhanis

05/10/2022, 12:58 PM
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

thdxr

05/10/2022, 1:25 PM
based on what this is I think you want to move the
wrapHandler
INSIDE the function
return wrapHandler(async function() { ... })
m

Meris Tarhanis

05/10/2022, 1:36 PM
@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

thdxr

05/10/2022, 2:07 PM
how are you using this handler function?
m

Meris Tarhanis

05/10/2022, 2:12 PM
@thdxr
t

thdxr

05/10/2022, 2:43 PM
it works if you remove the sentry wrapper?
m

Meris Tarhanis

05/10/2022, 2:45 PM
yes
t

thdxr

05/10/2022, 2:45 PM
I'm not really sure, nothing is sticking out to me
I use sentry myself and I don't have an issue
f

Frank

05/11/2022, 4:51 AM
@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

Meris Tarhanis

05/12/2022, 1:39 PM
@Frank I have just now seen your question. The problem happens in the
sst deploy
f

Frank

05/12/2022, 3:25 PM
Can you share the full lambda log from CloudWatch?
m

Meris Tarhanis

05/12/2022, 3:44 PM
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
2 Views