1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-28 21:09:17 +02:00
opentelemetry-go/example/grpc/client/main.go
David Montoya 77543cd80e Unary gRPC tracing example (#351)
* add grpc example

* update example guide

* decouple trace provider initialization

* add source license

* update api references
2019-11-26 16:14:09 -08:00

55 lines
1.5 KiB
Go

// 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)
}
defer conn.Close()
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",
)
context := metadata.NewOutgoingContext(context.Background(), md)
response, err := c.SayHello(context, &api.HelloRequest{Greeting: "World"})
if err != nil {
log.Fatalf("Error when calling SayHello: %s", err)
}
log.Printf("Response from server: %s", response.Reply)
}