mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-08 04:48:06 -06:00
feat: initial tracing support (#1623)
This commit is contained in:
parent
878ed48de3
commit
6392e00653
472 changed files with 102600 additions and 12 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue