当前位置:网站首页>Echo framework: add tracing Middleware
Echo framework: add tracing Middleware
2022-06-24 01:53:00 【Trespass 】
Introduce
Through a complete example , Based on Echo Add a call chain to the microservice of the framework (Tracing) middleware .
What is a call chain (Tracing) middleware ?
Call chain (Tracing) Middleware will be used for every API Request record Tracing data , Users can use something like Jaeger Tool View .
We will use rk-boot To start up Echo Microservices of the framework .
Please visit the following address for a complete tutorial :https://rkdocs.netlify.app/cn
install
go get github.com/rookie-ninja/rk-boot go get github.com/rookie-ninja/rk-echo
Quick start
rk-boot By default OpenTelemetry-CNCF To deal with it Tracing.
1. establish boot.yaml
In order to verify , We launched the following options :
- commonService:commonService It contains a series of general API. details
- jaeger exporter:Echo The service will be delivered locally jaeger agent send data .
---
echo:
- name: greeter # Required
port: 8080 # Required
enabled: true # Required
commonService:
enabled: true # Optional, default: false
interceptors:
tracingTelemetry:
enabled: true # Optional, Enable tracing interceptor/middleware
exporter:
jaeger:
agent:
enabled: true # Optional, Export to jaeger agent2. establish main.go
package main
import (
"context"
"github.com/rookie-ninja/rk-boot"
_ "github.com/rookie-ninja/rk-echo/boot"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}3. Folder structure
$ tree . ├── boot.yaml ├── go.mod ├── go.sum └── main.go 0 directories, 4 files
4. Local boot jaeger
$ docker run -d --name jaeger \
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14268:14268 \
-p 14250:14250 \
-p 9411:9411 \
jaegertracing/all-in-one:1.235. start-up main.go
$ go run main.go
6. verification
- Send a request
$ curl -X GET localhost:8080/rk/v1/healthy
{"healthy":true}- visit jaeger Home page : http://localhost:16686/
rk-boot Will use go.mod In the document module Suffix to name Service. give an example : If your go.mod The contents of the document are as follows , be Service The name is rk-demo
module github.com/rookie-ninja/rk-demo go 1.16 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 github.com/labstack/echo/v4 v4.6.1 github.com/rookie-ninja/rk-boot v1.4.0 github.com/rookie-ninja/rk-echo v0.0.5 github.com/swaggo/swag v1.7.0 )
Output to Stdout
It can be modified by boot.yaml File to modify the output path , such as STDOUT.
- boot.yaml
---
echo:
- name: greeter # Required
port: 8080 # Required
enabled: true # Required
commonService:
enabled: true # Optional, default: false
interceptors:
tracingTelemetry:
enabled: true # Optional, Enable tracing interceptor/middleware
exporter:
file:
enabled: true
outputPath: "stdout" # Optional, Output to stdoutoutput to a file
It can be modified by boot.yaml File to save Tracing Information to file .
- boot.yaml
---
echo:
- name: greeter # Required
port: 8080 # Required
enabled: true # Required
commonService:
enabled: true # Optional, default: false
interceptors:
tracingTelemetry:
enabled: true # Optional, Enable tracing interceptor/middleware
exporter:
file:
enabled: true
outputPath: "logs/tracing.log" # Optional, Log to filesOptions
name | describe | type | The default value is |
|---|---|---|---|
echo.interceptors.tracingTelemetry.enabled | Start the call chain interceptor | boolean | false |
echo.interceptors.tracingTelemetry.exporter.file.enabled | Start file output | boolean | false |
echo.interceptors.tracingTelemetry.exporter.file.outputPath | Output file path | string | stdout |
echo.interceptors.tracingTelemetry.exporter.jaeger.agent.enabled | jaeger agent Output as data | boolean | false |
echo.interceptors.tracingTelemetry.exporter.jaeger.agent.host | jaeger agent Address | string | localhost |
echo.interceptors.tracingTelemetry.exporter.jaeger.agent.port | jaeger agent port | int | 6831 |
echo.interceptors.tracingTelemetry.exporter.jaeger.collector.enabled | jaeger collector Output as data | boolean | false |
echo.interceptors.tracingTelemetry.exporter.jaeger.collector.endpoint | jaeger collector Address | string | http://localhost:16368/api/trace |
echo.interceptors.tracingTelemetry.exporter.jaeger.collector.username | jaeger collector user name | string | "" |
echo.interceptors.tracingTelemetry.exporter.jaeger.collector.password | jaeger collector password | string | "" |
边栏推荐
- Logistics industry supplier collaborative management platform supplier life cycle management to optimize logistics costs
- Make standardized tools in the cloud native era to realize efficient cloud R & D workflow
- How to generate EAN13 serial number barcode
- An error is reported when easynvr uploads the SSL certificate: the network request fails. How to handle it?
- [dry goods] configure failover active/acitve in transparent mode on Cisco ASA firewall
- [combat power upgrade] Tencent cloud's first arm architecture instance was launched! Experience the new architecture computing power!
- [SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)
- Horizontal movement of Intranet penetration -- password spray attack from domain to domain
- How to set up AI speech synthesis? What is the function of speech synthesis?
- How does easynvr set the video recording to be saved for more than 30 days?
猜你喜欢
![[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)](/img/c8/f6c2a62b8ab8fa88bd2b3d8f35f592.jpg)
[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)

It's too difficult for me. Ali has had 7 rounds of interviews (5 years of experience and won the offer of P7 post)

Review of AI hotspots this week: the Gan compression method consumes less than 1/9 of the computing power, and the open source generator turns your photos into hand drawn photos

I, a 27 year old female programmer, feel that life is meaningless, not counting the accumulation fund deposit of 430000

Stm32g474 infrared receiving based on irtim peripherals

layer 3 switch
![[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)](/img/b5/a8c4bbaf868dd20b7dc9449d2a4378.jpg)
[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)
随机推荐
Build a smart pole visual intercom system through an intelligent gateway
CLB O & M & operation best practices - big insight into access logs
Global and Chinese alumina nanoparticle market scale and Development Trend Outlook report 2022-2028
5、 Build freestyle projects and related knowledge
Query report of each mic quality inspection result on SAP QM inspection lot?
Typescript is a weak type
What does fortress server mean? What are the benefits of Fortress server installation
Review of AI hotspots this week: the Gan compression method consumes less than 1/9 of the computing power, and the open source generator turns your photos into hand drawn photos
Nature Reviews Neuroscience: cognitive and behavioral flexibility - neural mechanisms and clinical considerations
LeetCode 1289. Descent path min and II
[guide to cloud first] point north before tdsql elite challenge
Railway patrol system - Railway Intelligent Patrol communication system
Typescript type system
Easynvr background channel list timing request touchstreamclient interface optimization
[untitled]
What are the categories of code signing certificates? What are the differences between different types of certificates?
[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)
2、 Shell position variable
[dry goods] four tools linkage of automated batch hole digging process
Troubleshooting and repair of easygbs docking with universal video equipment to broadcast message 487