Skip to content

Commit

Permalink
#14 introducing a new telemetry struct
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Dec 19, 2023
1 parent 1c16e4b commit f808c7c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
14 changes: 0 additions & 14 deletions pkg/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cmd
import (
"github.com/spf13/cobra"
"glide/pkg"
"glide/pkg/telemetry"
"go.uber.org/zap"
)

// NewCLI Create a Glide CLI
Expand All @@ -14,18 +12,6 @@ func NewCLI() *cobra.Command {
Use: "",
Version: pkg.GetVersion(),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO: gonna be read from a config file
logConfig := telemetry.NewLogConfig()
logConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
logConfig.Encoding = "console"
logger, err := telemetry.NewLogger(logConfig)

if err != nil {
return err
}

logger.Debug("logger inited")

gateway, err := pkg.NewGateway()

if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"glide/pkg/api"
"glide/pkg/api/http"
"glide/pkg/telemetry"
"go.uber.org/multierr"
"go.uber.org/zap"
"os"
"os/signal"
"syscall"
Expand All @@ -23,13 +25,25 @@ type Gateway struct {
}

func NewGateway() (*Gateway, error) {
// TODO: gonna be read from a config file
logConfig := telemetry.NewLogConfig()
logConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
logConfig.Encoding = "console"

logger, err := telemetry.NewLogger(logConfig)

if err != nil {
return nil, err
}

serverManager, err := api.NewServerManager(&http.HTTPServerConfig{})

if err != nil {
return nil, err
}

return &Gateway{
logger: logger,
serverManager: serverManager,
signalC: make(chan os.Signal, 3), // equal to number of signal types we expect to receive
shutdownC: make(chan struct{}),
Expand Down
7 changes: 0 additions & 7 deletions pkg/telemetry/config.go

This file was deleted.

34 changes: 34 additions & 0 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package telemetry

import "go.uber.org/zap"

type TelemetryConfig struct {
LogConfig *LogConfig `json:"logs" yaml:"logs"`
// TODO: add OTEL config
}

type Telemetry struct {
logger *zap.Logger
// TODO: add OTEL meter, tracer
}

func NewTelemetry(cfg *TelemetryConfig) (*Telemetry, error) {
// TODO: gonna be read from a config file
logConfig := NewLogConfig()
logConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
logConfig.Encoding = "console"

logger, err := telemetry.NewLogger(logConfig)

if err != nil {
return nil, err
}

return &Telemetry{
logger: logger,
}
}

func (t *Telemetry) Logger() *zap.Logger {
return t.logger
}

0 comments on commit f808c7c

Please sign in to comment.