Skip to content

Instantly share code, notes, and snippets.

@Deleplace
Created November 26, 2018 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deleplace/f19963807758eed0e613938f7e2c49c8 to your computer and use it in GitHub Desktop.
Save Deleplace/f19963807758eed0e613938f7e2c49c8 to your computer and use it in GitHub Desktop.
Trace for AppEngine Standard with Go 1.9 (can't deploy as of 2018-11-26)
// Copyright 2018 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"net/http"
"contrib.go.opencensus.io/exporter/stackdriver"
"go.opencensus.io/trace"
"google.golang.org/appengine"
)
func main() {
sd, err := stackdriver.NewExporter(stackdriver.Options{
ProjectID: "spans-go19",
// MetricPrefix helps uniquely identify your metrics.
MetricPrefix: "demo-prefix",
})
if err != nil {
log.Fatalf("Failed to create the Stackdriver exporter: %v", err)
}
// It is imperative to invoke flush before your main function exits
defer sd.Flush()
// Register it as a trace exporter
trace.RegisterExporter(sd)
http.HandleFunc("/", handle)
appengine.Main()
}
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, VDE")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment