Skip to content

Commit 86fcb4b

Browse files
committed
use sentry WithScope and CaptureMessage instead of logger
1 parent 4800b74 commit 86fcb4b

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

cdk/cdk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func NewCdkStack(scope constructs.Construct, id string, props *CdkStackProps) aw
4848
"TOTP_TABLE": jsii.String(totpTable),
4949
"WEBAUTHN_TABLE": jsii.String(webauthnTable),
5050
"AWS_ENDPOINT": jsii.String(""),
51+
"ENVIRONMENT": jsii.String(env),
5152
"SENTRY_DSN": jsii.String(os.Getenv("SENTRY_DSN")),
5253
},
5354
FunctionName: &functionName,

cdk/env.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"Parameters": {
33
"AWS_ENDPOINT": "http://172.17.0.1:8000",
4+
"SENTRY_DSN": "",
5+
"ENVIRONMENT": "local",
46
"API_KEY_TABLE": "ApiKey",
57
"TOTP_TABLE": "Totp",
68
"WEBAUTHN_TABLE": "WebAuthn"

config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ type EnvConfig struct {
2323

2424
AWSConfig aws.Config `json:"-"`
2525

26-
SentryDSN string `split_words:"true"`
26+
Environment string
27+
SentryDSN string `split_words:"true"`
2728
}
2829

2930
func (e *EnvConfig) InitAWS() {

lambda/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ func handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.API
6161
}
6262

6363
if w.Status == http.StatusInternalServerError && envConfig.SentryDSN != "" {
64-
logger := sentry.NewLogger(ctx)
65-
logger.Error().Emit(string(w.Body))
66-
defer sentry.Flush(2 * time.Second)
64+
sentry.WithScope(func(scope *sentry.Scope) {
65+
scope.SetLevel(sentry.LevelError)
66+
sentry.CaptureMessage(string(w.Body))
67+
})
68+
sentry.Flush(2 * time.Second)
6769
}
6870

6971
return events.APIGatewayProxyResponse{
@@ -99,8 +101,9 @@ func sentryInit() {
99101
}
100102

101103
if err := sentry.Init(sentry.ClientOptions{
102-
Dsn: envConfig.SentryDSN,
103-
EnableLogs: true,
104+
Dsn: envConfig.SentryDSN,
105+
EnableLogs: true,
106+
Environment: envConfig.Environment,
104107
}); err != nil {
105108
log.Printf("Sentry initialization failed: %v\n", err)
106109
}

0 commit comments

Comments
 (0)