当前位置:网站首页>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 | "" |
边栏推荐
- Devops learning notes (II)
- Tcapulusdb Jun · industry news collection (November 22)
- In only three steps, this large manufacturing enterprise has achieved full operational improvement with data
- Line/kotlin jdsl: kotlin DSL for JPA criteria API
- Detailed explanation of SSH tunnel and stable intranet penetration using autossh
- Echo framework: implementing service end flow limiting Middleware
- Based on ARM embedded real-time streaming media service development and deployment, easygbs supports arm64 architecture
- "Cross border" layout photovoltaic circle Green Island wind invested 4.6 million to layout distributed photovoltaic power generation
- Thorough and thorough analysis of factory method mode
- Custom form dynamic form form designer process engine design scheme
猜你喜欢
![[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)

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

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

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)

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

layer 3 switch
随机推荐
An error is reported when easynvr uploads the SSL certificate: the network request fails. How to handle it?
Collation of commonly used glusterfs commands
SMS marketing is the key to retain customers
Login server in VNC mode
Practical case - Tencent security hosting service MSS helped "zero accident" during the period of digital Guangdong re insurance!
Comparison between rule engine and ML model - xlaszlo
LeetCode 120. Triangle minimum path sum
Tcapulusdb Jun · industry news collection
How to make a ECS into a fortress machine how long does it take to build a fortress machine
What is "data" in data analysis- Cassie Kozyrkov
LeetCode 931. Descent path min sum
SAP mm Migo 411k error - correct the customizing settings for the unique
Summary of various situations in which easycvr cannot use voice intercom function
[technical grass planting] look what I did with my server!
SAP mm maintains inter company sto error -no delivery type defined for supplying
[actual combat] how to realize people nearby through PostGIS
[tcapulusdb knowledge base] common problems of tcapulusdb local deployment
Tencent Conference - black screen analysis
Tencent music, slow down?
3、 Shell variable substring