2

I have a small proof-of-concept project to add DataDog APM/tracing capabilities to a gofiber (https://github.com/gofiber) web app. The app is up and running in an EKS environment which already has strong DataDog integration (agent, APM enabled for entire cluster, etc).

I am still learning the ropes with gofiber. My question is, what is the simplest and most efficient way to add the tracer and profile to my project?

DataDog is recommending these two packages:

go get gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer
go get gopkg.in/DataDog/dd-trace-go.v1/profiler

Currently I have a simple main.go file serving "Hello World" at /, using one of the gofiber recipes.

Can I add the tracer and profile as separate functions in the same file or should I have separate files for these in my project?

Definitely trying to avoid running an entirely separate container in my pod for this tracing capability. Thanks for any advice or suggestions.

Robert Campbell
  • 303
  • 3
  • 12

1 Answers1

0

You need to add datadog tracer in main.go and as fiber middleware, to trace fiber framework requests. Refer to below examples to enable datadog tracing for fiber apps.

main.go example

package main

import (
        
    "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
    
        tracer.Start(tracer.WithAgentAddr("localhost:8200")
        tracer.WithService("APP NAME")
        tracer.WithEnv("TRACE ENV")
        defer tracer.Stop()
}

Fiber middleware example

import (
        "github.com/gofiber/fiber/v2"

        fibertrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gofiber/fiber.v2"
    )
    
    func main() {
        
            app := fiber.New()
            app.Use(fibertrace.Middleware(fibertrace.WithServiceName("APP Name value")))
    }
Abhinav Garg
  • 1,642
  • 3
  • 22
  • 41