Skip to content

Commit 4ecfe9e

Browse files
committed
feat(crashtracker): add orchestrion auto-injection aspect
Add an orchestrion aspect that prepends crashtracker.Start() as the first statement of every program's main() function at compile time, enabling transparent crash report capture without any source changes. The aspect uses prepend-statements (not inject-declarations/func init()) because SetCrashOutput must run inside main(), after all package init()s have completed but before any user code executes. This matches the RFC's requirement for the monitor process to be established before any goroutine can crash. Env-gating (DD_CRASHTRACKING_ENABLED, default true) is handled inside Start() itself, so the injected statement is a single unconditional call. Regenerates orchestrion/all/orchestrion.tool.go to include the crashtracker package. Adds a harness integration test confirming the aspect wires correctly under orchestrion's compile-time transformation.
1 parent 323af46 commit 4ecfe9e

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

crashtracker/orchestrion.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed
2+
# under the Apache License Version 2.0.
3+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
# Copyright 2016-present Datadog, Inc.
5+
---
6+
# yaml-language-server: $schema=https://datadoghq.dev/orchestrion/schema.json
7+
meta:
8+
name: github.com/DataDog/dd-trace-go/v2/crashtracker
9+
description: |-
10+
Starts the Datadog crashtracker as the first statement of main(), so the
11+
monitor process is established before any goroutine can crash.
12+
13+
aspects:
14+
- id: func main()
15+
join-point:
16+
all-of:
17+
- package-name: main
18+
- test-main: false
19+
- function-body:
20+
function:
21+
- name: main
22+
- signature: {}
23+
advice:
24+
- prepend-statements:
25+
imports:
26+
crashtracker: github.com/DataDog/dd-trace-go/v2/crashtracker
27+
template: |-
28+
crashtracker.Start()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
package crashtracker
7+
8+
import (
9+
"context"
10+
"testing"
11+
12+
"github.com/DataDog/dd-trace-go/v2/internal/orchestrion/_integration/internal/trace"
13+
)
14+
15+
// TestCase verifies that crashtracker.Start() is injected into main() by
16+
// orchestrion. The crashtracker does not produce trace spans, so the test
17+
// only validates that the instrumented binary runs without crashing due to
18+
// a missing Start() call.
19+
type TestCase struct{}
20+
21+
func (*TestCase) Setup(_ context.Context, _ *testing.T) {}
22+
23+
func (*TestCase) Run(_ context.Context, _ *testing.T) {}
24+
25+
func (*TestCase) ExpectedTraces() trace.Traces {
26+
return trace.Traces{}
27+
}

internal/orchestrion/_integration/crashtracker/generated_test.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orchestrion/all/orchestrion.tool.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)