Skip to content

ENGTAI-24429: Add more examples and fix gosec issues #251

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion examples/gin-server/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log"
"net/http"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -38,5 +39,8 @@ func main() {

r := setupRouter()
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
err := r.Run(":8080")
if err != nil {
log.Fatalf("gin server failed with error: %v", err)
}
}
16 changes: 11 additions & 5 deletions examples/grpc-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ import (
"github.com/hypertrace/goagent/instrumentation/hypertrace"
"github.com/hypertrace/goagent/instrumentation/hypertrace/google.golang.org/hypergrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

const (
address = "localhost:50051"
address = "localhost:50151"
defaultName = "world"
)

func main() {
cfg := config.Load()
cfg.ServiceName = config.String("grpc-client")
cfg.Reporting.Endpoint = config.String("localhost:5442")
cfg.Reporting.TraceReporterType = config.TraceReporterType_OTLP

flusher := hypertrace.Init(cfg)
defer flusher()

// Set up a connection to the server.
conn, err := grpc.Dial(
address,
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithUnaryInterceptor(hypergrpc.UnaryClientInterceptor()),
)
Expand All @@ -45,12 +48,15 @@ func main() {
if len(os.Args) > 1 {
name = os.Args[1]
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := client.SayHello(ctx, &pb.HelloRequest{Name: name})
if err != nil {
log.Fatalf("could not greet: %v", err)
log.Printf("could not greet: %v", err)
} else {
log.Printf("Greeting: %v", r.GetMessage())
}

log.Printf("Greeting: %v", r.GetMessage())
// some time to flush the spans
time.Sleep(2000 * time.Millisecond)
}
4 changes: 3 additions & 1 deletion examples/grpc-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
port = ":50051"
port = ":50151"
)

// server is used to implement helloworld.GreeterServer.
Expand All @@ -33,6 +33,8 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe
func main() {
cfg := config.Load()
cfg.ServiceName = config.String("grpc-server")
cfg.Reporting.Endpoint = config.String("localhost:5442")
cfg.Reporting.TraceReporterType = config.TraceReporterType_OTLP

flusher := hypertrace.Init(cfg)
defer flusher()
Expand Down
Loading
Loading