Golang Application Tracing in Instana

The approach for the cloud age

Image by Andrew Martin from Pixabay

The init() function

import (
...
instana "github.com/instana/go-sensor"
"github.com/opentracing/opentracing-go"
...
)
var iSensor *instana.Sensorfunc init() {
instana.InitSensor(&instana.Options{
Service: "myapp",
LogLevel: instana.Debug,
EnableAutoProfile: true})
iSensor = instana.NewSensor("myapp-tracing")
}
func greet(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello")
}
http.HandleFunc("/", instana.TracingHandlerFunc(iSensor, "/", greet)
)

Enable Function Level Tracing

func myhandler(w http.ResponseWriter, r *http.Request) {
var span opentracing.Span
if parent, ok := instana.SpanFromContext(r.Context()); ok {
span = parent.Tracer().StartSpan("writeHandler", opentracing.ChildOf(parent.Context()))
defer span.Finish()
}
...
span.SetTag("count in million", num)
...
if parent, ok := instana.SpanFromContext(r.Context()); ok {
span = parent.Tracer().StartSpan("writeHandler", opentracing.ChildOf(parent.Context()))
defer span.Finish()
}

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: image-registry.openshift-image-registry.svc:5000/go-trace/myapp:v1.0
ports:
- containerPort: 8080
env:
- name: INSTANA_AGENT_HOST
valueFrom:
fieldRef:
fieldPath: status.hostIP

Cloud explorer