[英]Sentry SDK Java is not working on aws lambda
我正在嘗試在基於 Java 的 aws lambda 中使用哨兵。 我試圖在一個簡單的 lambda 中使用 sentry v3.1.1
,它捕獲如下異常。 問題是
works fine when run locally using main method
它works fine when run locally using main method
,並且事件出現在哨兵問題上doesn't work when invoked in as aws lambda
它doesn't work when invoked in as aws lambda
並且事件永遠不會出現在哨兵 ui 上。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);
}
}
<?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>
dsn=...removed intentionally...
environment=development
release=0.0.1-SNAPSHOT
stacktrace.app.packages=playground.demo
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 ...
我還嘗試使用 vpc 配置和互聯網訪問創建 aws lambda,但沒有成功任何人都可以指導我為什么它不工作,我該如何使它工作?
PS在這之前,我嘗試使用sentry-log4j2和sentry-logback ,最終達到了簡單的sentry-java 。 它們都在本地工作,但在 aws lambda 上失敗
[更新:2020 年 11 月 2 日]
正如@Manoel 建議設置調試標志,這里是更新的代碼和日志。
...
Sentry.init(options -> {
options.setDebug(true);
options.setDsn("...");
options.setEnvironment("development");
options.setRelease("0.0.1-SNAPSHOT");
});
...
/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
你能啟用debug
模式並復制粘貼日志嗎?
Sentry.init(options -> {
options.setDebug(true);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.