亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 AWS 控制臺中看不到手動創建的嵌套 AWS XRay 子分段

在 AWS 控制臺中看不到手動創建的嵌套 AWS XRay 子分段

Go
揚帆大魚 2023-02-28 20:17:20
我正在嘗試檢測用 Go 編寫的 Web 服務器,它提供 REST API,在 AWS ECS 上的容器中運行。我現在正在 VSCode 中的 Debug 中運行服務器,致力于概念證明,該證明將顯示不同端點的跟蹤,并將主要功能作為子段。我像這樣在我們的中間件中檢測了路由器:h = xray.Handler(xray.NewFixedSegmentNamer("myappname"), h)通過傳入請求上下文來檢測從各種處理函數進行的函數調用,然后:_, subSeg := xray.BeginSubsegment(ctx, "get-user")calculateUsefulInfo(ctx)subSeg.Close(nil)然后 calculateUsefulInfo() 函數可以調用其他函數,傳遞上下文 (ctx) 并在內部使用不同的子段名稱執行相同的操作(另一個 BeginSubsegment+subSeg.Close)。我正在運行 AWS XRay 守護程序,并具有適當的權限,我看到跟蹤顯示在 AWS 控制臺中。但是,我只看到一層嵌套。我在 AWS 中開啟了 100% 采樣。我在本地模式下運行 XRay 守護程序,開發級別的日志記錄。知道我在這里缺少什么嗎?
查看完整描述

1 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

父段存儲在上下文中,因此如果您只將頂級上下文傳遞給其他函數,它只會為該父段生成段。


要達到您想要的嵌套級別,您必須context使用xray.BeginSubsegment. 此上下文包含一個可以追溯到父級的新段。


嵌套段示例:


package main


import (

    "net"

    "net/http"

    "time"


    "github.com/aws/aws-xray-sdk-go/xray"

    "github.com/davecgh/go-spew/spew"

)


type ConsoleEmitter struct {

}


func (c *ConsoleEmitter) Emit(seg *xray.Segment) {

    spew.Dump(seg)

}


func (c *ConsoleEmitter) RefreshEmitterWithAddress(raddr *net.UDPAddr) {

    return

}


var _ xray.Emitter = (*ConsoleEmitter)(nil)


func init() {

    xray.Configure(xray.Config{

        DaemonAddr:     "127.0.0.1:2000", // default

        ServiceVersion: "1.2.3",

        // console emitter to view the hierarchy of the traces locally

        // without the xray daemon

        Emitter: &ConsoleEmitter{},

    })

}


func main() {

    http.Handle("/", xray.Handler(xray.NewFixedSegmentNamer("myApp"), http.HandlerFunc(top)))

    http.ListenAndServe(":7000", nil)

}


func top(w http.ResponseWriter, r *http.Request) {

    // use the context provided by xray for nested hierarchy

    ctx, subSeg := xray.BeginSubsegment(r.Context(), "top")

    _, childSeg := xray.BeginSubsegment(ctx, "top-sleep")

    time.Sleep(time.Millisecond * 50)

    childSeg.Close(nil)

    middle(w, r)

    subSeg.Close(nil)

}


func middle(w http.ResponseWriter, r *http.Request) {

    ctx, subSeg := xray.BeginSubsegment(r.Context(), "middle")

    _, childSeg := xray.BeginSubsegment(ctx, "middle-sleep")

    time.Sleep(time.Millisecond * 100)

    childSeg.Close(nil)

    bottom(w, r)

    subSeg.Close(nil)

}


func bottom(w http.ResponseWriter, r *http.Request) {

    _, subSeg := xray.BeginSubsegment(r.Context(), "bottom")

    w.Write([]byte("Hello!"))

    subSeg.Close(nil)

}



查看完整回答
反對 回復 2023-02-28
  • 1 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號