-
由 zhou liang 创作于b313386b
main.go 5.21 KiB
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"net"
"os"
"time"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/exporters/trace/jaeger"
grpcotel "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/shippingservice/genproto"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)
const (
defaultPort = "50051"
)
var log *logrus.Logger
func init() {
log = logrus.New()
log.Level = logrus.DebugLevel
log.Formatter = &logrus.JSONFormatter{
FieldMap: logrus.FieldMap{
logrus.FieldKeyTime: "timestamp",
logrus.FieldKeyLevel: "severity",
logrus.FieldKeyMsg: "message",
},
TimestampFormat: time.RFC3339Nano,
}
log.Out = os.Stdout
}
func main() {
if os.Getenv("DISABLE_TRACING") == "" {
log.Info("Tracing enabled.")
initTracer(log)
} else {
log.Info("Tracing disabled.")
}
port := defaultPort
if value, ok := os.LookupEnv("PORT"); ok {