Skip to content

Commit

Permalink
chore: remove sentry and update deps (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Giordano authored Jul 18, 2022
1 parent 1948117 commit e11d8e7
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 413 deletions.
58 changes: 35 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,43 @@ go 1.14

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/aws/aws-lambda-go v1.27.0
github.com/aws/aws-sdk-go v1.42.11
github.com/aws/aws-lambda-go v1.32.1
github.com/aws/aws-sdk-go v1.44.53
github.com/aws/aws-sdk-go-v2 v1.16.7
github.com/aws/aws-sdk-go-v2/config v1.10.0
github.com/aws/aws-sdk-go-v2/service/appsync v1.9.2
github.com/aws/aws-sdk-go-v2/service/cloudsearchdomain v1.9.0
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.10.0
github.com/aws/aws-sdk-go-v2/config v1.15.14
github.com/aws/aws-sdk-go-v2/service/appsync v1.14.8
github.com/aws/aws-sdk-go-v2/service/cloudsearchdomain v1.11.8
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.18.6
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.17.3
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.8.1
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.9.0
github.com/aws/aws-sdk-go-v2/service/firehose v1.14.7
github.com/aws/aws-sdk-go-v2/service/lambda v1.23.1
github.com/aws/aws-sdk-go-v2/service/pinpoint v1.14.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.18.0
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.9.0
github.com/aws/aws-sdk-go-v2/service/ses v1.12.0
github.com/aws/aws-sdk-go-v2/service/sns v1.17.7
github.com/aws/aws-sdk-go-v2/service/sqs v1.18.5
github.com/aws/aws-sdk-go-v2/service/ssm v1.27.1
github.com/aws/aws-sdk-go-v2/service/xray v1.11.0
github.com/aws/aws-xray-sdk-go v1.6.0
github.com/getsentry/sentry-go v0.11.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.9
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.16.5
github.com/aws/aws-sdk-go-v2/service/firehose v1.14.9
github.com/aws/aws-sdk-go-v2/service/lambda v1.23.4
github.com/aws/aws-sdk-go-v2/service/pinpoint v1.16.8
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.1
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.15.13
github.com/aws/aws-sdk-go-v2/service/ses v1.14.9
github.com/aws/aws-sdk-go-v2/service/sns v1.17.9
github.com/aws/aws-sdk-go-v2/service/sqs v1.19.0
github.com/aws/aws-sdk-go-v2/service/ssm v1.27.4
github.com/aws/aws-sdk-go-v2/service/xray v1.13.9
github.com/aws/aws-xray-sdk-go v1.7.0
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/guregu/dynamo v1.11.0
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.19.1
github.com/guregu/dynamo v1.15.1
github.com/klauspost/compress v1.15.8 // indirect
github.com/stretchr/testify v1.7.2
github.com/urfave/cli/v2 v2.2.0 // indirect
github.com/valyala/fasthttp v1.38.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
google.golang.org/genproto v0.0.0-20220712132514-bdd2acd4974d // indirect
google.golang.org/grpc v1.48.0 // indirect

)
291 changes: 150 additions & 141 deletions go.sum

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions pkg/container/logger.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package container

import (
"fmt"
"github.com/getsentry/sentry-go"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"os"
"time"
)

// NewLogger create a new Logger
Expand All @@ -18,18 +15,10 @@ func (c *Container) NewLogger() {
}

logger, _ := zap.NewProduction(zap.Hooks(func(entry zapcore.Entry) error {
if entry.Level == zapcore.WarnLevel {
defer sentry.Flush(2 * time.Second)
sentry.CaptureMessage(fmt.Sprintf("%s, Line No: %d :: %s", entry.Caller.File, entry.Caller.Line, entry.Message))
}
return nil
}))
if os.Getenv("LOG_LEVEL") == "debug" {
logger, _ = zap.NewDevelopment(zap.Hooks(func(entry zapcore.Entry) error {
if entry.Level == zapcore.WarnLevel {
defer sentry.Flush(2 * time.Second)
sentry.CaptureMessage(fmt.Sprintf("%s, Line No: %d :: %s", entry.Caller.File, entry.Caller.Line, entry.Message))
}
return nil
}))
}
Expand Down
43 changes: 1 addition & 42 deletions pkg/framework/handler_api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-xray-sdk-go/instrumentation/awsv2"
"github.com/getsentry/sentry-go"
"github.com/macai-project/framework-golang/pkg/container"
"os"
"strconv"
"time"
)

var businessLogicHandlerApiGateway func(ctx context.Context, c *container.Container, e events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
Expand Down Expand Up @@ -43,47 +39,10 @@ func HandleRequestApiGateway(ctx context.Context, e events.APIGatewayProxyReques
}, err
}

// Sentry
sentryDSN, ok := os.LookupEnv("SENTRY_DSN")
if ok != true {
c.Logger.Warnf("error fetching SENTRY_DSN, sentry won't sample")
sentryDSN = ""
}

samplingRate, err := strconv.ParseFloat(os.Getenv("SENTRY_SAMPLING_RATE"), 64)
if err != nil {
c.Logger.Warnf("error converting SENTRY_SAMPLING_RATE to float64, set to 1.0")
samplingRate = 1.0
}

environment, ok := os.LookupEnv("ENVIRONMENT")
if ok != true {
c.Logger.Warnf("error fetching ENVIRONMENT, setting empty environment")
environment = ""
}

err = sentry.Init(sentry.ClientOptions{
Dsn: sentryDSN,
Environment: environment,
TracesSampleRate: samplingRate,
})

// Xray
awsv2.AWSV2Instrumentor(&c.AwsConfig.APIOptions)

if err != nil {
return events.APIGatewayProxyResponse{
StatusCode: 500,
Body: "Sentry not initialized",
}, err
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(1 * time.Second)

result, err := businessLogicHandlerApiGateway(ctx, c, e)
if err != nil {
sentry.CaptureException(err)
}

return result, err
}
39 changes: 0 additions & 39 deletions pkg/framework/handler_appsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package framework
import (
"context"
"fmt"
"os"
"strconv"
"time"

"github.com/aws/aws-xray-sdk-go/instrumentation/awsv2"
"github.com/getsentry/sentry-go"
"github.com/macai-project/framework-golang/pkg/container"
)

Expand Down Expand Up @@ -37,45 +33,10 @@ func HandleRequestAppsync(ctx context.Context, e map[string]interface{}) (interf
return "AWS Config not initialized", err
}

// Sentry
sentryDSN, ok := os.LookupEnv("SENTRY_DSN")
if ok != true {
c.Logger.Warnf("error fetching SENTRY_DSN, sentry won't sample")
sentryDSN = ""
}

samplingRate, err := strconv.ParseFloat(os.Getenv("SENTRY_SAMPLING_RATE"), 64)
if err != nil {
c.Logger.Warnf("error converting SENTRY_SAMPLING_RATE to float64, set to 1.0")
samplingRate = 1.0
}

environment, ok := os.LookupEnv("ENVIRONMENT")
if ok != true {
c.Logger.Warnf("error fetching ENVIRONMENT, setting empty environment")
environment = ""
}

err = sentry.Init(sentry.ClientOptions{
Dsn: sentryDSN,
Environment: environment,
TracesSampleRate: samplingRate,
})
if err != nil {
return "Sentry not initialized", err
}

// Xray
awsv2.AWSV2Instrumentor(&c.AwsConfig.APIOptions)

// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(1 * time.Second)

result, err := businessLogicHandlerAppsync(ctx, c, e)
if err != nil {
sentry.CaptureException(err)
}

return result, err
}
40 changes: 1 addition & 39 deletions pkg/framework/handler_dynamo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-xray-sdk-go/instrumentation/awsv2"
"github.com/getsentry/sentry-go"
"github.com/macai-project/framework-golang/pkg/container"
"os"
"strconv"
"time"
)

var businessLogicHandlerDynamoDBEvent func(ctx context.Context, c *container.Container, e events.DynamoDBEvent) (string, error)
Expand All @@ -36,44 +32,10 @@ func HandleRequestDynamo(ctx context.Context, e events.DynamoDBEvent) (string, e
return "error initializing AWS Config", err
}

// Sentry
sentryDSN, ok := os.LookupEnv("SENTRY_DSN")
if ok != true {
c.Logger.Warnf("error fetching SENTRY_DSN, sentry won't sample")
sentryDSN = ""
}

samplingRate, err := strconv.ParseFloat(os.Getenv("SENTRY_SAMPLING_RATE"), 64)
if err != nil {
c.Logger.Warnf("error converting SENTRY_SAMPLING_RATE to float64, set to 1.0")
samplingRate = 1.0
}

environment, ok := os.LookupEnv("ENVIRONMENT")
if ok != true {
c.Logger.Warnf("error fetching ENVIRONMENT, setting empty environment")
environment = ""
}

err = sentry.Init(sentry.ClientOptions{
Dsn: sentryDSN,
Environment: environment,
TracesSampleRate: samplingRate,
})

// Xray
awsv2.AWSV2Instrumentor(&c.AwsConfig.APIOptions)

if err != nil {
return "error in sentry.Init", err
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(1 * time.Second)

result, err := businessLogicHandlerDynamoDBEvent(ctx, c, e)
if err != nil {
sentry.CaptureException(err)
}

return result, err
}
42 changes: 2 additions & 40 deletions pkg/framework/handler_eventbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-xray-sdk-go/instrumentation/awsv2"
"github.com/getsentry/sentry-go"
"github.com/macai-project/framework-golang/pkg/container"
"os"
"strconv"
"time"
)

var c *container.Container
Expand Down Expand Up @@ -43,44 +39,10 @@ func HandleRequest(ctx context.Context, e events.CloudWatchEvent) (string, error
return "error initializing AWS Config", err
}

// Sentry
sentryDSN, ok := os.LookupEnv("SENTRY_DSN")
if ok != true {
c.Logger.Warnf("error fetching SENTRY_DSN, sentry won't sample")
sentryDSN = ""
}

samplingRate, err := strconv.ParseFloat(os.Getenv("SENTRY_SAMPLING_RATE"), 64)
if err != nil {
c.Logger.Warnf("error converting SENTRY_SAMPLING_RATE to float64, set to 1.0")
samplingRate = 1.0
}

environment, ok := os.LookupEnv("ENVIRONMENT")
if ok != true {
c.Logger.Warnf("error fetching ENVIRONMENT, setting empty environment")
environment = ""
}

err = sentry.Init(sentry.ClientOptions{
Dsn: sentryDSN,
Environment: environment,
TracesSampleRate: samplingRate,
})

// Xray
awsv2.AWSV2Instrumentor(&c.AwsConfig.APIOptions)

if err != nil {
return "error in sentry.Init", err
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(1 * time.Second)

result, err := businessLogicHandler(ctx, c, e)
if err != nil {
sentry.CaptureException(err)
}

return result, err
}
}
40 changes: 1 addition & 39 deletions pkg/framework/handler_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import (
"context"
"fmt"
"github.com/aws/aws-xray-sdk-go/instrumentation/awsv2"
"github.com/getsentry/sentry-go"
"github.com/macai-project/framework-golang/pkg/container"
"os"
"strconv"
"time"
)

var businessGenericLogicHandler func(ctx context.Context, c *container.Container, e interface{}) (string, error)
Expand All @@ -35,44 +31,10 @@ func HandleGenericRequest(ctx context.Context, e interface{}) (string, error) {
return "error initializing AWS Config", err
}

// Sentry
sentryDSN, ok := os.LookupEnv("SENTRY_DSN")
if ok != true {
c.Logger.Warnf("error fetching SENTRY_DSN, sentry won't sample")
sentryDSN = ""
}

samplingRate, err := strconv.ParseFloat(os.Getenv("SENTRY_SAMPLING_RATE"), 64)
if err != nil {
c.Logger.Warnf("error converting SENTRY_SAMPLING_RATE to float64, set to 1.0")
samplingRate = 1.0
}

environment, ok := os.LookupEnv("ENVIRONMENT")
if ok != true {
c.Logger.Warnf("error fetching ENVIRONMENT, setting empty environment")
environment = ""
}

err = sentry.Init(sentry.ClientOptions{
Dsn: sentryDSN,
Environment: environment,
TracesSampleRate: samplingRate,
})

// Xray
awsv2.AWSV2Instrumentor(&c.AwsConfig.APIOptions)

if err != nil {
return "error in sentry.Init", err
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(1 * time.Second)

result, err := businessGenericLogicHandler(ctx, c, e)
if err != nil {
sentry.CaptureException(err)
}

return result, err
}
Loading

0 comments on commit e11d8e7

Please sign in to comment.