-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.go
More file actions
43 lines (35 loc) · 816 Bytes
/
server.go
File metadata and controls
43 lines (35 loc) · 816 Bytes
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
package main
import (
"net/http"
"os"
apmecho "github.com/flachnetz/echo-apm-middleware"
"github.com/labstack/echo/v4"
"github.com/opentracing-contrib/echo/examples/tracer"
"github.com/opentracing/opentracing-go"
)
const (
DefaultComponentName = "echo-demo"
)
func main() {
flag := os.Getenv("JAEGER_ENABLED")
if flag == "true" {
// 1. init tracer
tracer, closer := tracer.Init(DefaultComponentName)
if closer != nil {
defer closer.Close()
}
// 2. ste the global tracer
if tracer != nil {
opentracing.SetGlobalTracer(tracer)
}
}
e := echo.New()
if flag == "true" {
// 3. use the middleware
e.Use(apmecho.Middleware(DefaultComponentName))
}
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
}