Skip to content

TencentCloud/tencentcloud-opentelemetry-demo-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APM Go demo for manual instrumentation

Configuration

在 APM 控制台获取 endpointtoken,在 pkg/trace/trace.go 中配置 endpointtokenservice.namehost.name

Usage

go run cmd/http/main.go

服务接口 http://127.0.0.1:9001,持续触发请求后,可以在 APM 控制台看到对应的服务,服务名为代码中设置的 service.name

Trace result

Troubleshooting

如果发现上报失败,可以从以下几个方面排查。

网络连通

外网上报务必使用 APM 控制台的外网地址。

以上报到广州地区,外网接入点为例,使用 telnet 测试是否能连接到 endpoint。

telnet ap-guangzhou.apm.tencentcs.com 4317

埋点问题

如果网络没有问题,优先排查是否埋点成功。可以设置 exporter 将链路信息打印到本地,如果没有任何输出,说明埋点失败,如果有输出,排查链路中是否有 service.nametokenhost.name 等关键配置信息。

exporter, err := stdouttrace.New(
    stdouttrace.WithWriter(os.Stdout),
    stdouttrace.WithPrettyPrint(),
)

链路信息输出示例:

{
        "Name": "set",
        "SpanContext": {
                "TraceID": "c16ef2bb3fd579cccca5502ed29aed46",
                "SpanID": "e111043ac76ddb6c",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "c16ef2bb3fd579cccca5502ed29aed46",
                "SpanID": "6aa0a1ab779661d8",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2025-05-22T16:42:21.131946+08:00",
        "EndTime": "2025-05-22T16:42:21.134424875+08:00",
        "Attributes": [
                {
                        "Key": "db.system",
                        "Value": {
                                "Type": "STRING",
                                "Value": "redis"
                        }
                },
                {
                        "Key": "db.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "redis-mock"
                        }
                },
                {
                        "Key": "db.statement",
                        "Value": {
                                "Type": "STRING",
                                "Value": "set key value"
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "host.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "server-host-0"
                        }
                },
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "APM-Go-Demo"
                        }
                },
                {
                        "Key": "token",
                        "Value": {
                                "Type": "STRING",
                                "Value": "\u003cAPM-TOKEN-HERE\u003e"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "github.com/go-redis/redis/extra/redisotel",
                "Version": "semver:8.11.5",
                "SchemaURL": ""
        }
}

About

腾讯云APM团队 Go通过OpenTelemetry协议上报demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages