当前位置:网站首页>Gin framework: adding tracing Middleware
Gin framework: adding tracing Middleware
2022-06-24 01:53:00 【Trespass 】
Introduce
Through a complete example , Based on Gin 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 Gin 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-gin
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:Gin The service will be delivered locally jaeger agent send data .
---
gin:
- 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-gin/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/gin-gonic/gin v1.7.2 github.com/rookie-ninja/rk-boot v1.4.0 github.com/rookie-ninja/rk-gin v1.2.12 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
---
gin:
- 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
---
gin:
- 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 |
|---|---|---|---|
gin.interceptors.tracingTelemetry.enabled | Start the call chain interceptor | boolean | false |
gin.interceptors.tracingTelemetry.exporter.file.enabled | Start file output | boolean | false |
gin.interceptors.tracingTelemetry.exporter.file.outputPath | Output file path | string | stdout |
gin.interceptors.tracingTelemetry.exporter.jaeger.agent.enabled | jaeger agent Output as data | boolean | false |
gin.interceptors.tracingTelemetry.exporter.jaeger.agent.host | jaeger agent Address | string | localhost |
gin.interceptors.tracingTelemetry.exporter.jaeger.agent.port | jaeger agent port | int | 6831 |
gin.interceptors.tracingTelemetry.exporter.jaeger.collector.enabled | jaeger collector Output as data | boolean | false |
gin.interceptors.tracingTelemetry.exporter.jaeger.collector.endpoint | jaeger collector Address | string | http://localhost:16368/api/trace |
gin.interceptors.tracingTelemetry.exporter.jaeger.collector.username | jaeger collector user name | string | "" |
gin.interceptors.tracingTelemetry.exporter.jaeger.collector.password | jaeger collector password | string | "" |
边栏推荐
- Tcapulusdb Jun · industry news collection
- Thorough and thorough analysis of factory method mode
- Query report of each mic quality inspection result on SAP QM inspection lot?
- Six steps from strategy to product - johncutlefish
- 8、 Pipeline pipeline construction project
- [technology for grass planting] lightweight 248 helps individual developers go to the cloud
- How to make a ECS into a fortress machine how long does it take to build a fortress machine
- What is function point analysis - FPA
- Smart supply chain collaborative management platform for the home industry integrated upstream and downstream collaboration of the supply chain to improve management efficiency
- An error is reported when easynvr uploads the SSL certificate: the network request fails. How to handle it?
猜你喜欢

Stm32g474 infrared receiving based on irtim peripherals
![[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)
![[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)

layer 3 switch

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

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

I, a 27 year old female programmer, feel that life is meaningless, not counting the accumulation fund deposit of 430000
随机推荐
[read together] Web penetration attack and defense practice (I)
Why use CDN content distribution network?
Global and Chinese dealox industry development status and demand trend forecast report 2022-2028
How to restart the server through the fortress machine how to log in to the fortress machine
How to use the speech synthesis assistant? Does speech synthesis cost money?
In only three steps, this large manufacturing enterprise has achieved full operational improvement with data
Kubesphere upgrade & enable plug-ins after installation
[JS reverse hundred examples] md5+aes encryption analysis of an easy payment password
Smart supply chain collaborative management platform for the home industry integrated upstream and downstream collaboration of the supply chain to improve management efficiency
Can the fortress machine connect to the ECS? What are the reasons why the fortress cannot connect to the ECS?
Clubhouse online supports replay function; Webobs live streaming tools are going to be popular |w
[dry goods] four tools linkage of automated batch hole digging process
Analysis of ESIM short text matching model
Talk about 15 tips of SQL optimization
How does Huawei weautomate RPA achieve the natural growth of government enterprise automation?
Tencent Conference - black screen analysis
What is "data" in data analysis- Cassie Kozyrkov
2、 Shell position variable
3、 Shell variable substring
The core battlefield of China US AI arms race: trillion level pre training model