Skip to content

Commit

Permalink
GO-3508 Add dependencies tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
fat-fellow committed Nov 28, 2024
1 parent 862827a commit bd1f84b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ type ComponentStatable interface {
// App is the central part of the application
// It contains and manages all components
type App struct {
parent *App
components []Component
mu sync.RWMutex
startStat Stat
stopStat Stat
deviceState int
versionName string
anySyncVersion string
parent *App
components []Component
mu sync.RWMutex
startStat Stat
stopStat Stat
deviceState int
versionName string
anySyncVersion string
componentListener func(comp Component)
}

// Name returns app name
Expand Down Expand Up @@ -170,6 +171,7 @@ func (app *App) Component(name string) Component {
// MustComponent is like Component, but it will panic if service wasn't found
func (app *App) MustComponent(name string) Component {
s := app.Component(name)
app.onComponent(s)
if s == nil {
panic(fmt.Errorf("component '%s' not registered", name))
}
Expand All @@ -184,6 +186,7 @@ func MustComponent[i any](app *App) i {
for current != nil {
for _, s := range current.components {
if v, ok := s.(i); ok {
app.onComponent(s)
return v
}
}
Expand Down Expand Up @@ -384,3 +387,9 @@ func (app *App) AnySyncVersion() string {
})
return app.anySyncVersion
}

func (app *App) onComponent(s Component) {
if app.componentListener != nil {
app.componentListener(s)
}
}
8 changes: 8 additions & 0 deletions app/apptrace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build appdebug
// +build appdebug

package app

func (app *App) SetOnComponentListener(listener func(comp Component)) {
app.componentListener = listener
}

0 comments on commit bd1f84b

Please sign in to comment.