go-app/pkg/srv/grpc/services.go

34 lines
877 B
Go

package grpc
import (
"context"
"fmt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
)
func (a *appGRPCServer) registerGRPCServices(ctx context.Context) {
ctx, span := a.tracer.Start(ctx, "appgrpc.init.prepare.services", trace.WithAttributes(
attribute.Int("numServices", len(a.opts.Services)),
))
defer span.End()
for _, service := range a.opts.Services {
a.registerGRPCService(ctx, service)
a.registerServiceGatewayHandlers(ctx, service)
}
span.SetStatus(codes.Ok, "")
}
func (a *appGRPCServer) registerGRPCService(ctx context.Context, service *opts.GRPCService) {
span := trace.SpanFromContext(ctx)
span.AddEvent(fmt.Sprintf("registered %s service", service.Name))
a.server.RegisterService(service.Type, service.Service)
}