Skip to content

Commit

Permalink
ref(otelify): add method for enable distribution tracing records
Browse files Browse the repository at this point in the history
  • Loading branch information
kenriortega committed Nov 14, 2021
1 parent 88b8dd3 commit 1dbcc79
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cmd/cli/proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"context"

domain "github.com/kenriortega/ngonx/internal/proxy/domain"
handlers "github.com/kenriortega/ngonx/internal/proxy/handlers"
services "github.com/kenriortega/ngonx/internal/proxy/services"
Expand All @@ -9,13 +11,28 @@ import (
"github.com/kenriortega/ngonx/pkg/genkey"
"github.com/kenriortega/ngonx/pkg/httpsrv"
"github.com/kenriortega/ngonx/pkg/logger"
"github.com/kenriortega/ngonx/pkg/otelify"
"github.com/spf13/cobra"
)

var proxyCmd = &cobra.Command{
Use: "proxy",
Short: "Run ngonx as a reverse proxy",
Run: func(cmd *cobra.Command, args []string) {
tracing, err := cmd.Flags().GetBool("tracing")
if err != nil {
logger.LogError(errors.Errorf("proxy: %v", err).Error())
}
if tracing {
flush := otelify.InitProvider(
"example",
"v0.4.5",
"test",
"0.0.0.0:55680",
)
defer flush()
}

port, err := cmd.Flags().GetInt(flagPort)
if err != nil {
logger.LogError(errors.Errorf("proxy: %v", err).Error())
Expand All @@ -35,7 +52,7 @@ var proxyCmd = &cobra.Command{
key := configFromYaml.ProxyCache.Key + "_" + securityType

var proxyRepository domain.ProxyRepository
clientBadger := badgerdb.GetBadgerDB(false)
clientBadger := badgerdb.GetBadgerDB(context.Background(), false)
proxyRepository = domain.NewProxyRepository(clientBadger)
h := handlers.ProxyHandler{
Service: services.NewProxyService(proxyRepository),
Expand All @@ -59,7 +76,6 @@ var proxyCmd = &cobra.Command{
}

for _, endpoints := range configFromYaml.ProxyGateway.EnpointsProxy {

h.ProxyGateway(endpoints, engine, key, securityType)
}

Expand Down Expand Up @@ -89,6 +105,7 @@ var proxyCmd = &cobra.Command{
func init() {
proxyCmd.Flags().Int(flagPort, 5000, "Port to serve to run proxy")
proxyCmd.Flags().Bool(flagGenApiKey, false, "Action for generate hash for protected routes")
proxyCmd.Flags().Bool("tracing", false, "Action for enable distribution tracing")
proxyCmd.Flags().String(flagPrevKey, "", "Action for save a previous hash for protected routes to validate JWT")
rootCmd.AddCommand(proxyCmd)

Expand Down

0 comments on commit 1dbcc79

Please sign in to comment.