Skip to content

Commit

Permalink
feat: wire up basic tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
shipperizer committed Dec 10, 2023
1 parent d05630f commit 1c2b23c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions v2/glauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/glauth/glauth/v2/internal/monitoring"
"github.com/glauth/glauth/v2/internal/toml"
"github.com/glauth/glauth/v2/internal/tracing"
"github.com/glauth/glauth/v2/internal/version"
"github.com/glauth/glauth/v2/pkg/config"
"github.com/glauth/glauth/v2/pkg/frontend"
Expand Down Expand Up @@ -128,13 +129,15 @@ func startService() {
}

monitor := monitoring.NewMonitor(&log)
tracer := tracing.NewTracer(tracing.NewConfig(true, "", "", &log))

startConfigWatcher()

s, err := server.NewServer(
server.Logger(log),
server.Config(activeConfig),
server.Monitor(monitor),
server.Tracer(tracer),
)

if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions v2/pkg/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/rs/zerolog"
"go.opentelemetry.io/otel/trace"

"github.com/glauth/glauth/v2/internal/monitoring"
"github.com/glauth/glauth/v2/pkg/config"
Expand All @@ -17,6 +18,7 @@ type Options struct {
Logger zerolog.Logger
Config *config.Config
Monitor monitoring.MonitorInterface
Tracer trace.Tracer
Context context.Context
}

Expand Down Expand Up @@ -58,3 +60,10 @@ func Monitor(val monitoring.MonitorInterface) Option {
o.Monitor = val
}
}

// Tracer provides a function to set the tracer option.
func Tracer(val trace.Tracer) Option {
return func(o *Options) {
o.Tracer = val
}
}
11 changes: 10 additions & 1 deletion v2/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"plugin"

"github.com/rs/zerolog"
"go.opentelemetry.io/otel/trace"

"github.com/GeertJohan/yubigo"
"github.com/glauth/glauth/v2/internal/monitoring"
Expand All @@ -20,6 +21,7 @@ type LdapSvc struct {
l *ldap.Server

monitor monitoring.MonitorInterface
tracer trace.Tracer
log zerolog.Logger
}

Expand All @@ -30,6 +32,7 @@ func NewServer(opts ...Option) (*LdapSvc, error) {
log: options.Logger,
c: options.Config,
monitor: options.Monitor,
tracer: options.Tracer,
}

var err error
Expand All @@ -44,7 +47,7 @@ func NewServer(opts ...Option) (*LdapSvc, error) {

var helper handler.Handler

loh := handler.NewLDAPOpsHelper()
loh := handler.NewLDAPOpsHelper(s.tracer)

// instantiate the helper, if any
if s.c.Helper.Enabled {
Expand All @@ -55,6 +58,7 @@ func NewServer(opts ...Option) (*LdapSvc, error) {
handler.Config(s.c),
handler.YubiAuth(s.yubiAuth),
handler.LDAPHelper(loh),
handler.Tracer(s.tracer),
)
case "plugin":
plug, err := plugin.Open(s.c.Helper.Plugin)
Expand All @@ -77,6 +81,7 @@ func NewServer(opts ...Option) (*LdapSvc, error) {
handler.Config(s.c),
handler.YubiAuth(s.yubiAuth),
handler.LDAPHelper(loh),
handler.Tracer(s.tracer),
)
default:
return nil, fmt.Errorf("unsupported helper %s - must be one of 'config', 'plugin'", s.c.Helper.Datastore)
Expand All @@ -100,12 +105,14 @@ func NewServer(opts ...Option) (*LdapSvc, error) {
handler.Logger(&s.log),
handler.Helper(helper),
handler.Monitor(s.monitor),
handler.Tracer(s.tracer),
)
case "owncloud":
h = handler.NewOwnCloudHandler(
handler.Backend(backend),
handler.Logger(&s.log),
handler.Monitor(s.monitor),
handler.Tracer(s.tracer),
)
case "config":
h = handler.NewConfigHandler(
Expand All @@ -115,6 +122,7 @@ func NewServer(opts ...Option) (*LdapSvc, error) {
handler.YubiAuth(s.yubiAuth),
handler.LDAPHelper(loh),
handler.Monitor(s.monitor),
handler.Tracer(s.tracer),
)
case "plugin":
plug, err := plugin.Open(backend.Plugin)
Expand All @@ -139,6 +147,7 @@ func NewServer(opts ...Option) (*LdapSvc, error) {
handler.YubiAuth(s.yubiAuth),
handler.LDAPHelper(loh),
handler.Monitor(s.monitor),
handler.Tracer(s.tracer),
)
default:
return nil, fmt.Errorf("unsupported backend %s - must be one of 'config', 'ldap','owncloud' or 'plugin'", backend.Datastore)
Expand Down

0 comments on commit 1c2b23c

Please sign in to comment.