frontend/checkoutservice: add tracing
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
89618dbeb6
commit
555c8a4c05
4 changed files with 39 additions and 2 deletions
|
@ -7,7 +7,9 @@ RUN go get -d github.com/google/uuid \
|
||||||
google.golang.org/grpc \
|
google.golang.org/grpc \
|
||||||
google.golang.org/grpc/codes \
|
google.golang.org/grpc/codes \
|
||||||
google.golang.org/grpc/status \
|
google.golang.org/grpc/status \
|
||||||
go.opencensus.io/plugin/ocgrpc
|
go.opencensus.io/plugin/ocgrpc \
|
||||||
|
go.opencensus.io/exporter/stackdriver \
|
||||||
|
go.opencensus.io/trace
|
||||||
COPY . .
|
COPY . .
|
||||||
# get remaining dependencies
|
# get remaining dependencies
|
||||||
RUN go get -d ./...
|
RUN go get -d ./...
|
||||||
|
|
|
@ -8,7 +8,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"go.opencensus.io/exporter/stackdriver"
|
||||||
"go.opencensus.io/plugin/ocgrpc"
|
"go.opencensus.io/plugin/ocgrpc"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
@ -37,6 +39,8 @@ func main() {
|
||||||
port = os.Getenv("PORT")
|
port = os.Getenv("PORT")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initTracing()
|
||||||
|
|
||||||
svc := new(checkoutService)
|
svc := new(checkoutService)
|
||||||
mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
|
mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
|
||||||
mustMapEnv(&svc.productCatalogSvcAddr, "PRODUCT_CATALOG_SERVICE_ADDR")
|
mustMapEnv(&svc.productCatalogSvcAddr, "PRODUCT_CATALOG_SERVICE_ADDR")
|
||||||
|
@ -57,6 +61,18 @@ func main() {
|
||||||
log.Fatal(srv.Serve(lis))
|
log.Fatal(srv.Serve(lis))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initTracing() {
|
||||||
|
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to initialize stackdriver exporter: %+v", err)
|
||||||
|
log.Println("skipping uploading traces to stackdriver")
|
||||||
|
} else {
|
||||||
|
trace.RegisterExporter(exporter)
|
||||||
|
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
|
||||||
|
log.Println("registered stackdriver tracing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func mustMapEnv(target *string, envKey string) {
|
func mustMapEnv(target *string, envKey string) {
|
||||||
v := os.Getenv(envKey)
|
v := os.Getenv(envKey)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
|
|
|
@ -11,7 +11,9 @@ RUN go get -d github.com/google/uuid \
|
||||||
google.golang.org/grpc/codes \
|
google.golang.org/grpc/codes \
|
||||||
google.golang.org/grpc/status \
|
google.golang.org/grpc/status \
|
||||||
go.opencensus.io/plugin/ochttp \
|
go.opencensus.io/plugin/ochttp \
|
||||||
go.opencensus.io/plugin/ochttp/propagation/b3
|
go.opencensus.io/plugin/ochttp/propagation/b3 \
|
||||||
|
go.opencensus.io/exporter/stackdriver \
|
||||||
|
go.opencensus.io/trace
|
||||||
|
|
||||||
# copy go-only part of the build
|
# copy go-only part of the build
|
||||||
COPY *.go ./
|
COPY *.go ./
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
@ -10,9 +11,11 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.opencensus.io/exporter/stackdriver"
|
||||||
"go.opencensus.io/plugin/ocgrpc"
|
"go.opencensus.io/plugin/ocgrpc"
|
||||||
"go.opencensus.io/plugin/ochttp"
|
"go.opencensus.io/plugin/ochttp"
|
||||||
"go.opencensus.io/plugin/ochttp/propagation/b3"
|
"go.opencensus.io/plugin/ochttp/propagation/b3"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,6 +67,8 @@ func main() {
|
||||||
log.Level = logrus.DebugLevel
|
log.Level = logrus.DebugLevel
|
||||||
log.Formatter = &logrus.TextFormatter{}
|
log.Formatter = &logrus.TextFormatter{}
|
||||||
|
|
||||||
|
initTracing()
|
||||||
|
|
||||||
srvPort := port
|
srvPort := port
|
||||||
if os.Getenv("PORT") != "" {
|
if os.Getenv("PORT") != "" {
|
||||||
srvPort = os.Getenv("PORT")
|
srvPort = os.Getenv("PORT")
|
||||||
|
@ -106,6 +111,18 @@ func main() {
|
||||||
log.Fatal(http.ListenAndServe(addr+":"+srvPort, handler))
|
log.Fatal(http.ListenAndServe(addr+":"+srvPort, handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initTracing() {
|
||||||
|
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to initialize stackdriver exporter: %+v", err)
|
||||||
|
log.Println("skipping uploading traces to stackdriver")
|
||||||
|
} else {
|
||||||
|
trace.RegisterExporter(exporter)
|
||||||
|
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
|
||||||
|
log.Println("registered stackdriver tracing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func mustMapEnv(target *string, envKey string) {
|
func mustMapEnv(target *string, envKey string) {
|
||||||
v := os.Getenv(envKey)
|
v := os.Getenv(envKey)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
|
|
Loading…
Reference in a new issue