summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar Dominik Süß <dominik@suess.wtf>2023-05-09 19:19:48 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-09 18:19:48 +0100
commit6392e00653d3b81062ef60d8ae2fa2621873533f (patch)
tree761d0ff445c2c6a85020cecdc58f92ae1cf78513 /cmd
parent[bugfix] Don't try to get user when serializing local instance account (#1757) (diff)
downloadgotosocial-6392e00653d3b81062ef60d8ae2fa2621873533f.tar.xz
feat: initial tracing support (#1623)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/action/server/server.go22
-rw-r--r--cmd/gotosocial/action/testrig/testrig.go20
2 files changed, 34 insertions, 8 deletions
diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go
index b4329fec7..b33688800 100644
--- a/cmd/gotosocial/action/server/server.go
+++ b/cmd/gotosocial/action/server/server.go
@@ -32,6 +32,7 @@ import (
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/middleware"
+ "github.com/superseriousbusiness/gotosocial/internal/tracing"
"go.uber.org/automaxprocs/maxprocs"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -70,6 +71,12 @@ var Start action.GTSAction = func(ctx context.Context) error {
state.Caches.Start()
defer state.Caches.Stop()
+ // Initialize Tracing
+
+ if err := tracing.Initialize(); err != nil {
+ return fmt.Errorf("error initializing tracing: %w", err)
+ }
+
// Open connection to the database
dbService, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
@@ -146,16 +153,23 @@ var Start action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating router: %s", err)
}
- // attach global middlewares which are used for every request
- router.AttachGlobalMiddleware(
- middleware.AddRequestID(config.GetRequestIDHeader()),
+ middlewares := []gin.HandlerFunc{
+ middleware.AddRequestID(config.GetRequestIDHeader()), // requestID middleware must run before tracing
+ }
+ if config.GetTracingEnabled() {
+ middlewares = append(middlewares, tracing.InstrumentGin())
+ }
+ middlewares = append(middlewares, []gin.HandlerFunc{
// note: hooks adding ctx fields must be ABOVE
// the logger, otherwise won't be accessible.
middleware.Logger(),
middleware.UserAgent(),
middleware.CORS(),
middleware.ExtraHeaders(),
- )
+ }...)
+
+ // attach global middlewares which are used for every request
+ router.AttachGlobalMiddleware(middlewares...)
// attach global no route / 404 handler to the router
router.AttachNoRouteHandler(func(c *gin.Context) {
diff --git a/cmd/gotosocial/action/testrig/testrig.go b/cmd/gotosocial/action/testrig/testrig.go
index ba944a148..b5d34e7c9 100644
--- a/cmd/gotosocial/action/testrig/testrig.go
+++ b/cmd/gotosocial/action/testrig/testrig.go
@@ -40,6 +40,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oidc"
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/storage"
+ "github.com/superseriousbusiness/gotosocial/internal/tracing"
"github.com/superseriousbusiness/gotosocial/internal/web"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -51,6 +52,10 @@ var Start action.GTSAction = func(ctx context.Context) error {
testrig.InitTestConfig()
testrig.InitTestLog()
+ if err := tracing.Initialize(); err != nil {
+ return fmt.Errorf("error initializing tracing: %w", err)
+ }
+
// Initialize caches
state.Caches.Init()
state.Caches.Start()
@@ -93,14 +98,21 @@ var Start action.GTSAction = func(ctx context.Context) error {
*/
router := testrig.NewTestRouter(state.DB)
-
- // attach global middlewares which are used for every request
- router.AttachGlobalMiddleware(
+ middlewares := []gin.HandlerFunc{
+ middleware.AddRequestID(config.GetRequestIDHeader()), // requestID middleware must run before tracing
+ }
+ if config.GetTracingEnabled() {
+ middlewares = append(middlewares, tracing.InstrumentGin())
+ }
+ middlewares = append(middlewares, []gin.HandlerFunc{
middleware.Logger(),
middleware.UserAgent(),
middleware.CORS(),
middleware.ExtraHeaders(),
- )
+ }...)
+
+ // attach global middlewares which are used for every request
+ router.AttachGlobalMiddleware(middlewares...)
// attach global no route / 404 handler to the router
router.AttachNoRouteHandler(func(c *gin.Context) {