Skip to content

Commit

Permalink
Add more env vars for stackdriver config
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Apr 23, 2019
1 parent cfed6c3 commit 9c6a9d6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"runtime/pprof"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -92,7 +93,14 @@ func main() {

func withStackdriverTracing(f func()) {
sd, err := stackdriver.NewExporter(stackdriver.Options{
Location: "anacrolix-mbp",
Location: func() string {
s, ok := os.LookupEnv("STACKDRIVER_LOCATION")
if ok {
return s
}
s, _ = os.Hostname()
return s
}(),
ProjectID: os.Getenv("GOOGLE_CLOUD_PROJECT"),
})
if err != nil {
Expand All @@ -102,9 +110,16 @@ func withStackdriverTracing(f func()) {
// It is imperative to invoke flush before your main function exits
defer sd.Flush()

trace.ApplyConfig(trace.Config{
DefaultSampler: trace.AlwaysSample(),
})
if s, ok := os.LookupEnv("OCTRACE_SAMPLE_PROB"); ok {
f, err := strconv.ParseFloat(s, 64)
if err != nil {
log.Errorf("parsing OC trace sample probability: %v", err)
} else {
trace.ApplyConfig(trace.Config{
DefaultSampler: trace.ProbabilitySampler(f),
})
}
}

// Register it as a trace exporter
trace.RegisterExporter(sd)
Expand Down

0 comments on commit 9c6a9d6

Please sign in to comment.