DataDog/dd-trace-go

GitHub: DataDog/dd-trace-go

Datadog 官方 Go 客户端库,集分布式链路追踪、持续性能分析和应用安全监控于一体。

Stars: 838 | Forks: 507

[![主分支与发布测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/680b746620011259.svg)](https://github.com/DataDog/dd-trace-go/actions/workflows/main-branch-tests.yml) [![系统测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/eb764bc71f011300.svg)](https://github.com/DataDog/dd-trace-go/actions/workflows/system-tests.yml) [![CodeQL](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/2d94793dfe011301.svg)](https://github.com/DataDog/dd-trace-go/actions/workflows/codeql-analysis.yml) [![APM 参数化测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/5fae82b519011302.svg)](https://github.com/DataDog/dd-trace-go/actions/workflows/parametric-tests.yml) [![codecov](https://codecov.io/gh/DataDog/dd-trace-go/branch/v1/graph/badge.svg?token=jGG20Xhv8i)](https://codecov.io/gh/DataDog/dd-trace-go) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2) ### Datadog Go 客户端库 本仓库包含用于 Go 应用程序的应用性能监控、持续分析和应用安全监控的 Datadog 产品套件客户端组件的 Go 包。 - [Datadog 应用性能监控 (APM)](https://docs.datadoghq.com/tracing/):追踪请求在 Web 服务器、数据库和微服务之间的流转过程,让开发者能够清晰地洞察性能瓶颈和有问题的请求。 包 [`github.com/DataDog/dd-trace-go/v2/ddtrace/tracer`](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace/tracer) 允许您追踪任何 Go 代码片段,并且得益于我们在包 [`github.com/DataDog/dd-trace-go/v2/contrib`](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/contrib) 中提供的开箱即用集成,常用的 Go 库可以被自动追踪。 - [Datadog Go 持续分析器](https://docs.datadoghq.com/profiler/):持续分析您的 Go 应用,以按函数名和行号细分的维度发现 CPU、内存和同步瓶颈,从而显著降低最终用户延迟和基础设施成本。 包 [`github.com/DataDog/dd-trace-go/v2/profiler`](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/profiler) 允许您定期收集 Go 性能分析数据并发送到 Datadog API。 - [Datadog 应用安全管理 (ASM)](https://docs.datadoghq.com/security_platform/application_security/) 提供应用内监控和保护,防御旨在利用代码级漏洞的应用层攻击,例如服务器端请求伪造 (SSRF)、SQL 注入 (SQLi) 或反射型跨站脚本 (XSS)。ASM 识别暴露于应用攻击的服务,并利用应用内安全规则检测和保护您的应用环境免受威胁。ASM 不是一个独立的 Go 包,而是透明地集成到 APM tracer 中。您只需设置 [`DD_APPSEC_ENABLED=true`](https://docs.datadoghq.com/security/application_security/enabling/go) 即可启用它。 ### 安装 此模块包含许多包,但大多数用户可能应该安装以下两个包: ``` go get github.com/DataDog/dd-trace-go/v2/ddtrace/tracer go get github.com/DataDog/dd-trace-go/v2/profiler ``` 此外,还有许多 [contrib](./contrib) 包作为嵌套模块发布,可以安装它们以自动检测和追踪常用的 Go 库,例如 [net/http](https://pkg.go.dev/github.com/DataDog/dd-trace-go/contrib/net/http/v2)、[gorilla/mux](https://pkg.go.dev/github.com/DataDog/dd-trace-go/contrib/gorilla/mux/v2) 或 [database/sql/v2](https://pkg.go.dev/github.com/DataDog/dd-trace-go/contrib/database/sql/v2) ``` go get github.com/DataDog/dd-trace-go/contrib/gorilla/mux/v2 ``` 如果您安装了超出预期的包,可以使用 `go mod tidy` 移除任何未使用的包。 ### 文档 - [APM 追踪 API](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace) - [APM 追踪 Go 应用](https://docs.datadoghq.com/tracing/setup/go/) - [Go 持续分析器](https://docs.datadoghq.com/tracing/profiler/enabling/go) - [应用安全监控](https://docs.datadoghq.com/security_platform/application_security/setup_and_configure/?code-lang=go) - 如果您正在从旧版本的 tracer(例如 1.60.x)迁移,您可能会发现我们整理的[迁移文档](MIGRATING.md)很有帮助。 ### Go 支持政策 Datadog APM for Go 基于主机操作系统、Go 版本和 Datadog Agent/API 特定版本中定义的依赖项构建。dd-trace-go 支持最新的两个 Go 版本,符合 [官方 Go 政策](https://go.dev/doc/devel/release#policy)。本库仅正式支持 Go 的[一等端口](https://go.dev/wiki/PortingPolicy)。 ### 测试 测试可以使用 make 目标或 Go 工具集在本地运行。 **使用 Make(推荐)**: ``` Usage: make [target] Targets: help Show this help message all Run complete build pipeline (tools, generate, lint, test) tools-install Install development tools tools-install/checkmake Install checkmake binary for Makefile linting clean Clean build artifacts clean-all Clean everything including tools and temporary files generate Run code generation lint Run linting checks lint/go Run Go linting checks lint/go/fix Fix linting issues automatically lint/shell Run shell script linting checks lint/misc Run miscellaneous linting checks (copyright, Makefiles) lint/action Lint GitHub Actions workflows format Format code format/go Format Go code format/shell install shfmt test Run all tests (core, integration, contrib) test/unit Run unit tests test/appsec Run tests with AppSec enabled test/contrib Run contrib package tests test/integration Run integration tests test-deadlock Run tests with deadlock detection test-debug-deadlock Run tests with debug and deadlock detection fix-modules Fix module dependencies and consistency fix/go Apply go fix modernizations to Go code fix/go/diff Preview go fix modernizations (dry-run) docs Generate and Update embedded documentation in README files upgrade/orchestrion Upgrade Orchestrion and fix modules ``` **直接使用脚本**: 为了获得更多控制权,您可以直接使用 [scripts/test.sh](./scripts/test.sh) 脚本。运行集成测试需要安装 Docker 和 docker-compose。运行 `./scripts/test.sh --help` 查看所有可用选项。 要在本地运行集成测试,您应该设置 `INTEGRATION` 环境变量。集成测试的依赖项最好通过 Docker 运行。要了解版本和设置,请查看我们的 [docker-compose 配置](./docker-compose.yaml)。 如果您只对特定集成的测试感兴趣,通过 docker-compose 仅启动所需的容器会很有用。 例如,如果您正在运行需要启动 `mysql` 数据库容器的测试: ``` docker compose -f docker-compose.yaml -p dd-trace-go up -d mysql ```
标签:API集成, APM, ASM, Datadog, EVTX分析, EVTX分析, Go语言, Instrumentation, IP 地址批量处理, RASP, SaaS, 中间件集成, 分布式追踪, 可观测性, 应用安全监控, 应用性能监控, 开源库, 微服务监控, 性能分析, 持续性能剖析, 插桩, 搜索引擎爬虫, 日志审计, 瓶颈分析, 用户代理, 程序破解, 请求拦截, 运行时应用自我保护, 错误追踪