Skip to content

Commit ca1170a

Browse files
committed
Implement auto instrumentation with go orchestrion.
1 parent 94b6451 commit ca1170a

40 files changed

+2803
-65
lines changed

.claude/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
"Bash(jq:*)",
5757
"Bash(sort:*)",
5858
"Bash(uniq:*)",
59+
"Bash(orchestrion:*)",
60+
"Bash(orchestrion)",
61+
"Bash(mise:*)",
62+
"Bash(mise)",
5963
"Bash(cut:*)"
6064
]
6165
}

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
uses: golangci/golangci-lint-action@v8
3131
with:
3232
version: v2.1.6
33+
- name: Install orchestrion
34+
run: go install github.com/DataDog/orchestrion@latest
3335
- name: Lint, vet, tests, etc.
3436
run: make ci
3537

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ linters:
2020
enable:
2121
- bodyclose
2222
- forcetypeassert # catches potential panics
23-
- usetesting # nice-to-have not critical
23+
# - usetesting # nice-to-have not critical (disabled to reduce PR noise)
2424
- thelper # nice-to-have not critical
2525
- revive # critical for ensuring public functions/packages have docs.
2626

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717

1818
## Examples
1919
- New features should be covered in `examples/internal/` for validation
20+
- Run a single example: `go run examples/internal/<name>/main.go`
2021
- Run all examples: `make examples`

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help ci build clean test test-quiet test-vcr-off test-vcr-record test-vcr-verify cover cover-path lint fmt mod-verify fix godoc examples release
1+
.PHONY: help ci build clean test test-quiet test-vcr-off test-vcr-record test-vcr-verify cover cover-path lint fmt mod-verify fix godoc examples release generate
22

33
help:
44
@echo "Available commands:"
@@ -17,6 +17,7 @@ help:
1717
@echo " fix - Run golangci-lint with auto-fix"
1818
@echo " godoc - Start godoc server"
1919
@echo " examples - Run all examples"
20+
@echo " generate - Generate combined orchestrion.yml"
2021
@echo " ci - Run CI pipeline (clean, lint, test, build)"
2122
@echo " precommit - Run fmt then ci"
2223
@echo " release - Publish release with goreleaser"
@@ -80,3 +81,6 @@ precommit: fmt ci
8081

8182
release: ci
8283
./scripts/publish.sh
84+
85+
generate:
86+
go run ./internal/genorchestrion/cmd

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,50 @@ func main() {
116116

117117
### Tracing LLM Calls
118118

119-
Automatically trace LLM calls by adding middleware to your client:
119+
Trace LLM calls with **automatic** or **manual** instrumentation.
120+
121+
#### Automatic Instrumentation (Recommended)
122+
123+
Use [Orchestrion](https://github.com/DataDog/orchestrion) to automatically inject tracing at compile time—no code changes required.
124+
125+
**1. Install orchestrion:**
126+
```bash
127+
go install github.com/DataDog/orchestrion@latest
128+
```
129+
130+
**2. Create `orchestrion.tool.go` in your project root:**
131+
```go
132+
//go:build tools
133+
134+
package main
135+
136+
import (
137+
_ "github.com/DataDog/orchestrion"
138+
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/all" // All LLM providers
139+
)
140+
```
141+
142+
Or import only the integrations you need:
143+
```go
144+
import (
145+
_ "github.com/DataDog/orchestrion"
146+
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/openai" // OpenAI (openai-go)
147+
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/anthropic" // Anthropic
148+
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/genai" // Google GenAI
149+
_ "github.com/braintrustdata/braintrust-sdk-go/trace/contrib/github.com/sashabaranov/go-openai" // sashabaranov/go-openai
150+
)
151+
```
152+
153+
**3. Build with orchestrion:**
154+
```bash
155+
orchestrion go build ./...
156+
```
157+
158+
That's it! Your LLM client calls are now automatically traced. No middleware or wrapper code needed in your application.
159+
160+
#### Manual Instrumentation
161+
162+
Alternatively, add tracing middleware explicitly to your clients:
120163

121164
**OpenAI:**
122165
```go
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Binary output
2+
autoinstrumentation
3+
autoinstrumentation-example
4+
5+
# Go build artifacts
6+
*.exe
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.PHONY: run build help
2+
3+
help:
4+
@echo "Auto-Instrumentation Example (using Orchestrion)"
5+
@echo ""
6+
@echo "Prerequisites:"
7+
@echo " go install github.com/DataDog/orchestrion@latest"
8+
@echo ""
9+
@echo "Environment variables:"
10+
@echo " BRAINTRUST_API_KEY - Braintrust API key"
11+
@echo " OPENAI_API_KEY - OpenAI API key"
12+
@echo " ANTHROPIC_API_KEY - Anthropic API key"
13+
@echo ""
14+
@echo "Commands:"
15+
@echo " make run - Run with orchestrion auto-instrumentation"
16+
@echo " make build - Build with orchestrion auto-instrumentation"
17+
18+
run:
19+
orchestrion go run .
20+
21+
build:
22+
orchestrion go build -o autoinstrumentation-example .
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
module github.com/braintrustdata/braintrust-sdk-go/examples/internal/autoinstrumentation
2+
3+
go 1.24.0
4+
5+
toolchain go1.24.11
6+
7+
require (
8+
github.com/DataDog/orchestrion v1.6.1
9+
github.com/anthropics/anthropic-sdk-go v1.4.0
10+
github.com/braintrustdata/braintrust-sdk-go v0.0.0
11+
github.com/openai/openai-go v1.12.0
12+
github.com/sashabaranov/go-openai v1.41.2
13+
go.opentelemetry.io/otel v1.38.0
14+
go.opentelemetry.io/otel/sdk v1.38.0
15+
)
16+
17+
require (
18+
cloud.google.com/go v0.121.4 // indirect
19+
cloud.google.com/go/auth v0.16.3 // indirect
20+
cloud.google.com/go/compute/metadata v0.7.0 // indirect
21+
github.com/DataDog/datadog-agent/comp/core/tagger/origindetection v0.71.2 // indirect
22+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.71.2 // indirect
23+
github.com/DataDog/datadog-agent/pkg/opentelemetry-mapping-go/otlp/attributes v0.71.2 // indirect
24+
github.com/DataDog/datadog-agent/pkg/proto v0.71.2 // indirect
25+
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.73.0-rc.1 // indirect
26+
github.com/DataDog/datadog-agent/pkg/trace v0.71.2 // indirect
27+
github.com/DataDog/datadog-agent/pkg/util/log v0.71.2 // indirect
28+
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.71.2 // indirect
29+
github.com/DataDog/datadog-agent/pkg/version v0.71.2 // indirect
30+
github.com/DataDog/datadog-go/v5 v5.8.1 // indirect
31+
github.com/DataDog/dd-trace-go/v2 v2.5.0 // indirect
32+
github.com/DataDog/go-libddwaf/v4 v4.8.0 // indirect
33+
github.com/DataDog/go-runtime-metrics-internal v0.0.4-0.20250806100345-ca5e7fdaf7b6 // indirect
34+
github.com/DataDog/go-sqllexer v0.1.8 // indirect
35+
github.com/DataDog/go-tuf v1.1.1-0.5.2 // indirect
36+
github.com/DataDog/sketches-go v1.4.7 // indirect
37+
github.com/Microsoft/go-winio v0.6.2 // indirect
38+
github.com/antithesishq/antithesis-sdk-go v0.5.0 // indirect
39+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
40+
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
41+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
42+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
43+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
44+
github.com/charmbracelet/colorprofile v0.3.2 // indirect
45+
github.com/charmbracelet/lipgloss v1.1.0 // indirect
46+
github.com/charmbracelet/x/ansi v0.10.2 // indirect
47+
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
48+
github.com/charmbracelet/x/term v0.2.1 // indirect
49+
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
50+
github.com/clipperhouse/stringish v0.1.1 // indirect
51+
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
52+
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
53+
github.com/dave/dst v0.27.3 // indirect
54+
github.com/dustin/go-humanize v1.0.1 // indirect
55+
github.com/ebitengine/purego v0.9.0 // indirect
56+
github.com/felixge/httpsnoop v1.0.4 // indirect
57+
github.com/fsnotify/fsnotify v1.9.0 // indirect
58+
github.com/go-logr/logr v1.4.3 // indirect
59+
github.com/go-logr/stdr v1.2.2 // indirect
60+
github.com/go-ole/go-ole v1.3.0 // indirect
61+
github.com/goccy/go-yaml v1.18.0 // indirect
62+
github.com/golang/protobuf v1.5.4 // indirect
63+
github.com/google/go-cmp v0.7.0 // indirect
64+
github.com/google/go-tpm v0.9.6 // indirect
65+
github.com/google/s2a-go v0.1.9 // indirect
66+
github.com/google/uuid v1.6.0 // indirect
67+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
68+
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
69+
github.com/gorilla/websocket v1.5.3 // indirect
70+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
71+
github.com/hashicorp/go-version v1.7.0 // indirect
72+
github.com/json-iterator/go v1.1.12 // indirect
73+
github.com/klauspost/compress v1.18.1 // indirect
74+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
75+
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
76+
github.com/lufia/plan9stats v0.0.0-20251013123823-9fd1530e3ec3 // indirect
77+
github.com/mattn/go-colorable v0.1.14 // indirect
78+
github.com/mattn/go-isatty v0.0.20 // indirect
79+
github.com/mattn/go-runewidth v0.0.19 // indirect
80+
github.com/minio/highwayhash v1.0.3 // indirect
81+
github.com/minio/simdjson-go v0.4.5 // indirect
82+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
83+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
84+
github.com/muesli/termenv v0.16.0 // indirect
85+
github.com/nats-io/jwt/v2 v2.8.0 // indirect
86+
github.com/nats-io/nats-server/v2 v2.12.1 // indirect
87+
github.com/nats-io/nats.go v1.47.0 // indirect
88+
github.com/nats-io/nkeys v0.4.11 // indirect
89+
github.com/nats-io/nuid v1.0.1 // indirect
90+
github.com/outcaste-io/ristretto v0.2.3 // indirect
91+
github.com/philhofer/fwd v1.2.0 // indirect
92+
github.com/pkg/errors v0.9.1 // indirect
93+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
94+
github.com/polyfloyd/go-errorlint v1.8.1-0.20250906200200-9b25878c4dea // indirect
95+
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
96+
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
97+
github.com/rivo/uniseg v0.4.7 // indirect
98+
github.com/rs/zerolog v1.34.0 // indirect
99+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
100+
github.com/secure-systems-lab/go-securesystemslib v0.9.1 // indirect
101+
github.com/sergi/go-diff v1.3.1 // indirect
102+
github.com/shirou/gopsutil/v4 v4.25.9 // indirect
103+
github.com/theckman/httpforwarded v0.4.0 // indirect
104+
github.com/tidwall/gjson v1.17.1 // indirect
105+
github.com/tidwall/match v1.1.1 // indirect
106+
github.com/tidwall/pretty v1.2.1 // indirect
107+
github.com/tidwall/sjson v1.2.5 // indirect
108+
github.com/tinylib/msgp v1.4.0 // indirect
109+
github.com/tklauser/go-sysconf v0.3.15 // indirect
110+
github.com/tklauser/numcpus v0.10.0 // indirect
111+
github.com/urfave/cli/v2 v2.27.7 // indirect
112+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
113+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
114+
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
115+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
116+
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
117+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
118+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
119+
go.opentelemetry.io/collector/component v1.44.0 // indirect
120+
go.opentelemetry.io/collector/featuregate v1.46.0 // indirect
121+
go.opentelemetry.io/collector/internal/telemetry v0.138.0 // indirect
122+
go.opentelemetry.io/collector/pdata v1.46.0 // indirect
123+
go.opentelemetry.io/collector/pdata/pprofile v0.140.0 // indirect
124+
go.opentelemetry.io/contrib/bridges/otelzap v0.13.0 // indirect
125+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
126+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
127+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect
128+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.36.0 // indirect
129+
go.opentelemetry.io/otel/log v0.14.0 // indirect
130+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
131+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
132+
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
133+
go.uber.org/atomic v1.11.0 // indirect
134+
go.uber.org/multierr v1.11.0 // indirect
135+
go.uber.org/zap v1.27.0 // indirect
136+
go.yaml.in/yaml/v3 v3.0.4 // indirect
137+
golang.org/x/crypto v0.45.0 // indirect
138+
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
139+
golang.org/x/mod v0.30.0 // indirect
140+
golang.org/x/net v0.47.0 // indirect
141+
golang.org/x/sync v0.18.0 // indirect
142+
golang.org/x/sys v0.38.0 // indirect
143+
golang.org/x/term v0.37.0 // indirect
144+
golang.org/x/text v0.31.0 // indirect
145+
golang.org/x/time v0.14.0 // indirect
146+
golang.org/x/tools v0.38.0 // indirect
147+
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
148+
google.golang.org/genai v1.23.0 // indirect
149+
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
150+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
151+
google.golang.org/grpc v1.76.0 // indirect
152+
google.golang.org/protobuf v1.36.10 // indirect
153+
gopkg.in/ini.v1 v1.67.0 // indirect
154+
gopkg.in/yaml.v3 v3.0.1 // indirect
155+
)
156+
157+
replace github.com/braintrustdata/braintrust-sdk-go => ../../..

0 commit comments

Comments
 (0)