diff --git a/app/sephirah/cmd/sephirah/main.go b/app/sephirah/cmd/sephirah/main.go index cb8d685..2d20e10 100644 --- a/app/sephirah/cmd/sephirah/main.go +++ b/app/sephirah/cmd/sephirah/main.go @@ -7,6 +7,7 @@ import ( "github.com/tuihub/librarian/internal/lib/libapp" "github.com/tuihub/librarian/internal/lib/libcron" "github.com/tuihub/librarian/internal/lib/libmq" + "github.com/tuihub/librarian/internal/lib/libsentry" "github.com/go-kratos/kratos/v2" "github.com/go-kratos/kratos/v2/registry" @@ -50,6 +51,11 @@ func main() { var bc conf.Sephirah appSettings.LoadConfig(&bc) + err = libsentry.InitSentry(bc.GetSentry()) + if err != nil { + panic(err) + } + app, cleanup, err := wireApp( bc.GetServer(), bc.GetData(), diff --git a/cmd/librarian/main.go b/cmd/librarian/main.go index be00473..0326155 100644 --- a/cmd/librarian/main.go +++ b/cmd/librarian/main.go @@ -9,6 +9,7 @@ import ( "github.com/tuihub/librarian/internal/lib/libapp" "github.com/tuihub/librarian/internal/lib/libcron" "github.com/tuihub/librarian/internal/lib/libmq" + "github.com/tuihub/librarian/internal/lib/libsentry" miner "github.com/tuihub/protos/pkg/librarian/miner/v1" searcher "github.com/tuihub/protos/pkg/librarian/searcher/v1" @@ -75,6 +76,11 @@ func main() { bc.EnableServiceDiscovery = new(conf.Librarian_EnableServiceDiscovery) } + err = libsentry.InitSentry(bc.GetSentry()) + if err != nil { + panic(err) + } + app, cleanup, err := wireApp( bc.GetEnableServiceDiscovery(), bc.GetServer(), diff --git a/go.mod b/go.mod index 36864fe..837de21 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( entgo.io/ent v0.12.5 - github.com/BurntSushi/toml v0.3.1 + github.com/BurntSushi/toml v1.2.1 github.com/PuerkitoBio/goquery v1.8.1 github.com/ThreeDotsLabs/watermill v1.3.4 github.com/ThreeDotsLabs/watermill-sql/v2 v2.0.0 @@ -14,6 +14,8 @@ require ( github.com/cayleygraph/quad v1.2.5 github.com/dgraph-io/ristretto v0.1.1 github.com/fullstorydev/grpchan v1.1.1 + github.com/getsentry/sentry-go v0.27.0 + github.com/getsentry/sentry-go/otel v0.27.0 github.com/go-co-op/gocron v1.37.0 github.com/go-kratos/kratos/contrib/log/zap/v2 v2.0.0-20240119085030-a556a2b53120 github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-20240119085030-a556a2b53120 @@ -34,6 +36,8 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tuihub/protos v0.4.2 github.com/zhihu/norm v0.1.11 + go.opentelemetry.io/otel v1.16.0 + go.opentelemetry.io/otel/sdk v1.16.0 go.uber.org/ratelimit v0.3.0 go.uber.org/zap v1.26.0 golang.org/x/crypto v0.18.0 @@ -48,7 +52,7 @@ require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 // indirect github.com/RoaringBitmap/roaring v1.2.3 // indirect github.com/agext/levenshtein v1.2.3 // indirect - github.com/andybalholm/brotli v1.0.4 // indirect + github.com/andybalholm/brotli v1.0.5 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect github.com/antlr4-go/antlr/v4 v4.13.0 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect @@ -94,7 +98,7 @@ require ( github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect github.com/golang/glog v1.1.2 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/golang/snappy v0.0.1 // indirect + github.com/golang/snappy v0.0.4 // indirect github.com/google/cel-go v0.18.2 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -151,12 +155,11 @@ require ( github.com/tklauser/go-sysconf v0.3.11 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d // indirect + github.com/valyala/fasthttp v1.40.0 // indirect github.com/vesoft-inc/nebula-go/v2 v2.6.0 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect github.com/zclconf/go-cty v1.12.1 // indirect go.etcd.io/bbolt v1.3.7 // indirect - go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect go.uber.org/atomic v1.9.0 // indirect diff --git a/go.sum b/go.sum index 9f97b75..22f7fc1 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,9 @@ entgo.io/ent v0.12.5 h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4= entgo.io/ent v0.12.5/go.mod h1:Y3JVAjtlIk8xVZYSn3t3mf8xlZIn5SAOXZQxD6kKI+Q= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= @@ -75,8 +76,9 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -278,13 +280,20 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS github.com/fsouza/go-dockerclient v1.2.2/go.mod h1:KpcjM623fQYE9MZiTGzKhjfxXAV9wbyX2C1cyRHfhl0= github.com/fullstorydev/grpchan v1.1.1 h1:heQqIJlAv5Cnks9a70GRL2EJke6QQoUB25VGR6TZQas= github.com/fullstorydev/grpchan v1.1.1/go.mod h1:f4HpiV8V6htfY/K44GWV1ESQzHBTq7DinhzqQ95lpgc= +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/getsentry/sentry-go/otel v0.27.0 h1:p06qcOWuwA5eZkIoJuWjQVBQGFAPrHibShoFKakDV2g= +github.com/getsentry/sentry-go/otel v0.27.0/go.mod h1:ulQ2Luf7K0eIiESCpcPaUZeQx6T0BS08hSPJx+xIZNg= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0= github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY= +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/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -319,12 +328,15 @@ github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBY github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/form/v4 v4.2.0 h1:N1wh+Goz61e6w66vo8vJkQt+uwZSoLz50kZPJWR8eic= github.com/go-playground/form/v4 v4.2.0/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= +github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= +github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-sourcemap/sourcemap v2.1.2+incompatible h1:0b/xya7BKGhXuqFESKM4oIiRo9WOt2ebz7KxfreD6ug= github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -352,6 +364,8 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= +github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= +github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -401,8 +415,9 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= @@ -628,8 +643,9 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= @@ -674,8 +690,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.20 h1:BAZ50Ns0OFBNxdAqFhbZqdPcht1Xlb16pDCqkq1spr0= github.com/mattn/go-sqlite3 v1.14.20/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= @@ -733,8 +747,6 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -761,12 +773,17 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= +github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= +github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/piprate/json-gold v0.3.0 h1:a1vHx7Q1jOO1pjCtKwTI/WCzwaQwRt9VM7apK2uy200= github.com/piprate/json-gold v0.3.0/go.mod h1:OK1z7UgtBZk06n2cDE2OSq1kffmjFFp5/2yhLLCz9UM= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -931,8 +948,6 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tuihub/protos v0.4.1 h1:nGW2u+TJ4lSwh6+s4pMhKcKGMne19Kf+wo0bDONg2qU= -github.com/tuihub/protos v0.4.1/go.mod h1:FvaMeevw4RUzHy5kNgbCHWk3fH25ApXEaNmPvDhXozc= github.com/tuihub/protos v0.4.2 h1:MkwhkXrPWR+YTRU9Vn34RGC4LTtOSRN5oB3FgEDpEMA= github.com/tuihub/protos v0.4.2/go.mod h1:FvaMeevw4RUzHy5kNgbCHWk3fH25ApXEaNmPvDhXozc= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= @@ -941,14 +956,16 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d h1:xS9QTPgKl9ewGsAOPc+xW7DeStJDqYPfisDmeSCcbco= github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= +github.com/valyala/fasthttp v1.40.0 h1:CRq/00MfruPGFLTQKY8b+8SfdK60TxNztjRMnH0t1Yc= +github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/vesoft-inc/nebula-go/v2 v2.0.0-ga/go.mod h1:qvrlydV8O1Jbff7b7cXSLOvZNs9BcE8pFZa/1nvB3fo= github.com/vesoft-inc/nebula-go/v2 v2.6.0 h1:yS5JH8eNjXtHSZXDRcNihdYaW9FyjOsrpG5iIMkIFBs= diff --git a/internal/conf/base.pb.go b/internal/conf/base.pb.go index 05fd1c7..b9c6894 100644 --- a/internal/conf/base.pb.go +++ b/internal/conf/base.pb.go @@ -399,6 +399,53 @@ func (x *Consul) GetToken() string { return "" } +type Sentry struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Dsn string `protobuf:"bytes,1,opt,name=dsn,proto3" json:"dsn,omitempty"` +} + +func (x *Sentry) Reset() { + *x = Sentry{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_base_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Sentry) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Sentry) ProtoMessage() {} + +func (x *Sentry) ProtoReflect() protoreflect.Message { + mi := &file_conf_base_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Sentry.ProtoReflect.Descriptor instead. +func (*Sentry) Descriptor() ([]byte, []int) { + return file_conf_base_proto_rawDescGZIP(), []int{6} +} + +func (x *Sentry) GetDsn() string { + if x != nil { + return x.Dsn + } + return "" +} + var File_conf_base_proto protoreflect.FileDescriptor var file_conf_base_proto_rawDesc = []byte{ @@ -440,9 +487,11 @@ var file_conf_base_proto_rawDesc = []byte{ 0x22, 0x32, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, - 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x1e, 0x5a, 0x1c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, - 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, - 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x1a, 0x0a, 0x06, 0x53, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x64, 0x73, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x64, 0x73, 0x6e, + 0x42, 0x1e, 0x5a, 0x1c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -457,7 +506,7 @@ func file_conf_base_proto_rawDescGZIP() []byte { return file_conf_base_proto_rawDescData } -var file_conf_base_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_conf_base_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_conf_base_proto_goTypes = []interface{}{ (*GRPC)(nil), // 0: kratos.api.GRPC (*Database)(nil), // 1: kratos.api.Database @@ -465,10 +514,11 @@ var file_conf_base_proto_goTypes = []interface{}{ (*Auth)(nil), // 3: kratos.api.Auth (*Cache)(nil), // 4: kratos.api.Cache (*Consul)(nil), // 5: kratos.api.Consul - (*durationpb.Duration)(nil), // 6: google.protobuf.Duration + (*Sentry)(nil), // 6: kratos.api.Sentry + (*durationpb.Duration)(nil), // 7: google.protobuf.Duration } var file_conf_base_proto_depIdxs = []int32{ - 6, // 0: kratos.api.GRPC.timeout:type_name -> google.protobuf.Duration + 7, // 0: kratos.api.GRPC.timeout:type_name -> google.protobuf.Duration 1, // 1: kratos.api.MQ.database:type_name -> kratos.api.Database 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type @@ -555,6 +605,18 @@ func file_conf_base_proto_init() { return nil } } + file_conf_base_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Sentry); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -562,7 +624,7 @@ func file_conf_base_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_conf_base_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 0, }, diff --git a/internal/conf/base.proto b/internal/conf/base.proto index b5b8020..1629803 100644 --- a/internal/conf/base.proto +++ b/internal/conf/base.proto @@ -39,4 +39,8 @@ message Cache { message Consul { string addr = 1; string token = 2; +} + +message Sentry { + string dsn = 1; } \ No newline at end of file diff --git a/internal/conf/librarian.pb.go b/internal/conf/librarian.pb.go index eee07dd..1b2daaf 100644 --- a/internal/conf/librarian.pb.go +++ b/internal/conf/librarian.pb.go @@ -33,6 +33,7 @@ type Librarian struct { Cache *Cache `protobuf:"bytes,5,opt,name=cache,proto3" json:"cache,omitempty"` Porter *Porter `protobuf:"bytes,6,opt,name=porter,proto3" json:"porter,omitempty"` Consul *Consul `protobuf:"bytes,7,opt,name=consul,proto3" json:"consul,omitempty"` + Sentry *Sentry `protobuf:"bytes,8,opt,name=sentry,proto3" json:"sentry,omitempty"` Mapper *Mapper `protobuf:"bytes,11,opt,name=mapper,proto3" json:"mapper,omitempty"` Searcher *Searcher `protobuf:"bytes,12,opt,name=searcher,proto3" json:"searcher,omitempty"` Miner *Miner `protobuf:"bytes,13,opt,name=miner,proto3" json:"miner,omitempty"` @@ -126,6 +127,13 @@ func (x *Librarian) GetConsul() *Consul { return nil } +func (x *Librarian) GetSentry() *Sentry { + if x != nil { + return x.Sentry + } + return nil +} + func (x *Librarian) GetMapper() *Mapper { if x != nil { return x.Mapper @@ -229,7 +237,7 @@ var file_conf_librarian_proto_rawDesc = []byte{ 0x61, 0x70, 0x70, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x13, 0x63, 0x6f, 0x6e, 0x66, 0x2f, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x10, 0x63, 0x6f, 0x6e, 0x66, 0x2f, 0x6d, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0x9f, 0x05, 0x0a, 0x09, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, 0x6e, + 0x74, 0x6f, 0x22, 0xcb, 0x05, 0x0a, 0x09, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x12, 0x66, 0x0a, 0x18, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, @@ -255,25 +263,28 @@ var file_conf_librarian_proto_rawDesc = []byte{ 0x6f, 0x72, 0x74, 0x65, 0x72, 0x12, 0x2a, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x73, 0x75, - 0x6c, 0x12, 0x2a, 0x0a, 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, - 0x61, 0x70, 0x70, 0x65, 0x72, 0x52, 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x12, 0x30, 0x0a, - 0x08, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x65, 0x72, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x14, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x61, - 0x72, 0x63, 0x68, 0x65, 0x72, 0x52, 0x08, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x65, 0x72, 0x12, - 0x27, 0x0a, 0x05, 0x6d, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, - 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x69, 0x6e, 0x65, - 0x72, 0x52, 0x05, 0x6d, 0x69, 0x6e, 0x65, 0x72, 0x1a, 0x7a, 0x0a, 0x16, 0x45, 0x6e, 0x61, 0x62, - 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, - 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, - 0x61, 0x72, 0x63, 0x68, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x73, 0x65, - 0x61, 0x72, 0x63, 0x68, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x12, 0x14, - 0x0a, 0x05, 0x6d, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6d, - 0x69, 0x6e, 0x65, 0x72, 0x42, 0x1e, 0x5a, 0x1c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, - 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, - 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, + 0x65, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x2a, 0x0a, + 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, + 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x70, 0x70, 0x65, + 0x72, 0x52, 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x08, 0x73, 0x65, 0x61, + 0x72, 0x63, 0x68, 0x65, 0x72, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6b, 0x72, + 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x65, + 0x72, 0x52, 0x08, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x65, 0x72, 0x12, 0x27, 0x0a, 0x05, 0x6d, + 0x69, 0x6e, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6b, 0x72, 0x61, + 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x6d, + 0x69, 0x6e, 0x65, 0x72, 0x1a, 0x7a, 0x0a, 0x16, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x12, 0x16, + 0x0a, 0x06, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, + 0x6d, 0x61, 0x70, 0x70, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, + 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, + 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x06, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x69, + 0x6e, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6d, 0x69, 0x6e, 0x65, 0x72, + 0x42, 0x1e, 0x5a, 0x1c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -299,9 +310,10 @@ var file_conf_librarian_proto_goTypes = []interface{}{ (*Cache)(nil), // 6: kratos.api.Cache (*Porter)(nil), // 7: kratos.api.Porter (*Consul)(nil), // 8: kratos.api.Consul - (*Mapper)(nil), // 9: kratos.api.Mapper - (*Searcher)(nil), // 10: kratos.api.Searcher - (*Miner)(nil), // 11: kratos.api.Miner + (*Sentry)(nil), // 9: kratos.api.Sentry + (*Mapper)(nil), // 10: kratos.api.Mapper + (*Searcher)(nil), // 11: kratos.api.Searcher + (*Miner)(nil), // 12: kratos.api.Miner } var file_conf_librarian_proto_depIdxs = []int32{ 1, // 0: kratos.api.Librarian.enable_service_discovery:type_name -> kratos.api.Librarian.EnableServiceDiscovery @@ -312,14 +324,15 @@ var file_conf_librarian_proto_depIdxs = []int32{ 6, // 5: kratos.api.Librarian.cache:type_name -> kratos.api.Cache 7, // 6: kratos.api.Librarian.porter:type_name -> kratos.api.Porter 8, // 7: kratos.api.Librarian.consul:type_name -> kratos.api.Consul - 9, // 8: kratos.api.Librarian.mapper:type_name -> kratos.api.Mapper - 10, // 9: kratos.api.Librarian.searcher:type_name -> kratos.api.Searcher - 11, // 10: kratos.api.Librarian.miner:type_name -> kratos.api.Miner - 11, // [11:11] is the sub-list for method output_type - 11, // [11:11] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 9, // 8: kratos.api.Librarian.sentry:type_name -> kratos.api.Sentry + 10, // 9: kratos.api.Librarian.mapper:type_name -> kratos.api.Mapper + 11, // 10: kratos.api.Librarian.searcher:type_name -> kratos.api.Searcher + 12, // 11: kratos.api.Librarian.miner:type_name -> kratos.api.Miner + 12, // [12:12] is the sub-list for method output_type + 12, // [12:12] is the sub-list for method input_type + 12, // [12:12] is the sub-list for extension type_name + 12, // [12:12] is the sub-list for extension extendee + 0, // [0:12] is the sub-list for field type_name } func init() { file_conf_librarian_proto_init() } diff --git a/internal/conf/librarian.proto b/internal/conf/librarian.proto index 1e3bb79..7280005 100644 --- a/internal/conf/librarian.proto +++ b/internal/conf/librarian.proto @@ -25,6 +25,7 @@ message Librarian { Cache cache = 5; Porter porter = 6; Consul consul = 7; + Sentry sentry = 8; Mapper mapper = 11; Searcher searcher = 12; diff --git a/internal/conf/sephirah.pb.go b/internal/conf/sephirah.pb.go index 7dbe58e..671e484 100644 --- a/internal/conf/sephirah.pb.go +++ b/internal/conf/sephirah.pb.go @@ -197,6 +197,7 @@ type Sephirah struct { Cache *Cache `protobuf:"bytes,5,opt,name=cache,proto3" json:"cache,omitempty"` Porter *Porter `protobuf:"bytes,6,opt,name=porter,proto3" json:"porter,omitempty"` Consul *Consul `protobuf:"bytes,7,opt,name=consul,proto3" json:"consul,omitempty"` + Sentry *Sentry `protobuf:"bytes,8,opt,name=sentry,proto3" json:"sentry,omitempty"` } func (x *Sephirah) Reset() { @@ -280,6 +281,13 @@ func (x *Sephirah) GetConsul() *Consul { return nil } +func (x *Sephirah) GetSentry() *Sentry { + if x != nil { + return x.Sentry + } + return nil +} + type SephirahServer_Info struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -473,7 +481,7 @@ var file_conf_sephirah_proto_rawDesc = []byte{ 0x08, 0x52, 0x06, 0x75, 0x73, 0x65, 0x53, 0x73, 0x6c, 0x22, 0x31, 0x0a, 0x06, 0x50, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x12, 0x27, 0x0a, 0x0f, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x72, - 0x75, 0x73, 0x74, 0x65, 0x64, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0xb3, 0x02, 0x0a, + 0x75, 0x73, 0x74, 0x65, 0x64, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0xdf, 0x02, 0x0a, 0x08, 0x53, 0x65, 0x70, 0x68, 0x69, 0x72, 0x61, 0x68, 0x12, 0x32, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x70, 0x68, 0x69, 0x72, 0x61, 0x68, 0x53, @@ -493,9 +501,12 @@ var file_conf_sephirah_proto_rawDesc = []byte{ 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x12, 0x2a, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x73, - 0x75, 0x6c, 0x42, 0x1e, 0x5a, 0x1c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x2f, - 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, - 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x6c, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x53, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x1e, + 0x5a, 0x1c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -524,6 +535,7 @@ var file_conf_sephirah_proto_goTypes = []interface{}{ (*MQ)(nil), // 9: kratos.api.MQ (*Cache)(nil), // 10: kratos.api.Cache (*Consul)(nil), // 11: kratos.api.Consul + (*Sentry)(nil), // 12: kratos.api.Sentry } var file_conf_sephirah_proto_depIdxs = []int32{ 6, // 0: kratos.api.SephirahServer.grpc:type_name -> kratos.api.GRPC @@ -538,11 +550,12 @@ var file_conf_sephirah_proto_depIdxs = []int32{ 10, // 9: kratos.api.Sephirah.cache:type_name -> kratos.api.Cache 2, // 10: kratos.api.Sephirah.porter:type_name -> kratos.api.Porter 11, // 11: kratos.api.Sephirah.consul:type_name -> kratos.api.Consul - 12, // [12:12] is the sub-list for method output_type - 12, // [12:12] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name + 12, // 12: kratos.api.Sephirah.sentry:type_name -> kratos.api.Sentry + 13, // [13:13] is the sub-list for method output_type + 13, // [13:13] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_conf_sephirah_proto_init() } diff --git a/internal/conf/sephirah.proto b/internal/conf/sephirah.proto index 5e79075..c8e58d6 100644 --- a/internal/conf/sephirah.proto +++ b/internal/conf/sephirah.proto @@ -41,4 +41,5 @@ message Sephirah { Cache cache = 5; Porter porter = 6; Consul consul = 7; + Sentry sentry = 8; } diff --git a/internal/lib/libsentry/sentry.go b/internal/lib/libsentry/sentry.go new file mode 100644 index 0000000..cace813 --- /dev/null +++ b/internal/lib/libsentry/sentry.go @@ -0,0 +1,33 @@ +package libsentry + +import ( + "github.com/tuihub/librarian/internal/conf" + + "github.com/getsentry/sentry-go" + sentryotel "github.com/getsentry/sentry-go/otel" + "go.opentelemetry.io/otel" + tracesdk "go.opentelemetry.io/otel/sdk/trace" +) + +func InitSentry(c *conf.Sentry) error { + if c == nil || c.GetDsn() == "" { + return nil + } + // Initialize the Sentry SDK. + err := sentry.Init(sentry.ClientOptions{ //nolint:exhaustruct // no need + Dsn: c.GetDsn(), + AttachStacktrace: true, + EnableTracing: true, + TracesSampleRate: 1.0, + }) + if err != nil { + return err + } + // Initialize the OpenTelemetry tracing integration. + tp := tracesdk.NewTracerProvider( + tracesdk.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()), + ) + otel.SetTracerProvider(tp) + otel.SetTextMapPropagator(sentryotel.NewSentryPropagator()) + return nil +} diff --git a/internal/lib/libsentry/sentry_middleware.go b/internal/lib/libsentry/sentry_middleware.go new file mode 100644 index 0000000..ffd8179 --- /dev/null +++ b/internal/lib/libsentry/sentry_middleware.go @@ -0,0 +1,139 @@ +// Based on https://github.com/go-kratos/sentry + +package libsentry + +import ( + "context" + "errors" + "net" + "os" + "strings" + "time" + + "github.com/getsentry/sentry-go" + "github.com/go-kratos/kratos/v2/middleware" + "github.com/go-kratos/kratos/v2/transport" + "github.com/go-kratos/kratos/v2/transport/grpc" + http2 "github.com/go-kratos/kratos/v2/transport/http" +) + +type valuesKey struct{} + +type Option func(*Options) + +type Options struct { + // Repanic configures whether Sentry should repanic after recovery, in most cases it should be set to true. + Repanic bool + // WaitForDelivery configures whether you want to block the request before moving forward with the response. + WaitForDelivery bool + // Timeout for the event delivery requests. + Timeout time.Duration +} + +func WithRepanic(repanic bool) Option { + return func(opts *Options) { + opts.Repanic = repanic + } +} + +func WithWaitForDelivery(waitForDelivery bool) Option { + return func(opts *Options) { + opts.WaitForDelivery = waitForDelivery + } +} + +func WithTimeout(timeout time.Duration) Option { + return func(opts *Options) { + opts.Timeout = timeout + } +} + +// Server returns a new server middleware for Sentry. +func Server(opts ...Option) middleware.Middleware { //nolint:gocognit // ignore + options := Options{Repanic: true} //nolint: exhaustruct // default options + for _, o := range opts { + o(&options) + } + if options.Timeout == 0 { + options.Timeout = 2 * time.Second //nolint: gomnd // default timeout + } + return func(handler middleware.Handler) middleware.Handler { + return func(ctx context.Context, req interface{}) (interface{}, error) { + hub := sentry.GetHubFromContext(ctx) + if hub == nil { + hub = sentry.CurrentHub().Clone() + } + scope := hub.Scope() + if tr, ok := transport.FromServerContext(ctx); ok { + switch tr.Kind() { + case transport.KindGRPC: + gtr, ok2 := tr.(*grpc.Transport) + if !ok2 { + break + } + scope.SetContext("gRPC", map[string]interface{}{ + "endpoint": gtr.Endpoint(), + "operation": gtr.Operation(), + }) + headers := make(map[string]interface{}) + for _, k := range gtr.RequestHeader().Keys() { + headers[k] = gtr.RequestHeader().Get(k) + } + scope.SetContext("Headers", headers) + case transport.KindHTTP: + htr, ok2 := tr.(*http2.Transport) + if !ok2 { + break + } + r := htr.Request() + scope.SetRequest(r) + } + } + + ctx = context.WithValue(ctx, valuesKey{}, hub) + defer recoverWithSentry(options, hub, ctx, req) + return handler(ctx, req) + } + } +} + +func recoverWithSentry(opts Options, hub *sentry.Hub, ctx context.Context, req interface{}) { + if err := recover(); err != nil { + if !isBrokenPipeError(err) { + eventID := hub.RecoverWithContext( + context.WithValue(ctx, sentry.RequestContextKey, req), + err, + ) + if eventID != nil && opts.WaitForDelivery { + hub.Flush(opts.Timeout) + } + } + if opts.Repanic { + panic(err) + } + } +} + +func isBrokenPipeError(err interface{}) bool { + if err1, ok := err.(error); ok && err1 != nil { //nolint: nestif // ignore + var netErr *net.OpError + if errors.As(err1, &netErr) { + var sysErr *os.SyscallError + if errors.As(netErr.Err, &sysErr) { + if strings.Contains(strings.ToLower(sysErr.Error()), "broken pipe") || + strings.Contains(strings.ToLower(sysErr.Error()), "connection reset by peer") { + return true + } + } + } + } + return false +} + +// GetHubFromContext retrieves attached *sentry.Hub instance from context. +func GetHubFromContext(ctx context.Context) *sentry.Hub { + if hub, ok := ctx.Value(valuesKey{}).(*sentry.Hub); ok { + return hub + } + return nil +} diff --git a/internal/server/grpc.go b/internal/server/grpc.go index e5aaeb0..84dcd29 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -4,12 +4,14 @@ import ( "github.com/tuihub/librarian/internal/conf" "github.com/tuihub/librarian/internal/lib/libapp" "github.com/tuihub/librarian/internal/lib/libauth" + "github.com/tuihub/librarian/internal/lib/libsentry" pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1" "github.com/go-kratos/kratos/v2/middleware" "github.com/go-kratos/kratos/v2/middleware/logging" "github.com/go-kratos/kratos/v2/middleware/ratelimit" "github.com/go-kratos/kratos/v2/middleware/recovery" + "github.com/go-kratos/kratos/v2/middleware/tracing" "github.com/go-kratos/kratos/v2/transport/grpc" ) @@ -27,12 +29,14 @@ func NewGRPCServer( var middlewares = []middleware.Middleware{ logging.Server(libapp.GetLogger()), ratelimit.Server(), + tracing.Server(), validator, } - middlewares = append(middlewares, NewTokenMatcher(auth)...) if app.EnablePanicRecovery { middlewares = append(middlewares, recovery.Recovery()) } + middlewares = append(middlewares, libsentry.Server()) + middlewares = append(middlewares, NewTokenMatcher(auth)...) var opts = []grpc.ServerOption{ grpc.Middleware(middlewares...), } diff --git a/internal/server/grpc_web.go b/internal/server/grpc_web.go index 872ac7b..3c9e81f 100644 --- a/internal/server/grpc_web.go +++ b/internal/server/grpc_web.go @@ -6,11 +6,13 @@ import ( "github.com/tuihub/librarian/internal/conf" "github.com/tuihub/librarian/internal/lib/libapp" "github.com/tuihub/librarian/internal/lib/libauth" + "github.com/tuihub/librarian/internal/lib/libsentry" "github.com/go-kratos/kratos/v2/middleware" "github.com/go-kratos/kratos/v2/middleware/logging" "github.com/go-kratos/kratos/v2/middleware/ratelimit" "github.com/go-kratos/kratos/v2/middleware/recovery" + "github.com/go-kratos/kratos/v2/middleware/tracing" "github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/http" "github.com/improbable-eng/grpc-web/go/grpcweb" @@ -29,12 +31,14 @@ func NewGrpcWebServer( var middlewares = []middleware.Middleware{ logging.Server(libapp.GetLogger()), ratelimit.Server(), + tracing.Server(), validator, } - middlewares = append(middlewares, NewTokenMatcher(auth)...) if app.EnablePanicRecovery { middlewares = append(middlewares, recovery.Recovery()) } + middlewares = append(middlewares, libsentry.Server()) + middlewares = append(middlewares, NewTokenMatcher(auth)...) var opts = []http.ServerOption{ http.Middleware(middlewares...), }