Skip to content

Commit 2848f3a

Browse files
authored
ENGTAI-24429: Add more examples and fix gosec issues (#251)
* ENGTAI-00000: Add more examples * fix some gosec issues * fix some more gosec issues
1 parent 95e853c commit 2848f3a

File tree

7 files changed

+321
-19
lines changed

7 files changed

+321
-19
lines changed

examples/gin-server/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"log"
45
"net/http"
56

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

3940
r := setupRouter()
4041
// Listen and Server in 0.0.0.0:8080
41-
r.Run(":8080")
42+
err := r.Run(":8080")
43+
if err != nil {
44+
log.Fatalf("gin server failed with error: %v", err)
45+
}
4246
}

examples/grpc-client/main.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,27 @@ import (
1313
"github.com/hypertrace/goagent/instrumentation/hypertrace"
1414
"github.com/hypertrace/goagent/instrumentation/hypertrace/google.golang.org/hypergrpc"
1515
"google.golang.org/grpc"
16+
"google.golang.org/grpc/credentials/insecure"
1617
)
1718

1819
const (
19-
address = "localhost:50051"
20+
address = "localhost:50151"
2021
defaultName = "world"
2122
)
2223

2324
func main() {
2425
cfg := config.Load()
2526
cfg.ServiceName = config.String("grpc-client")
27+
cfg.Reporting.Endpoint = config.String("localhost:5442")
28+
cfg.Reporting.TraceReporterType = config.TraceReporterType_OTLP
2629

2730
flusher := hypertrace.Init(cfg)
2831
defer flusher()
2932

3033
// Set up a connection to the server.
3134
conn, err := grpc.Dial(
3235
address,
33-
grpc.WithInsecure(),
36+
grpc.WithTransportCredentials(insecure.NewCredentials()),
3437
grpc.WithBlock(),
3538
grpc.WithUnaryInterceptor(hypergrpc.UnaryClientInterceptor()),
3639
)
@@ -45,12 +48,15 @@ func main() {
4548
if len(os.Args) > 1 {
4649
name = os.Args[1]
4750
}
51+
4852
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
4953
defer cancel()
5054
r, err := client.SayHello(ctx, &pb.HelloRequest{Name: name})
5155
if err != nil {
52-
log.Fatalf("could not greet: %v", err)
56+
log.Printf("could not greet: %v", err)
57+
} else {
58+
log.Printf("Greeting: %v", r.GetMessage())
5359
}
54-
55-
log.Printf("Greeting: %v", r.GetMessage())
60+
// some time to flush the spans
61+
time.Sleep(2000 * time.Millisecond)
5662
}

examples/grpc-server/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
const (
19-
port = ":50051"
19+
port = ":50151"
2020
)
2121

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

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

0 commit comments

Comments
 (0)