We have a lambda function in Java, no framework we are using.
We are unable to integrate Sentry in lambda.
Below is my SentryConfig.java file
package com.my.mypackage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.my.exception.MyException;
import com.my.model.PropertyReader;
import io.sentry.Sentry;
import io.sentry.SentryClient;
public class SentryConfig {
private static final Logger LOG = LoggerFactory.getLogger(SentryConfig.class);
private final String propertyFile = "config.properties";
public SentryClient initializeSentry(){
try {
Properties prop = new PropertyReader().readPropertyFile(propertyFile);
String environment = prop.getProperty("environment");
if (!Utils.isEmpty(environment)) {
String sentryDns = prop.getProperty("non_prod_sentry_dns");
if(environment.equals("PROD")) {
sentryDns = prop.getProperty("prod_sentry_dns");
}
LOG.info("Initializing sentry for {} environment.", environment);
return initializeSentry(environment, sentryDns);
} else {
// No need to setup sentry for DEV environment
LOG.info("Please setup environment property");
return null;
}
} catch (IOException e) {
throw new MyException(MyConstant.UANBLE_TO_LOAD_CONFIG);
}
}
private SentryClient initializeSentry(String env, String dsn) {
Sentry.init(dsn);
SentryClient sc = Sentry.getStoredClient();
sc.setEnvironment(env);
return sc;
}
}
I am invoking Sentry as below
(new SentryConfig()).initializeSentry();
Sentry.getContext().addExtra(“payload”, request.toString());
Sentry.capture(ex);
It working fine when I run it locally but not with lambda.