From 1dbcc790545ec52ce0a490d0f96a32ba8f10c034 Mon Sep 17 00:00:00 2001 From: kenriortega Date: Sat, 13 Nov 2021 20:49:52 -0500 Subject: [PATCH] ref(`otelify`): add method for enable distribution tracing records --- cmd/cli/proxy.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/cli/proxy.go b/cmd/cli/proxy.go index 28ca513..e54c096 100644 --- a/cmd/cli/proxy.go +++ b/cmd/cli/proxy.go @@ -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" @@ -9,6 +11,7 @@ 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" ) @@ -16,6 +19,20 @@ 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()) @@ -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), @@ -59,7 +76,6 @@ var proxyCmd = &cobra.Command{ } for _, endpoints := range configFromYaml.ProxyGateway.EnpointsProxy { - h.ProxyGateway(endpoints, engine, key, securityType) } @@ -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)