Skip to content

Commit 7a2adb4

Browse files
committed
feat(errortracking): extend agenttelemetry component with error log submission
- Add SubmitErrorLog(ErrorLog) to the component interface - Add bounded errLogsCh channel, non-blocking SubmitErrorLog(), and flushErrortracking() scheduler job - Add errortracking_sender.go: converts ErrorLog to dd-go Log with stack symbolization - Add logs_payload.go: builds LogsPayload batches for HTTP POST - Refactor sender.go: extract shared sendPayloadBody() helper reused by metrics and logs paths
1 parent f18b1d1 commit 7a2adb4

12 files changed

Lines changed: 1139 additions & 46 deletions

File tree

comp/core/agenttelemetry/def/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ go_library(
55
srcs = ["component.go"],
66
importpath = "github.com/DataDog/datadog-agent/comp/core/agenttelemetry/def",
77
visibility = ["//visibility:public"],
8-
deps = ["//pkg/fleet/installer/telemetry"],
8+
deps = [
9+
"//pkg/fleet/installer/telemetry",
10+
"//pkg/util/log/errortracking",
11+
],
912
)

comp/core/agenttelemetry/def/component.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111

1212
installertelemetry "github.com/DataDog/datadog-agent/pkg/fleet/installer/telemetry"
13+
"github.com/DataDog/datadog-agent/pkg/util/log/errortracking"
1314
)
1415

1516
// team: agent-runtimes
@@ -21,5 +22,26 @@ type Component interface {
2122
// payload - de-serializable into JSON
2223
SendEvent(eventType string, eventPayload []byte) error
2324

25+
// SubmitErrorLog accepts a single error log record from the
26+
// pkg/util/log slog handler and enqueues it for asynchronous flush
27+
// to the internal agent telemetry intake. Implementations
28+
// MUST be non-blocking on the hot path: enqueue to a bounded buffer
29+
// and drop silently on overflow.
30+
//
31+
// Recursion prevention: the flush path
32+
// (sendLogsBatch → sendPayload) MUST NOT log at
33+
// Error or above. A flush-path Errorf would re-enter the slog
34+
// handler and feed records back into this same channel. This
35+
// invariant is enforced by convention — there is no runtime
36+
// caller-identity guard. See
37+
// comp/core/agenttelemetry/impl/errortracking_sender.go. If a
38+
// flush fails, the failed batch is not re-attempted; the Debug-level
39+
// log is the only signal.
40+
//
41+
// This method receives the ErrorLog value-type defined at
42+
// pkg/util/log/errortracking; the component never sees raw slog
43+
// types on its public surface.
44+
SubmitErrorLog(log errortracking.ErrorLog)
45+
2446
StartStartupSpan(operationName string) (*installertelemetry.Span, context.Context)
2547
}

comp/core/agenttelemetry/def/go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ module github.com/DataDog/datadog-agent/comp/core/agenttelemetry/def
22

33
go 1.25.0
44

5-
require github.com/DataDog/datadog-agent/pkg/fleet/installer v0.70.0
5+
require (
6+
github.com/DataDog/datadog-agent/pkg/fleet/installer v0.70.0
7+
github.com/DataDog/datadog-agent/pkg/util/log v0.73.2
8+
)
69

710
require (
811
github.com/DataDog/datadog-agent/pkg/template v0.73.2 // indirect
9-
github.com/DataDog/datadog-agent/pkg/util/log v0.73.2 // indirect
1012
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.73.2 // indirect
1113
github.com/DataDog/datadog-agent/pkg/version v0.73.2 // indirect
1214
github.com/ebitengine/purego v0.10.0 // indirect

comp/core/agenttelemetry/fx/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ require (
4747
github.com/DataDog/datadog-agent/pkg/util/hostinfo v0.0.0-20251027120702-0e91eee9852f // indirect
4848
github.com/DataDog/datadog-agent/pkg/util/http v0.75.4 // indirect
4949
github.com/DataDog/datadog-agent/pkg/util/log v0.75.4 // indirect
50+
github.com/DataDog/datadog-agent/pkg/util/log/setup v0.0.0-00010101000000-000000000000 // indirect
5051
github.com/DataDog/datadog-agent/pkg/util/option v0.75.4 // indirect
5152
github.com/DataDog/datadog-agent/pkg/util/pointer v0.75.4 // indirect
5253
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.75.4 // indirect

comp/core/agenttelemetry/impl/BUILD.bazel

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ go_library(
55
srcs = [
66
"agenttelemetry.go",
77
"config.go",
8+
"errortracking_sender.go",
9+
"logs_payload.go",
810
"runner.go",
911
"sender.go",
1012
"utils.go",
@@ -24,32 +26,41 @@ go_library(
2426
"//pkg/fleet/installer/telemetry",
2527
"//pkg/util/hostinfo",
2628
"//pkg/util/http",
29+
"//pkg/util/log/errortracking",
30+
"//pkg/util/log/setup",
2731
"//pkg/util/scrubber",
2832
"//pkg/version",
2933
"@com_github_datadog_zstd//:zstd",
3034
"@com_github_prometheus_client_model//go",
3135
"@com_github_robfig_cron_v3//:cron",
3236
"@in_yaml_go_yaml_v2//:yaml",
37+
"@org_uber_go_atomic//:atomic",
3338
],
3439
)
3540

3641
go_test(
3742
name = "impl_test",
38-
srcs = ["agenttelemetry_test.go"],
43+
srcs = [
44+
"agenttelemetry_test.go",
45+
"errortracking_sender_test.go",
46+
],
3947
embed = [":impl"],
4048
gotags = ["test"],
4149
deps = [
4250
"//comp/core/log/def",
4351
"//comp/core/log/mock",
4452
"//comp/core/telemetry/def",
4553
"//comp/core/telemetry/mock",
54+
"//comp/logs/agent/config",
4655
"//pkg/config/mock",
4756
"//pkg/util/fxutil",
4857
"//pkg/util/jsonquery",
58+
"//pkg/util/log/errortracking",
4959
"@com_github_datadog_zstd//:zstd",
5060
"@com_github_prometheus_client_model//go",
5161
"@com_github_stretchr_testify//assert",
5262
"@com_github_stretchr_testify//mock",
5363
"@com_github_stretchr_testify//require",
64+
"@org_uber_go_atomic//:atomic",
5465
],
5566
)

0 commit comments

Comments
 (0)