From 90898df5008e31885a5bdb9c4354c9bc57dc2156 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 19 May 2024 13:15:54 +0200 Subject: [PATCH] Enable Sentry (#25) --- gatewayd_plugin.yaml | 1 + go.mod | 1 + go.sum | 7 +++++++ main.go | 12 ++++++++++++ 4 files changed, 21 insertions(+) diff --git a/gatewayd_plugin.yaml b/gatewayd_plugin.yaml index b8b2309..1bace84 100644 --- a/gatewayd_plugin.yaml +++ b/gatewayd_plugin.yaml @@ -59,5 +59,6 @@ plugins: # Possible values: trace, debug, info, warn, error # Other values will result in no level being set. - LOG_LEVEL=error + - SENTRY_DSN=https://379ef59ea0c55742957b06c94bc496e1@o4504550475038720.ingest.us.sentry.io/4507282732810240 # Checksum hash to verify the binary before loading checksum: dee4aa014a722e1865d91744a4fd310772152467d9c6ab4ba17fd9dd40d3f724 diff --git a/go.mod b/go.mod index 15c15cf..3db127a 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/carlmjohnson/requests v0.23.5 github.com/corazawaf/libinjection-go v0.1.3 github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.13 + github.com/getsentry/sentry-go v0.27.0 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.1 github.com/jackc/pgx/v5 v5.5.5 diff --git a/go.sum b/go.sum index 798ee9f..0c29b1c 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,10 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.13 h1:zjsMK6m/DwaD8vHmPDKhMyhUuWlRzF4Y8FO3hNmujZg= github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.13/go.mod h1:TN8dII/sN3awR0znv2vY25rhHLN9XyMTNnEIUWjioMk= +github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= @@ -62,6 +66,9 @@ github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/pganalyze/pg_query_go/v5 v5.1.0 h1:MlxQqHZnvA3cbRQYyIrjxEjzo560P6MyTgtlaf3pmXg= github.com/pganalyze/pg_query_go/v5 v5.1.0/go.mod h1:FsglvxidZsVN+Ltw3Ai6nTgPVcK2BPukH3jCDEqc1Ug= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/main.go b/main.go index 462209a..3820587 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "log" "os" sdkConfig "github.com/gatewayd-io/gatewayd-plugin-sdk/config" @@ -10,12 +11,23 @@ import ( p "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin" v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1" "github.com/gatewayd-io/gatewayd-plugin-sql-ids-ips/plugin" + "github.com/getsentry/sentry-go" "github.com/hashicorp/go-hclog" goplugin "github.com/hashicorp/go-plugin" "github.com/spf13/cast" ) func main() { + sentryDSN := sdkConfig.GetEnv("SENTRY_DSN", "") + // Initialize Sentry SDK + err := sentry.Init(sentry.ClientOptions{ + Dsn: sentryDSN, + TracesSampleRate: 1.0, + }) + if err != nil { + log.Fatalf("Failed to initialize Sentry SDK: %s", err.Error()) + } + // Parse command line flags, passed by GatewayD via the plugin config logLevel := flag.String("log-level", "info", "Log level") flag.Parse()