mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-30 08:50:49 -06:00
Change invitations to use service tracing provider
This changes the invitations service to use the service tracing provider.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/config/parser"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/server/http"
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/service/v0"
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/tracing"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
svc, err := service.New(
|
||||
service.Logger(logger),
|
||||
service.Config(cfg),
|
||||
//service.WithRelationProviders(relationProviders),
|
||||
// service.WithRelationProviders(relationProviders),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("handler init")
|
||||
@@ -62,7 +62,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
}
|
||||
svc = service.NewInstrument(svc, metrics)
|
||||
svc = service.NewLogging(svc, logger) // this logs service specific data
|
||||
svc = service.NewTracing(svc)
|
||||
svc = service.NewTracing(svc, traceProvider)
|
||||
|
||||
server, err := http.Server(
|
||||
http.Logger(logger),
|
||||
@@ -70,7 +70,6 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
http.Config(cfg),
|
||||
http.Service(svc),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Info().
|
||||
Err(err).
|
||||
@@ -98,7 +97,6 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
debug.Context(ctx),
|
||||
debug.Config(cfg),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||
return err
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
|
||||
// Tracing defines the available tracing configuration.
|
||||
type Tracing struct {
|
||||
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;INVITATIONS_TRACING_ENABLED" desc:"Activates tracing."`
|
||||
@@ -7,3 +9,13 @@ type Tracing struct {
|
||||
Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;INVITATIONS_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."`
|
||||
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;INVITATIONS_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."`
|
||||
}
|
||||
|
||||
// Convert Tracing to the tracing package's Config struct.
|
||||
func (t Tracing) Convert() tracing.Config {
|
||||
return tracing.Config{
|
||||
Enabled: t.Enabled,
|
||||
Type: t.Type,
|
||||
Endpoint: t.Endpoint,
|
||||
Collector: t.Collector,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,21 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/invitations"
|
||||
invitationstracing "github.com/owncloud/ocis/v2/services/invitations/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// NewTracing returns a service that instruments traces.
|
||||
func NewTracing(next Service) Service {
|
||||
func NewTracing(next Service, tp trace.TracerProvider) Service {
|
||||
return tracing{
|
||||
next: next,
|
||||
tp: tp,
|
||||
}
|
||||
}
|
||||
|
||||
type tracing struct {
|
||||
next Service
|
||||
tp trace.TracerProvider
|
||||
}
|
||||
|
||||
// Invite implements the Service interface.
|
||||
@@ -27,8 +28,9 @@ func (t tracing) Invite(ctx context.Context, invitation *invitations.Invitation)
|
||||
trace.WithAttributes(
|
||||
attribute.KeyValue{
|
||||
Key: "invitation", Value: attribute.StringValue(invitation.InvitedUserEmailAddress),
|
||||
})}
|
||||
ctx, span := invitationstracing.TraceProvider.Tracer("invitations").Start(ctx, "Invite", spanOpts...)
|
||||
}),
|
||||
}
|
||||
ctx, span := t.tp.Tracer("invitations").Start(ctx, "Invite", spanOpts...)
|
||||
defer span.End()
|
||||
|
||||
return t.next.Invite(ctx, invitation)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/config"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
var err error
|
||||
if cfg.Tracing.Enabled {
|
||||
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user