I am trying to use sentry in java based aws lambda. I am trying to used sentry v3.1.1 in a simple lambda which captures exception as below. The problem is
- it
works fine when run locally using main method, and event appears on sentry issues ui - but it
doesn't work when invoked in as aws lambdaand event never appears on sentry ui.
SentryLambda.java
package playground.demo;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import io.sentry.Sentry;
public class SentryLambda implements RequestHandler<String, String> {
@Override
public String handleRequest(String input, Context context) {
Sentry.init();
Sentry.captureException(new Exception("Test Sentry"));
return "Returned " + input;
}
public static void main(String[] args) {
SentryLambda sentryLambda = new SentryLambda();
sentryLambda.handleRequest("Requested String", null);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>playground.demo</groupId>
<artifactId>aws-lambda-sentry</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<finalName>${project.name}-${project.version}-jar-with-dependencies</finalName>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.github.edwgiz</groupId>
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
sentry.properties
dsn=...removed intentionally...
environment=development
release=0.0.1-SNAPSHOT
stacktrace.app.packages=playground.demo
samp-template.tml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sentry Lambda
Resources:
SentryLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: sentryLambda
Handler: playground.demo.SentryLambda
Runtime: java8
CodeUri: target/aws-lambda-sentry-0.0.1-SNAPSHOT-jar-with-dependencies.jar
MemorySize: 512
Timeout: 15
AutoPublishAlias: DEFAULT
Role: ... a role with AWSLambdaFullAccess policy ...
I also tried creating aws lambda with vpc config and internet access but did not succeed Can anyone please guide me why it's not working and how can I make it work?
P.S. Before all this, I tried working with sentry-log4j2 and sentry-logback, and eventually reached to simple sentry-java. They all work locally but fail on aws lambda
[Update: Nov 02, 2020]
As @Manoel suggested to set debug flag, here's the updated code and logs.
SentryLambda.java
...
Sentry.init(options -> {
options.setDebug(true);
options.setDsn("...");
options.setEnvironment("development");
options.setRelease("0.0.1-SNAPSHOT");
});
...
Logs
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a START RequestId: b3f6c0f5-3a89-4f62-8994-7d4b198351e5 Version: $LATEST
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a INFO: Initializing SDK with DSN: '...'
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a INFO: No outbox dir path is defined in options.
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a INFO: GlobalHubMode: 'false'
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a DEBUG: UncaughtExceptionHandlerIntegration enabled: true
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a DEBUG: UncaughtExceptionHandlerIntegration installed.
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a DEBUG: Capturing event: ff1def349ab34a5eb151d52e7dd72425
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a INFO: Session is null on scope.withSession
/aws/lambda/sentryLambda 2020/11/02/[$LATEST]da849aebc90744409bbc11f98ac49c2a END RequestId: b3f6c0f5-3a89-4f62-8994-7d4b198351e5