Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git committed Mar 27, 2024
1 parent 313d9d1 commit 34955c3
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions contrib/trace/otlpgrpc/otlpgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func Init(serviceName, endpoint, traceToken string) (func(), error) {
return func() {
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
if err = tracerProvider.Shutdown(ctx); err != nil {
g.Log().Errorf(ctx, "Shutdown tracerProvider failed err:%+v", err)
}
if err = traceExp.Shutdown(ctx); err != nil {
g.Log().Errorf(ctx, "Shutdown traceExp failed err:%+v", err)
otel.Handle(err)
Expand Down
3 changes: 3 additions & 0 deletions contrib/trace/otlphttp/otlphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func Init(serviceName, endpoint, path string) (func(), error) {
return func() {
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
if err = tracerProvider.Shutdown(ctx); err != nil {
g.Log().Errorf(ctx, "Shutdown tracerProvider failed err:%+v", err)
}
if err = traceExp.Shutdown(ctx); err != nil {
g.Log().Errorf(ctx, "Shutdown traceExp failed err:%+v", err)
otel.Handle(err)
Expand Down
5 changes: 5 additions & 0 deletions example/trace/grpc-with-db/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package main

import (
"time"

"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/contrib/trace/otlpgrpc/v2"
Expand Down Expand Up @@ -81,4 +83,7 @@ func StartRequests() {
return
}
g.Log().Info(ctx, "delete id:", -1)

// Leave a little time to complete the report.
time.Sleep(3 * time.Second)
}
5 changes: 5 additions & 0 deletions example/trace/http-with-db/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package main

import (
"time"

"github.com/gogf/gf/contrib/trace/otlphttp/v2"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
Expand Down Expand Up @@ -81,4 +83,7 @@ func StartRequests() {
panic(err)
}
g.Log().Info(ctx, "delete result:", deleteRes)

// Leave a little time to complete the report.
time.Sleep(3 * time.Second)
}
5 changes: 5 additions & 0 deletions example/trace/http/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package main

import (
"time"

"github.com/gogf/gf/contrib/trace/otlphttp/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/gtrace"
Expand Down Expand Up @@ -39,4 +41,7 @@ func StartRequests() {

content := g.Client().GetContent(ctx, "http://127.0.0.1:8199/hello")
g.Log().Print(ctx, content)

// Leave a little time to complete the report.
time.Sleep(3 * time.Second)
}
9 changes: 7 additions & 2 deletions example/trace/inprocess/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

const (
serviceName = "inprocess"
endpoint = "localhost:6831"
path = "adapt_******_******/api/otlp/traces"
endpoint = "192.168.10.42:4318"
path = "/v1/traces"
)

func main() {
Expand All @@ -40,6 +40,11 @@ func main() {
// Trace 2.
user100 := GetUser(ctx, 100)
g.Dump(user100)

// Leave a little time to complete the report.
span.End()
// time.Sleep(6 * time.Second)
shutdown()
}

// GetUser retrieves and returns hard coded user data for demonstration.
Expand Down
5 changes: 5 additions & 0 deletions example/trace/otlp/grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package main

import (
"time"

"github.com/gogf/gf/contrib/trace/otlpgrpc/v2"

"github.com/gogf/gf/v2/frame/g"
Expand All @@ -29,6 +31,9 @@ func main() {
defer shutdown()

StartRequests()

// Leave a little time to complete the report.
time.Sleep(3 * time.Second)
}

// StartRequests starts requests.
Expand Down
5 changes: 5 additions & 0 deletions example/trace/otlp/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package main

import (
"time"

"github.com/gogf/gf/contrib/trace/otlphttp/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/gtrace"
Expand All @@ -28,6 +30,9 @@ func main() {
defer shutdown()

StartRequests()

// Leave a little time to complete the report.
time.Sleep(3 * time.Second)
}

// StartRequests starts requests.
Expand Down

0 comments on commit 34955c3

Please sign in to comment.