feat: use new logger.CapturedE() api

This commit is contained in:
wpetit 2023-10-19 22:09:18 +02:00
parent b0898eefc3
commit ce9b3003fe
18 changed files with 58 additions and 131 deletions

View File

@ -8,7 +8,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/auth/agent" "forge.cadoles.com/Cadoles/emissary/internal/auth/agent"
"forge.cadoles.com/Cadoles/emissary/internal/jwk" "forge.cadoles.com/Cadoles/emissary/internal/jwk"
"forge.cadoles.com/Cadoles/emissary/pkg/client" "forge.cadoles.com/Cadoles/emissary/pkg/client"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/api" "gitlab.com/wpetit/goweb/api"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -45,16 +44,14 @@ func (a *Agent) Run(ctx context.Context) error {
if err := a.registerAgent(ctx, client, state); err != nil { if err := a.registerAgent(ctx, client, state); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not register agent", logger.E(err)) logger.Error(ctx, "could not register agent", logger.CapturedE(err))
sentry.CaptureException(err)
} }
logger.Debug(ctx, "state before reconciliation", logger.F("state", state)) logger.Debug(ctx, "state before reconciliation", logger.F("state", state))
if err := a.Reconcile(ctx, state); err != nil { if err := a.Reconcile(ctx, state); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not reconcile node with state", logger.E(err)) logger.Error(ctx, "could not reconcile node with state", logger.CapturedE(err))
sentry.CaptureException(err)
return return
} }
@ -85,8 +82,7 @@ func (a *Agent) Reconcile(ctx context.Context, state *State) error {
if err := ctrl.Reconcile(ctrlCtx, state); err != nil { if err := ctrl.Reconcile(ctrlCtx, state); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not reconcile", logger.E(err)) logger.Error(ctx, "could not reconcile", logger.CapturedE(err))
sentry.CaptureException(err)
} }
} }
@ -120,9 +116,8 @@ func (a *Agent) collectMetadata(ctx context.Context) (map[string]any, error) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error( logger.Error(
ctx, "could not collect metadata", ctx, "could not collect metadata",
logger.E(err), logger.F("name", name), logger.CapturedE(err), logger.F("name", name),
) )
sentry.CaptureException(err)
continue continue
} }

View File

@ -23,7 +23,6 @@ import (
"forge.cadoles.com/arcad/edge/pkg/storage/driver" "forge.cadoles.com/arcad/edge/pkg/storage/driver"
"forge.cadoles.com/arcad/edge/pkg/storage/share" "forge.cadoles.com/arcad/edge/pkg/storage/share"
"github.com/Masterminds/sprig/v3" "github.com/Masterminds/sprig/v3"
"github.com/getsentry/sentry-go"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/lestrrat-go/jwx/v2/jwa" "github.com/lestrrat-go/jwx/v2/jwa"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -201,9 +200,8 @@ func createResolveAppURL(specs *spec.Spec) (ResolveAppURLFunc, error) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Warn( logger.Warn(
ctx, "could not find interface", ctx, "could not find interface",
logger.E(err), logger.F("iface", ifaceName), logger.CapturedE(err), logger.F("iface", ifaceName),
) )
sentry.CaptureException(err)
continue continue
} }
@ -213,10 +211,9 @@ func createResolveAppURL(specs *spec.Spec) (ResolveAppURLFunc, error) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error( logger.Error(
ctx, "could not list interface addresses", ctx, "could not list interface addresses",
logger.E(err), logger.CapturedE(err),
logger.F("iface", iface.Name), logger.F("iface", iface.Name),
) )
sentry.CaptureException(err)
continue continue
} }
@ -227,10 +224,9 @@ func createResolveAppURL(specs *spec.Spec) (ResolveAppURLFunc, error) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error( logger.Error(
ctx, "could not parse interface ip", ctx, "could not parse interface ip",
logger.E(err), logger.CapturedE(err),
logger.F("iface", iface.Name), logger.F("iface", iface.Name),
) )
sentry.CaptureException(err)
continue continue
} }

View File

@ -8,7 +8,6 @@ import (
"forge.cadoles.com/arcad/edge/pkg/app" "forge.cadoles.com/arcad/edge/pkg/app"
"forge.cadoles.com/arcad/edge/pkg/bundle" "forge.cadoles.com/arcad/edge/pkg/bundle"
appModule "forge.cadoles.com/arcad/edge/pkg/module/app" appModule "forge.cadoles.com/arcad/edge/pkg/module/app"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -65,8 +64,7 @@ func (r *AppRepository) List(ctx context.Context) ([]*app.Manifest, error) {
bundle, err := bundle.FromPath(path) bundle, err := bundle.FromPath(path)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(bundleCtx, "could not load bundle", logger.E(err)) logger.Error(bundleCtx, "could not load bundle", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
@ -74,8 +72,7 @@ func (r *AppRepository) List(ctx context.Context) ([]*app.Manifest, error) {
manifest, err := app.LoadManifest(bundle) manifest, err := app.LoadManifest(bundle)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(bundleCtx, "could not load manifest", logger.E(err)) logger.Error(bundleCtx, "could not load manifest", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
@ -103,8 +100,7 @@ func (r *AppRepository) findManifest(ctx context.Context, id app.ID) (*app.Manif
bundle, err := bundle.FromPath(path) bundle, err := bundle.FromPath(path)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(bundleCtx, "could not load bundle", logger.E(err)) logger.Error(bundleCtx, "could not load bundle", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
@ -112,8 +108,7 @@ func (r *AppRepository) findManifest(ctx context.Context, id app.ID) (*app.Manif
manifest, err := app.LoadManifest(bundle) manifest, err := app.LoadManifest(bundle)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(bundleCtx, "could not load manifest", logger.E(err)) logger.Error(bundleCtx, "could not load manifest", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }

View File

@ -11,7 +11,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/app/spec" "forge.cadoles.com/Cadoles/emissary/internal/agent/controller/app/spec"
"forge.cadoles.com/arcad/edge/pkg/app" "forge.cadoles.com/arcad/edge/pkg/app"
"forge.cadoles.com/arcad/edge/pkg/bundle" "forge.cadoles.com/arcad/edge/pkg/bundle"
"github.com/getsentry/sentry-go"
"github.com/mitchellh/hashstructure/v2" "github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -71,9 +70,8 @@ func (c *Controller) stopAllApps(ctx context.Context, spec *spec.Spec) {
logger.Error( logger.Error(
ctx, "error while stopping app", ctx, "error while stopping app",
logger.F("appID", appID), logger.F("appID", appID),
logger.E(err), logger.CapturedE(err),
) )
sentry.CaptureException(err)
delete(c.servers, appID) delete(c.servers, appID)
} }
@ -94,9 +92,8 @@ func (c *Controller) updateApps(ctx context.Context, specs *spec.Spec) {
logger.Error( logger.Error(
ctx, "error while stopping app", ctx, "error while stopping app",
logger.F("appKey", appKey), logger.F("appKey", appKey),
logger.E(err), logger.CapturedE(err),
) )
sentry.CaptureException(err)
delete(c.servers, appKey) delete(c.servers, appKey)
} }
@ -106,9 +103,8 @@ func (c *Controller) updateApps(ctx context.Context, specs *spec.Spec) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error( logger.Error(
ctx, "could not update app repository", ctx, "could not update app repository",
logger.E(err), logger.CapturedE(err),
) )
sentry.CaptureException(err)
return return
} }
@ -119,8 +115,7 @@ func (c *Controller) updateApps(ctx context.Context, specs *spec.Spec) {
if err := c.updateApp(ctx, specs, appKey); err != nil { if err := c.updateApp(ctx, specs, appKey); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(appCtx, "could not update app", logger.E(err)) logger.Error(appCtx, "could not update app", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
} }

View File

@ -14,7 +14,6 @@ import (
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
"forge.cadoles.com/arcad/edge/pkg/bundle" "forge.cadoles.com/arcad/edge/pkg/bundle"
"github.com/getsentry/sentry-go"
"github.com/go-chi/chi/middleware" "github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -74,8 +73,7 @@ func (s *Server) Start(ctx context.Context, addr string) (err error) {
if recovered := recover(); recovered != nil { if recovered := recover(); recovered != nil {
if err, ok := recovered.(error); ok { if err, ok := recovered.(error); ok {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, err.Error(), logger.E(err)) logger.Error(ctx, err.Error(), logger.CapturedE(err))
sentry.CaptureException(err)
return return
} }

View File

@ -8,7 +8,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent" "forge.cadoles.com/Cadoles/emissary/internal/agent"
mdns "forge.cadoles.com/Cadoles/emissary/internal/agent/controller/mdns/spec" mdns "forge.cadoles.com/Cadoles/emissary/internal/agent/controller/mdns/spec"
"github.com/brutella/dnssd" "github.com/brutella/dnssd"
"github.com/getsentry/sentry-go"
"github.com/mitchellh/hashstructure/v2" "github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -119,8 +118,7 @@ func (c *Controller) updateResponder(ctx context.Context, spec *mdns.Spec) error
service, err := dnssd.NewService(config) service, err := dnssd.NewService(config)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not create mdns service", logger.E(err)) logger.Error(ctx, "could not create mdns service", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
@ -136,8 +134,7 @@ func (c *Controller) updateResponder(ctx context.Context, spec *mdns.Spec) error
for _, service := range services { for _, service := range services {
if _, err := responder.Add(service); err != nil { if _, err := responder.Add(service); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not add mdns service", logger.E(err)) logger.Error(ctx, "could not add mdns service", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
@ -154,8 +151,7 @@ func (c *Controller) updateResponder(ctx context.Context, spec *mdns.Spec) error
if err := responder.Respond(ctx); err != nil && !errors.Is(err, context.Canceled) { if err := responder.Respond(ctx); err != nil && !errors.Is(err, context.Canceled) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not respond to mdns queries", logger.E(err)) logger.Error(ctx, "could not respond to mdns queries", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()

View File

@ -11,7 +11,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent" "forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/openwrt/spec/sysupgrade" "forge.cadoles.com/Cadoles/emissary/internal/agent/controller/openwrt/spec/sysupgrade"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -68,10 +67,9 @@ func (c *SysUpgradeController) Reconcile(ctx context.Context, state *agent.State
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error( logger.Error(
ctx, "could not remove download direction", ctx, "could not remove download direction",
logger.E(err), logger.CapturedE(err),
logger.F("downloadDir", downloadDir), logger.F("downloadDir", downloadDir),
) )
sentry.CaptureException(err)
} }
}() }()

View File

@ -9,7 +9,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent" "forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/openwrt/uci" "forge.cadoles.com/Cadoles/emissary/internal/openwrt/uci"
ucispec "forge.cadoles.com/Cadoles/emissary/internal/spec/uci" ucispec "forge.cadoles.com/Cadoles/emissary/internal/spec/uci"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -48,8 +47,7 @@ func (c *UCIController) Reconcile(ctx context.Context, state *agent.State) error
if err := c.updateConfiguration(ctx, uciSpec); err != nil { if err := c.updateConfiguration(ctx, uciSpec); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not update configuration", logger.E(err)) logger.Error(ctx, "could not update configuration", logger.CapturedE(err))
sentry.CaptureException(err)
return nil return nil
} }

View File

@ -10,7 +10,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent" "forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/spec" "forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -147,8 +146,7 @@ func (c *Controller) writeState(ctx context.Context, state *agent.State) error {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not remove temporary file", logger.E(err)) logger.Error(ctx, "could not remove temporary file", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()
@ -159,8 +157,7 @@ func (c *Controller) writeState(ctx context.Context, state *agent.State) error {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not close temporary file", logger.E(err)) logger.Error(ctx, "could not close temporary file", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()

View File

@ -7,7 +7,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent" "forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/proxy" "forge.cadoles.com/Cadoles/emissary/internal/proxy"
spec "forge.cadoles.com/Cadoles/emissary/internal/spec/proxy" spec "forge.cadoles.com/Cadoles/emissary/internal/spec/proxy"
"github.com/getsentry/sentry-go"
"github.com/mitchellh/hashstructure/v2" "github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -63,9 +62,8 @@ func (c *Controller) stopAllProxies(ctx context.Context) {
logger.Error( logger.Error(
ctx, "error while stopping proxy", ctx, "error while stopping proxy",
logger.F("proxyID", proxyID), logger.F("proxyID", proxyID),
logger.E(err), logger.CapturedE(err),
) )
sentry.CaptureException(err)
delete(c.proxies, proxyID) delete(c.proxies, proxyID)
} }
@ -86,9 +84,8 @@ func (c *Controller) updateProxies(ctx context.Context, spec *spec.Spec) {
logger.Error( logger.Error(
ctx, "error while stopping proxy", ctx, "error while stopping proxy",
logger.F("proxyID", proxyID), logger.F("proxyID", proxyID),
logger.E(err), logger.CapturedE(err),
) )
sentry.CaptureException(err)
delete(c.proxies, proxyID) delete(c.proxies, proxyID)
} }
@ -100,8 +97,7 @@ func (c *Controller) updateProxies(ctx context.Context, spec *spec.Spec) {
if err := c.updateProxy(ctx, proxyID, proxySpec); err != nil { if err := c.updateProxy(ctx, proxyID, proxySpec); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(proxyCtx, "could not update proxy", logger.E(err)) logger.Error(proxyCtx, "could not update proxy", logger.CapturedE(err))
sentry.CaptureException(err)
continue continue
} }
} }

View File

@ -6,7 +6,6 @@ import (
"sync" "sync"
"forge.cadoles.com/Cadoles/emissary/internal/proxy" "forge.cadoles.com/Cadoles/emissary/internal/proxy"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -40,15 +39,13 @@ func (p *ReverseProxy) Start(ctx context.Context, addr string, funcs ...proxy.Op
defer func() { defer func() {
if err := p.Stop(); err != nil { if err := p.Stop(); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "error while stopping gateway", logger.E(err)) logger.Error(ctx, "error while stopping gateway", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "error while listening", logger.E(err)) logger.Error(ctx, "error while listening", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()

View File

@ -6,7 +6,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent" "forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/datastore" "forge.cadoles.com/Cadoles/emissary/internal/datastore"
"forge.cadoles.com/Cadoles/emissary/pkg/client" "forge.cadoles.com/Cadoles/emissary/pkg/client"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -49,8 +48,7 @@ func (c *Controller) reconcileAgent(ctx context.Context, client *client.Client,
specs, err := client.GetAgentSpecs(ctx, agent.ID) specs, err := client.GetAgentSpecs(ctx, agent.ID)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not retrieve agent specs", logger.E(err)) logger.Error(ctx, "could not retrieve agent specs", logger.CapturedE(err))
sentry.CaptureException(err)
return nil return nil
} }

View File

@ -64,6 +64,10 @@ func Main(buildDate, projectVersion, gitRef, defaultConfigPath string, commands
if err != nil { if err != nil {
logger.Error(ctx.Context, "could not initialize sentry", logger.E(errors.WithStack(err))) logger.Error(ctx.Context, "could not initialize sentry", logger.E(errors.WithStack(err)))
} }
logger.SetCaptureFunc(func(err error) {
sentry.CaptureException(err)
})
} }
return nil return nil

View File

@ -5,7 +5,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/command/common" "forge.cadoles.com/Cadoles/emissary/internal/command/common"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -34,8 +33,7 @@ func PingCommand() *cli.Command {
defer func() { defer func() {
if err := db.Close(); err != nil { if err := db.Close(); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx.Context, "error while closing database connection", logger.E(err)) logger.Error(ctx.Context, "error while closing database connection", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()

View File

@ -9,7 +9,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/datastore" "forge.cadoles.com/Cadoles/emissary/internal/datastore"
"github.com/getsentry/sentry-go"
"github.com/lestrrat-go/jwx/v2/jwk" "github.com/lestrrat-go/jwx/v2/jwk"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -74,8 +73,7 @@ func (r *AgentRepository) GetSpecs(ctx context.Context, agentID datastore.AgentI
defer func() { defer func() {
if err := rows.Close(); err != nil { if err := rows.Close(); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not close rows", logger.E(err)) logger.Error(ctx, "could not close rows", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()
@ -230,8 +228,7 @@ func (r *AgentRepository) Query(ctx context.Context, opts ...datastore.AgentQuer
defer func() { defer func() {
if err := rows.Close(); err != nil { if err := rows.Close(); err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not close rows", logger.E(errors.WithStack(err))) logger.Error(ctx, "could not close rows", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()
@ -550,8 +547,7 @@ func (r *AgentRepository) withTx(ctx context.Context, fn func(*sql.Tx) error) er
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not rollback transaction", logger.E(err)) logger.Error(ctx, "could not rollback transaction", logger.CapturedE(err))
sentry.CaptureException(err)
} }
}() }()

View File

@ -9,7 +9,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata" "forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
"forge.cadoles.com/Cadoles/emissary/internal/datastore" "forge.cadoles.com/Cadoles/emissary/internal/datastore"
"forge.cadoles.com/Cadoles/emissary/internal/jwk" "forge.cadoles.com/Cadoles/emissary/internal/jwk"
"github.com/getsentry/sentry-go"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/api" "gitlab.com/wpetit/goweb/api"
@ -41,8 +40,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
keySet, err := jwk.Parse(registerAgentReq.KeySet) keySet, err := jwk.Parse(registerAgentReq.KeySet)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not parse key set", logger.E(err)) logger.Error(ctx, "could not parse key set", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -55,8 +53,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
validSignature, err := jwk.Verify(keySet, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata) validSignature, err := jwk.Verify(keySet, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not validate signature", logger.E(err)) logger.Error(ctx, "could not validate signature", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -80,8 +77,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
if !errors.Is(err, datastore.ErrAlreadyExist) { if !errors.Is(err, datastore.ErrAlreadyExist) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not create agent", logger.E(err)) logger.Error(ctx, "could not create agent", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -94,8 +90,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
) )
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not retrieve agents", logger.E(err)) logger.Error(ctx, "could not retrieve agents", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -103,9 +98,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
if len(agents) == 0 { if len(agents) == 0 {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not retrieve matching agent", logger.E(err)) logger.Error(ctx, "could not retrieve matching agent", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeNotFound, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeNotFound, nil)
return return
@ -118,9 +111,8 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error( logger.Error(
ctx, "could not retrieve agent", ctx, "could not retrieve agent",
logger.E(err), logger.F("agentID", agentID), logger.CapturedE(err), logger.F("agentID", agentID),
) )
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
@ -130,8 +122,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
validSignature, err = jwk.Verify(agent.KeySet.Set, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata) validSignature, err = jwk.Verify(agent.KeySet.Set, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not validate signature using previous keyset", logger.E(err)) logger.Error(ctx, "could not validate signature using previous keyset", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil) api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil)
@ -146,8 +137,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
) )
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not update agent", logger.E(err)) logger.Error(ctx, "could not update agent", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
@ -197,9 +187,7 @@ func (s *Server) updateAgent(w http.ResponseWriter, r *http.Request) {
) )
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not update agent", logger.E(err)) logger.Error(ctx, "could not update agent", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -281,9 +269,7 @@ func (s *Server) queryAgents(w http.ResponseWriter, r *http.Request) {
) )
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not list agents", logger.E(err)) logger.Error(ctx, "could not list agents", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -318,9 +304,7 @@ func (s *Server) deleteAgent(w http.ResponseWriter, r *http.Request) {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not delete agent", logger.E(err)) logger.Error(ctx, "could not delete agent", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -353,9 +337,7 @@ func (s *Server) getAgent(w http.ResponseWriter, r *http.Request) {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not get agent", logger.E(err)) logger.Error(ctx, "could not get agent", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
return return
@ -373,7 +355,7 @@ func getAgentID(w http.ResponseWriter, r *http.Request) (datastore.AgentID, bool
agentID, err := strconv.ParseInt(rawAgentID, 10, 64) agentID, err := strconv.ParseInt(rawAgentID, 10, 64)
if err != nil { if err != nil {
logger.Error(r.Context(), "could not parse agent id", logger.E(errors.WithStack(err))) logger.Error(r.Context(), "could not parse agent id", logger.CapturedE(errors.WithStack(err)))
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil) api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
return 0, false return 0, false
@ -388,9 +370,7 @@ func getIntQueryParam(w http.ResponseWriter, r *http.Request, param string, defa
value, err := strconv.ParseInt(rawValue, 10, 64) value, err := strconv.ParseInt(rawValue, 10, 64)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(r.Context(), "could not parse int param", logger.F("param", param), logger.E(err)) logger.Error(r.Context(), "could not parse int param", logger.F("param", param), logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil) api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
return 0, false return 0, false
@ -424,9 +404,7 @@ func getIntSliceValues(w http.ResponseWriter, r *http.Request, param string, def
value, err := strconv.ParseInt(rv, 10, 64) value, err := strconv.ParseInt(rv, 10, 64)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(r.Context(), "could not parse int slice param", logger.F("param", param), logger.E(err)) logger.Error(r.Context(), "could not parse int slice param", logger.F("param", param), logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil) api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
return nil, false return nil, false

View File

@ -8,7 +8,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/auth" "forge.cadoles.com/Cadoles/emissary/internal/auth"
"forge.cadoles.com/Cadoles/emissary/internal/auth/agent" "forge.cadoles.com/Cadoles/emissary/internal/auth/agent"
"forge.cadoles.com/Cadoles/emissary/internal/auth/thirdparty" "forge.cadoles.com/Cadoles/emissary/internal/auth/thirdparty"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/api" "gitlab.com/wpetit/goweb/api"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
@ -126,8 +125,7 @@ func assertRequestUser(w http.ResponseWriter, r *http.Request) (auth.User, bool)
user, err := auth.CtxUser(ctx) user, err := auth.CtxUser(ctx)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not retrieve user", logger.E(err)) logger.Error(ctx, "could not retrieve user", logger.CapturedE(err))
sentry.CaptureException(err)
forbidden(w, r) forbidden(w, r)

View File

@ -6,7 +6,6 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/datastore" "forge.cadoles.com/Cadoles/emissary/internal/datastore"
"forge.cadoles.com/Cadoles/emissary/internal/spec" "forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/getsentry/sentry-go"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/api" "gitlab.com/wpetit/goweb/api"
@ -46,8 +45,7 @@ func (s *Server) updateSpec(w http.ResponseWriter, r *http.Request) {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not validate spec", logger.E(err)) logger.Error(ctx, "could not validate spec", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, data) api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, data)
@ -75,8 +73,7 @@ func (s *Server) updateSpec(w http.ResponseWriter, r *http.Request) {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not update spec", logger.E(err)) logger.Error(ctx, "could not update spec", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
@ -107,8 +104,7 @@ func (s *Server) getAgentSpecs(w http.ResponseWriter, r *http.Request) {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not list specs", logger.E(err)) logger.Error(ctx, "could not list specs", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
@ -152,8 +148,7 @@ func (s *Server) deleteSpec(w http.ResponseWriter, r *http.Request) {
} }
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(ctx, "could not delete spec", logger.E(err)) logger.Error(ctx, "could not delete spec", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
@ -173,8 +168,7 @@ func getSpecID(w http.ResponseWriter, r *http.Request) (datastore.SpecID, bool)
specID, err := strconv.ParseInt(rawSpecID, 10, 64) specID, err := strconv.ParseInt(rawSpecID, 10, 64)
if err != nil { if err != nil {
err = errors.WithStack(err) err = errors.WithStack(err)
logger.Error(r.Context(), "could not parse spec id", logger.E(err)) logger.Error(r.Context(), "could not parse spec id", logger.CapturedE(err))
sentry.CaptureException(err)
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil) api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)