adds OpenTelemetry startup tracing, updates Go dependencies, and refines build configurations
This commit is contained in:
41
main.go
41
main.go
@@ -19,16 +19,23 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/demo"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/service"
|
||||
)
|
||||
|
||||
const terminationGracePeriod = 30 * time.Second
|
||||
const (
|
||||
terminationGracePeriod = 30 * time.Second
|
||||
appName = "demo-app"
|
||||
)
|
||||
|
||||
var (
|
||||
// TODO: Register your service.AppService implementers here
|
||||
@@ -51,14 +58,24 @@ func main() {
|
||||
// app config struct which embeds app.AooConfig
|
||||
ctx, serviceConfig := app.MustLoadConfigInto(ctx, &config.ServiceConfig{})
|
||||
|
||||
log := zerolog.Ctx(ctx)
|
||||
|
||||
// Print schema if that's all we have to do
|
||||
if flagSchema {
|
||||
printSchema()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prepare app
|
||||
app := &app.App{
|
||||
AppContext: ctx,
|
||||
}
|
||||
app.InitOTEL()
|
||||
|
||||
tracer := otel.GetTracer(ctx, appName)
|
||||
ctx, span := tracer.Start(ctx, appName+".startup", trace.WithAttributes(
|
||||
attribute.Int("appServices", len(appServices)),
|
||||
))
|
||||
|
||||
log := zerolog.Ctx(ctx)
|
||||
log.Debug().Any("mergedConfig", serviceConfig).Msg("App configuration prepared")
|
||||
|
||||
// Prepare services
|
||||
@@ -67,23 +84,25 @@ func main() {
|
||||
for i, svc := range appServices {
|
||||
sdFuncs[i], err = svc.Init(ctx, serviceConfig)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
log.Fatal().Err(err).Send()
|
||||
}
|
||||
}
|
||||
span.AddEvent("app services initialized")
|
||||
|
||||
// Merge all service implementations for app
|
||||
// Merge all service implementations and add to app
|
||||
grpcSvcs, httpSvcs := service.MergeServices(ctx, appServices...)
|
||||
|
||||
// Prepare app with all merged services
|
||||
app := &app.App{
|
||||
AppContext: ctx,
|
||||
GRPC: grpcSvcs,
|
||||
HTTP: httpSvcs,
|
||||
}
|
||||
app.GRPC = grpcSvcs
|
||||
app.HTTP = httpSvcs
|
||||
|
||||
// Launch app
|
||||
app.MustRun()
|
||||
|
||||
span.AddEvent("app started")
|
||||
span.SetStatus(codes.Ok, "")
|
||||
span.End()
|
||||
|
||||
// Wait for app to complete and then perform internal shutdown
|
||||
<-app.Done()
|
||||
|
||||
|
Reference in New Issue
Block a user