Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate with OpenCensus and Ocagent exporter #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (

"golang.org/x/time/rate"

"contrib.go.opencensus.io/exporter/ocagent"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/trace"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
Expand Down Expand Up @@ -61,6 +65,29 @@ func main() {
log.Fatalf("bad value for rps limit: %s", rpsLimitStr)
}

// Register stats and trace exporters to export the collected data.
serviceName := os.Getenv("SERVICE_NAME")
if len(serviceName) == 0 {
serviceName = "go-app"
}

agentHostName := os.Getenv("OCAGENT_TRACE_EXPORTER_ENDPOINT")
if len(agentHostName) == 0 {
agentHostName = "localhost"
}

exporter, err := ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithServiceName(serviceName), ocagent.WithAddress(agentHostName))
if err != nil {
log.Printf("Failed to create the agent exporter: %v", err)
}

trace.RegisterExporter(exporter)

// Always trace for this demo. In a production application, you should
// configure this to a trace.ProbabilitySampler set at the desired
// probability.
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})

// ctr := &metrics{
// lastTime: time.Now(),
// }
Expand All @@ -73,7 +100,7 @@ func main() {
http.Handle("/metrics", promhttp.Handler())
http.Handle("/", instrumentHandler(throttledHandler))
// go rpsTelemetryCalculator(ctr)
log.Fatal(http.ListenAndServe(":8080", nil))
log.Fatal(http.ListenAndServe(":8080", &ochttp.Handler{Propagation: &tracecontext.HTTPFormat{}}))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this defined? When I try to compile this, it doesn't compile:

 ---> Running in 8f6a5333361a
# rpsdemo/cmd/app
cmd/app/app.go:92:71: undefined: tracecontext

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed one line in the import: "go.opencensus.io/plugin/ochttp/propagation/tracecontext"

}

func throttler(
Expand Down