amazon-web-services - aws xray 和 golang http 调用
问题描述
我正在尝试在我的 go 应用程序上使用 awx xray 来对服务进行 http 调用。我只是跟着这个,不确定我是否错过了什么,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 射线部分,一切似乎都正常工作,为什么我没有收到任何数据或错误?
解决方案
在 Lambda 场景中,Lambda 负责创建 Segments,AWS X-Ray Golang SDK 只创建 Subsegments 然后发出它们。根据您的代码片段,您没有找到使用 X-Ray Go SDK API 检测您的应用程序以在 Lambda 函数中生成子段的代码。在这里,我附上了一个链接,您可以在其中找到如何检测您的应用程序:lambdadocs
推荐阅读
- javascript - 为什么我要使用 RxJS 的 interval() 或 timer() 轮询而不是 window.setInterval()?
- batch-file - 如何将命令更改为您自己的命令
- javascript - Bootstrap Slides 在使用 Angular 6 的多项目轮播时滞后
- php - 如何上传管理域中的图像,并将它们保存在另一个域(博客)的图像文件夹中?
- javascript - 映射到 json 并使用 javascript 转换为 html 时得到额外的逗号
- angular - 如何在 Angular 中访问这些信息?
- vba - 使用 Find 和 Offset 检查两个选项卡中的记录
- angular - 为什么我在 AngularJS 中的路由不起作用?
- java - 无法执行构建:LocationAwareException:任务“:app:processDebugGoogleServices”执行失败
- c# - 通过邮件发送超链接会删除超链接