Skip to content

Commit

Permalink
move dd tracer start back to main
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiidb committed Jul 20, 2023
1 parent f6b8185 commit 8a18883
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 0 additions & 8 deletions init_echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/rs/zerolog"
"github.com/ziflex/lecho/v3"
"golang.org/x/time/rate"
ddEcho "gopkg.in/DataDog/dd-trace-go.v1/contrib/labstack/echo.v4"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func initEcho(c *service.Config, logger *lecho.Logger) (e *echo.Echo) {
Expand All @@ -32,12 +30,6 @@ func initEcho(c *service.Config, logger *lecho.Logger) (e *echo.Echo) {
e.HTTPErrorHandler = responses.HTTPErrorHandler
e.Validator = &lib.CustomValidator{Validator: validator.New()}

//if Datadog is configured, add datadog middleware
if c.DatadogAgentUrl != "" {
tracer.Start(tracer.WithAgentAddr(c.DatadogAgentUrl))
defer tracer.Stop()
e.Use(ddEcho.Middleware(ddEcho.WithServiceName("lndhub.go")))
}
e.Use(middleware.Recover())
e.Use(middleware.BodyLimit("250K"))
// set the default rate limit defining the overal max requests/second
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"time"

"github.com/getAlby/lndhub.go/rabbitmq"
ddEcho "gopkg.in/DataDog/dd-trace-go.v1/contrib/labstack/echo.v4"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

"github.com/getAlby/lndhub.go/db"
"github.com/getAlby/lndhub.go/db/migrations"
Expand Down Expand Up @@ -142,6 +144,13 @@ func main() {

//init echo server
e := initEcho(c, logger)
//if Datadog is configured, add datadog middleware
if c.DatadogAgentUrl != "" {
tracer.Start(tracer.WithAgentAddr(c.DatadogAgentUrl))
defer tracer.Stop()
e.Use(ddEcho.Middleware(ddEcho.WithServiceName("lndhub.go")))
}

logMw := createLoggingMiddleware(logger)
// strict rate limit for requests for sending payments
strictRateLimitMiddleware := createRateLimitMiddleware(c.StrictRateLimit, c.BurstRateLimit)
Expand Down

0 comments on commit 8a18883

Please sign in to comment.