Goland 清理缓存
GoLand 的缓存可能卡在旧状态,手动清理最彻底:
-
删除项目根目录下的
.idea文件夹(隐藏文件夹) -
(可选)清理全局缓存:
C:\Users\zhou\AppData\Local\JetBrains\GoLand\下的caches缓存目录
在go mod 模式下,ide泛红可以这样操作。
版本
bash
C:\Users\zhou>go version
go version go1.26.0 windows/amd64
C:\Users\zhou>
## 编译版本
go build -toolexec="D:\lib\skywalking-go\bin\skywalking-go-agent-0.4.0-windows-amd64 -config ./apm.yaml" -a -o app.exe .
apm.yaml
bash
agent:
service_name: devops-apm-dev
reporter:
grpc:
backend_service: apm.qq.com:11800
# 添加这一行,设为 info 级别
logging:
level: "info"
代码
bash
package main
import (
"fmt"
"log"
"net/http"
_ "github.com/apache/skywalking-go"
"github.com/apache/skywalking-go/toolkit/trace"
)
func main() {
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
// 1. 创建入口 Span(注意官方示例的写法)
trace.CreateEntrySpan("/ping", func(key string) (string, error) {
return r.Header.Get(key), nil
})
defer trace.StopSpan()
// 2. 设置 Span 信息
trace.SetOperationName("ping-handler")
trace.SetTag("http.method", r.Method)
trace.SetTag("http.url", r.URL.Path)
trace.SetTag("http.status_code", "200")
// 3. 业务逻辑
log.Println("收到 /ping 请求")
fmt.Fprintf(w, "pong")
})
log.Println("Server starting on :8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
debug启动
bash
set SW_AGENT_LOG_LEVEL=debug
set GODEBUG=http2debug=2
app.exe
循环请求
bash
for /l %i in (1,0,2) do (curl http://127.0.0.1:8080/ping & timeout /t 2 >nul)