This commit is contained in:
2025-01-03 21:49:59 -05:00
parent b93f8fb6c8
commit 7d4e3ea1bd
5 changed files with 358 additions and 9 deletions

28
main.go
View File

@ -12,12 +12,16 @@ import (
"context"
"os"
"os/signal"
"time"
"github.com/rs/zerolog"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/codes"
"golang.org/x/sys/unix"
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config"
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/logging"
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/observability"
)
func main() {
@ -32,8 +36,27 @@ func main() {
cfg := config.MustFromCtx(ctx)
ctx = logging.MustInitLogging(ctx)
l := zerolog.Ctx(ctx)
// Set up OTEL
opts := make([]observability.Option, 0)
if cfg.Logging.Level == "trace" {
opts = append(opts, observability.EnableStdoutExporter)
}
shutdown := observability.Init(ctx, opts...)
defer func() {
shutdownCtx, cncl := context.WithTimeout(context.Background(), 30*time.Second)
defer cncl()
shutdown(shutdownCtx)
}()
// Begin Server init
tracer := otel.Tracer(cfg.Name)
_, initSpan := tracer.Start(ctx, "init")
// TODO: HTTP Server
// App Ready
l.Trace().Any("config", *cfg).Send()
l.Info().
Str("name", cfg.Name).
@ -41,6 +64,9 @@ func main() {
Str("logLevel", cfg.Logging.Level).
Msg("app initialized")
initSpan.SetStatus(codes.Ok, "")
initSpan.End()
<-ctx.Done()
}