2019-11-27 02:14:09 +02:00
|
|
|
// Copyright 2019, OpenTelemetry Authors
|
|
|
|
//
|
|
|
|
// 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 (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/example/grpc/api"
|
|
|
|
"go.opentelemetry.io/otel/example/grpc/config"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/example/grpc/middleware/tracing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
config.Init()
|
|
|
|
|
|
|
|
var conn *grpc.ClientConn
|
|
|
|
conn, err := grpc.Dial(":7777", grpc.WithInsecure(), grpc.WithUnaryInterceptor(tracing.UnaryClientInterceptor))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %s", err)
|
|
|
|
}
|
2019-12-09 23:03:11 +02:00
|
|
|
defer func() { _ = conn.Close() }()
|
2019-11-27 02:14:09 +02:00
|
|
|
|
|
|
|
c := api.NewHelloServiceClient(conn)
|
|
|
|
|
|
|
|
md := metadata.Pairs(
|
|
|
|
"timestamp", time.Now().Format(time.StampNano),
|
|
|
|
"client-id", "web-api-client-us-east-1",
|
|
|
|
"user-id", "some-test-user-id",
|
|
|
|
)
|
2019-12-09 23:03:11 +02:00
|
|
|
ctx := metadata.NewOutgoingContext(context.Background(), md)
|
|
|
|
response, err := c.SayHello(ctx, &api.HelloRequest{Greeting: "World"})
|
2019-11-27 02:14:09 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error when calling SayHello: %s", err)
|
|
|
|
}
|
|
|
|
log.Printf("Response from server: %s", response.Reply)
|
|
|
|
}
|