AWS Xray和Golang http呼叫

时间:2018-08-27 02:49:09

标签: amazon-web-services go aws-xray

我正在尝试在进行http调用服务的go应用上使用awx xray。我只是遵循了这一步,不确定https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-go-httpclients.html

是否错过了什么

我这样拨打http:

payloadStr, _ := json.Marshal(dxPayload)

fmt.Println("size: ", int(unsafe.Sizeof(bytes.NewBuffer(payloadStr))))

clambda = &http.Client{}

//-------ADDED XRAY HERE-------//
xray.Client(clambda)

reqLambda, errReq := http.NewRequest("POST", lambdaurl, bytes.NewBuffer(payloadStr))
if errReq != nil {
    log.Fatal("Request Error: ", errReq)
    return
}

reqLambda.Header.Add("accept", "application/json;v=1")
reqLambda.Header.Add("cach-control", "no-cache")
reqLambda.Header.Add("content-type", "application/json")
reqLambda.Header.Add("authorization", "Bearer " + devexToken.AccessToken)

respLambda, errResp := clambda.Do(reqLambda)
if errResp != nil {
    log.Fatal("Status Response Error ", errResp)
    return
} else {

}

在我的main.go文件中,我在func init()

中有此文件
func init() {

    pConfig = createpConfig()

    //aws xray config
    ss, err := sampling.NewLocalizedStrategyFromFilePath("xray.json")

    if err != nil {
        panic(err)
    }
    xray.Configure(xray.Config{
        SamplingStrategy: ss,
    })
}

和我的xray.json配置如下:

{
  "version": 1,
  "rules": [
    {
      "description": "ehb",
      "service_name": "ehb-kafka-push",
      "http_method": "*",
      "url_path": "/private/api/calllambda/*",
      "fixed_target": 0,
      "rate": 0.85
    }
  ],
  "default": {
    "fixed_target": 1,
    "rate": 0.1
  }
}

现在,当我启动我的应用程序时...我的api调用通过了,但是在AWS xray和本地的xray守护程序中看不到任何东西,我只在日志中看到了这一点:

2018-08-26T18:45:04-07:00 [Info] Initializing AWS X-Ray daemon 2.1.3
2018-08-26T18:45:04-07:00 [Debug] Listening on UDP 127.0.0.1:2000
2018-08-26T18:45:04-07:00 [Info] Using buffer memory limit of 163 MB
2018-08-26T18:45:04-07:00 [Info] 2608 segment buffers allocated
2018-08-26T18:45:04-07:00 [Debug] Fetch region us-east-1 from commandline argument
2018-08-26T18:45:04-07:00 [Info] Using region: us-east-1
2018-08-26T18:45:04-07:00 [Debug] ARN of the AWS resource running the daemon: 
2018-08-26T18:45:04-07:00 [Debug] No Metadata set for telemetry records
2018-08-26T18:45:04-07:00 [Debug] Using Endpoint: https://xray.us-east-1.amazonaws.com
2018-08-26T18:45:04-07:00 [Debug] Telemetry initiated
2018-08-26T18:45:04-07:00 [Debug] Using Endpoint: https://xray.us-east-1.amazonaws.com
2018-08-26T18:45:04-07:00 [Debug] Batch size: 50
2018-08-26T18:46:04-07:00 [Debug] Skipped telemetry data as no segments found
2018-08-26T18:47:04-07:00 [Debug] Skipped telemetry data as no segments found
2018-08-26T18:48:04-07:00 [Debug] Skipped telemetry data as no segments found

我在这里想念什么?除了X射线部分,其他所有东西似乎都正常工作,为什么我没有收到任何数据或错误?

1 个答案:

答案 0 :(得分:1)

在Lambda场景中,Lambda负责创建细分,AWS X-Ray Golang SDK仅创建子细分,然后发出它们。根据您的代码片段,您找不到使用X-Ray Go SDK API来检测应用程序以在Lambda函数内部生成子段的代码。我在这里附加了一个链接,您可以在其中找到如何检测应用程序:lambdadocs