71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
|
srvgrpc "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc"
|
|
grpcopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
|
srvhttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http"
|
|
)
|
|
|
|
func (a *App) initGRPC(ctx context.Context) error {
|
|
ctx, span := a.tracer.Start(ctx, "init.grpc")
|
|
defer span.End()
|
|
|
|
shutdown, doneChan, err := srvgrpc.InitGRPCServer(ctx,
|
|
&grpcopts.GRPCOpts{
|
|
GRPCConfig: a.cfg.GRPC,
|
|
AppGRPC: a.GRPC,
|
|
})
|
|
if err != nil {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, err.Error())
|
|
return err
|
|
}
|
|
|
|
a.shutdownFuncs = append(a.shutdownFuncs, shutdown)
|
|
a.GRPC.GRPCDone = doneChan
|
|
|
|
span.SetStatus(codes.Ok, "")
|
|
return nil
|
|
}
|
|
|
|
func (a *App) initHTTP(ctx context.Context) error {
|
|
var err error
|
|
var httpShutdown shutdownFunc
|
|
|
|
_, span := a.tracer.Start(ctx, "init.http")
|
|
defer span.End()
|
|
|
|
span.SetAttributes(
|
|
attribute.Int("numHTTPFuncs", len(a.HTTP.Funcs)),
|
|
attribute.Int("numHTTPMiddlewares", len(a.HTTP.Middleware)),
|
|
attribute.Int("numHTTPHealthChecks", len(a.HTTP.HealthChecks)),
|
|
)
|
|
|
|
a.HTTP.Ctx = a.AppContext
|
|
httpShutdown, a.HTTP.HTTPDone, err = srvhttp.InitHTTPServer(a.HTTP)
|
|
|
|
a.shutdownFuncs = append(a.shutdownFuncs, httpShutdown)
|
|
|
|
if err != nil {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, err.Error())
|
|
} else {
|
|
span.SetStatus(codes.Ok, "")
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (a *App) initOTEL() {
|
|
var otelShutdown shutdownFunc
|
|
a.AppContext, otelShutdown = otel.Init(a.AppContext)
|
|
a.shutdownFuncs = append(a.shutdownFuncs, otelShutdown)
|
|
a.tracer = otel.MustTracerFromCtx(a.AppContext)
|
|
}
|