-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_test.go
85 lines (82 loc) · 1.97 KB
/
echo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package echox
import (
"context"
"github.com/TiyaAnlite/FocotServicesCommon/envx"
"github.com/TiyaAnlite/FocotServicesCommon/utils"
"github.com/labstack/echo/v4"
"github.com/uptrace/uptrace-go/uptrace"
"go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
"go.opentelemetry.io/otel/trace"
"os"
"os/signal"
"testing"
"time"
)
func TestOpel(t *testing.T) {
ctx := context.Background()
opelDSN := os.Getenv("TRACE_DSN")
if opelDSN == "" {
t.Error("openDSN not set")
t.FailNow()
}
uptrace.ConfigureOpentelemetry(
uptrace.WithDSN(opelDSN),
uptrace.WithServiceName("EchoHelper"),
uptrace.WithServiceVersion("test"),
uptrace.WithDeploymentEnvironment("test"),
)
defer uptrace.Shutdown(ctx)
traceFunc := func(c echo.Context) error {
var ch trace.Span
_, ch = RootTracer(c, "processing")
t.Logf("do something...")
time.Sleep(time.Second)
ch.End()
_, ch = RootTracer(c, "processing2")
time.Sleep(time.Millisecond * 500)
ch.End()
t.Logf("ok")
return NormalEmptyResponse(c)
}
go Run(&EchoConfig{
Port: 8080,
}, func(e *echo.Echo) {
e.Use(otelecho.Middleware("EchoHelperTest"))
e.Any("/", traceFunc)
})
utils.Wait4CtrlC()
}
func TestEchoServer(t *testing.T) {
ctx := context.Background()
opelDSN := os.Getenv("TRACE_DSN")
if opelDSN == "" {
t.Error("openDSN not set")
t.FailNow()
}
uptrace.ConfigureOpentelemetry(
uptrace.WithDSN(opelDSN),
uptrace.WithServiceName("EchoHelper"),
uptrace.WithServiceVersion("test"),
uptrace.WithDeploymentEnvironment("test"),
)
defer uptrace.Shutdown(ctx)
cfg := &EchoConfig{
Port: 8080,
UseHealthCheck: false,
TelemetryHostName: "EchoHelperTest",
}
envx.MustLoadEnv(cfg)
go Run(cfg, func(e *echo.Echo) {
e.Any("/", func(c echo.Context) error {
return NormalResponse(c, "ok")
})
})
ctrlc := make(chan os.Signal, 1)
signal.Notify(ctrlc, os.Interrupt)
go func() {
time.Sleep(time.Second * 5)
ctrlc <- os.Interrupt
}()
<-ctrlc
Shutdown(cfg)
}