thestrukture/IDE

View on GitHub
api/tracer/appdash.go

Summary

Maintainability
A
0 mins
Test Coverage
// File generated by Gopher Sauce
// DO NOT EDIT!!
package tracer

import (
    "fmt"
    "log"
    "net"
    "net/http"
    "net/url"

    "github.com/fatih/color"
    "github.com/opentracing/opentracing-go"
    "sourcegraph.com/sourcegraph/appdash"
    appdashot "sourcegraph.com/sourcegraph/appdash/opentracing"
    "sourcegraph.com/sourcegraph/appdash/traceapp"
)

func LoadTraceServer() {
    store := appdash.NewMemoryStore()

    // Listen on any available TCP port locally.
    l, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
    if err != nil {
        log.Fatal(err)
    }
    collectorPort := l.Addr().(*net.TCPAddr).Port

    // Start an Appdash collection server that will listen for spans and
    // annotations and add them to the local collector (stored in-memory).
    cs := appdash.NewServer(l, appdash.NewLocalCollector(store))
    go cs.Start()

    // Print the URL at which the web UI will be running.
    appdashPort := 8700
    appdashURLStr := fmt.Sprintf("http://localhost:%d", appdashPort)
    appdashURL, err := url.Parse(appdashURLStr)
    if err != nil {
        log.Fatalf("Error parsing %s: %s", appdashURLStr, err)
    }
    color.Red("✅ Important!")
    log.Println("To see your traces, go to ", appdashURL)

    // Start the web UI in a separate goroutine.
    tapp, err := traceapp.New(nil, appdashURL)
    if err != nil {
        log.Fatal(err)
    }
    tapp.Store = store
    tapp.Queryer = store
    go func() {
        log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appdashPort), tapp))
    }()

    tracer := appdashot.NewTracer(appdash.NewRemoteCollector(fmt.Sprintf(":%d", collectorPort)))
    opentracing.InitGlobalTracer(tracer)
}