Go and DataDog Part 1 : Simple Go HTTP Monitoring with DataDog

Today im trying to share a simple GoLang HTTP monitoring using DataDog APM. On this example im using trial version of DataDog for testing purpose, but on production im using enterprise version. Shouldnt be so much difference between those two.

Okay, after we register on DataDog website, we can start with installing DataDog agent on our server.


Im using Ubuntu Server, so my installation command is like below,

DD_API_KEY=<your datadog api key> bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/datadog-agent/master/cmd/agent/install_script.sh)"

After our installation runs well, we need to configure APM first

vi /etc/datadog-agent/datadog.yaml

with below configuration,

   enabled: true

we can start our Datadog-agent using below command,

sudo datadog-agent start

and check its status using

sudo datadog-agent status

Next is writing our code, im using Go’s simple htttp package

package main

import (
    httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http" // In order to instrument the http library

func main() {
     defer tracer.Stop()
     mux := httptrace.NewServeMux() // init the http tracer
     mux.HandleFunc("/", handle) // use the tracer to handle the urls     
     log.Println("Listening on port 8099")	 
     log.Fatal(http.ListenAndServe(":8099", mux)) // use the tracer to start the http server

func handle(w http.ResponseWriter, r *http.Request) {     
     fmt.Fprint(w, "Hello world!")

we can simulate http request to our server with a simple command,

curl -v

We can see the result on our Datadog dashboard below,

and the detailed view for each url,

Hopefully it helps :-D


No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked

:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)