Exports OTEL initialization function and adds extensive documentation across packages for improved clarity.

This commit is contained in:
2025-08-13 16:01:51 -04:00
parent 31fc6dca16
commit 318115690d
16 changed files with 50 additions and 23 deletions

View File

@@ -1,3 +1,5 @@
// Package app provides methods to configure, run, and stop
// a go-app.
package app
import (
@@ -11,6 +13,8 @@ import (
httpopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
)
// App is the main application struct, holding its context, configurations,
// and various services like HTTP and gRPC.
type App struct {
AppContext context.Context
HTTP *httpopts.AppHTTP

View File

@@ -62,7 +62,12 @@ func (a *App) initHTTP(ctx context.Context) error {
return err
}
func (a *App) initOTEL() {
func (a *App) InitOTEL() {
if a.tracer != nil {
a.l.Debug().Msg("superfluous call of already configured app otel")
return
}
var otelShutdown shutdownFunc
a.AppContext, otelShutdown = otel.Init(a.AppContext)
a.shutdownFuncs = append(a.shutdownFuncs, otelShutdown)

View File

@@ -27,7 +27,7 @@ func (a *App) monitor() {
a.appDone <- nil // Notify app
}
// Typically invoked when AppContext is done
// Shutdown is typically invoked when AppContext is done
// or Server has exited. Not intended to be called
// manually
func (a *App) Shutdown() {

View File

@@ -35,7 +35,7 @@ func (a *App) MustRun() {
// Start OTEL
// Registers a NO-OP provider if not enabled
a.initOTEL()
a.InitOTEL()
// With OTEL ready, create an init span to track startup
ctx, initSpan := a.tracer.Start(a.AppContext, "init")

View File

@@ -6,11 +6,11 @@ import (
js "github.com/swaggest/jsonschema-go"
)
// Generates json schema for app's config.AppConfig
func (app *App) Schema() ([]byte, error) {
// Schema generates json schema for app's config.AppConfig
func (a *App) Schema() ([]byte, error) {
r := js.Reflector{}
s, err := r.Reflect(*app.cfg)
s, err := r.Reflect(*a.cfg)
if err != nil {
return nil, err
}
@@ -18,7 +18,7 @@ func (app *App) Schema() ([]byte, error) {
return json.MarshalIndent(s, "", " ")
}
// Generates json schema for custom config
// CustomSchema generates json schema for custom config
// which embeds *config.AppConfig into it
// Panics if no *config.AppConfig is embedded into custom
// config type

View File

@@ -9,7 +9,7 @@ import (
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/logging"
)
// Helper function to return a context loaded up with
// MustSetupConfigAndLogging is a helper function to return a context loaded up with
// config.AppConfig and a logger
func MustSetupConfigAndLogging(ctx context.Context) context.Context {
ctx, err := config.LoadConfig(ctx)
@@ -24,7 +24,7 @@ func MustSetupConfigAndLogging(ctx context.Context) context.Context {
return ctx
}
// Unmarshal config into a custom type
// MustSetupConfigAndLoggingInto will unmarshal config into a custom type
// Type MUST include *config.AppConfig
// Stored in context as *config.AppConfig but can be asserted back
func MustSetupConfigAndLoggingInto[T any](ctx context.Context, into T) (context.Context, T) {

View File

@@ -13,7 +13,7 @@ import (
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
)
// Used to unmarshal config and environment into a custom type
// MustLoadConfigInto is used to unmarshal config and environment into a custom type
// that overloads *config.AppConfig. Will perform normal env
// substitutions for AppConfig, but env overrides for custom type
// are up to the caller.