| 1 |
# antithesis-go-toolexec |
| 2 |
|
| 3 |
Adds Antithesis coverage instrumentation and assertion catalogs from inside |
| 4 |
`go build`, as a |
| 5 |
[`-toolexec`](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) |
| 6 |
wrapper, instead of by copying and rewriting a source tree. |
| 7 |
|
| 8 |
## Using it |
| 9 |
|
| 10 |
```sh |
| 11 |
go build -toolexec=antithesis-go-toolexec -o /app ./cmd/app |
| 12 |
``` |
| 13 |
|
| 14 |
or, so that no build command has to change: |
| 15 |
|
| 16 |
```dockerfile |
| 17 |
ENV GOFLAGS=-toolexec=antithesis-go-toolexec |
| 18 |
RUN go build -o /app ./cmd/app |
| 19 |
RUN go test ./... # instrumented too |
| 20 |
``` |
| 21 |
|
| 22 |
Assertion catalogs are produced too, one per instrumented package, so no separate |
| 23 |
`antithesis-go-instrumentor` pass is needed. |
| 24 |
|
| 25 |
Coverage and cataloguing are independent. For catalogs alone, turn coverage off: |
| 26 |
|
| 27 |
```sh |
| 28 |
ANTITHESIS_SKIP_COVERAGE=1 go build -toolexec=antithesis-go-toolexec ./... |
| 29 |
``` |
| 30 |
|
| 31 |
Or to produce symbol tables without assertion catalogs, turn cataloguing off: |
| 32 |
|
| 33 |
```sh |
| 34 |
ANTITHESIS_SKIP_CATALOG=1 go build -toolexec=antithesis-go-toolexec ./... |
| 35 |
``` |
| 36 |
|
| 37 |
### In a multi-stage image build |
| 38 |
|
| 39 |
Symbol tables are written to `/symbols` by default, which is where the image |
| 40 |
build harvests them. A multi-stage Dockerfile has to carry them forward: |
| 41 |
|
| 42 |
```dockerfile |
| 43 |
FROM golang:1.24 AS builder |
| 44 |
ENV GOFLAGS=-toolexec=antithesis-go-toolexec |
| 45 |
RUN go build -o /app ./cmd/app |
| 46 |
|
| 47 |
FROM debian:bookworm-slim |
| 48 |
COPY --from=builder /app /app |
| 49 |
COPY --from=builder /symbols /symbols |
| 50 |
``` |
| 51 |
|
| 52 |
### Configuration |
| 53 |
|
| 54 |
Configuration is via environment variables: |
| 55 |
|
| 56 |
| Variable | Effect | |
| 57 |
| --- | --- | |
| 58 |
| `ANTITHESIS_INSTRUMENT` | Comma-separated import path prefixes to instrument. Default: everything whose sources are in the working tree, which is the main module plus any locally replaced module, and excludes downloaded dependencies. | |
| 59 |
| `ANTITHESIS_SYMBOLS_DIR` | Where symbol tables are collected. Default `/symbols`. | |
| 60 |
| `ANTITHESIS_EXCLUDE` | Exclusions file, in the format `antithesis-go-instrumentor -exclude` accepts. | |
| 61 |
| `ANTITHESIS_SYMBOL_PREFIX` | Prefix for symbol table file names, matching `-prefix`. | |
| 62 |
| `ANTITHESIS_SDK_MODULE_DIR` | An `antithesis-sdk-go` checkout, used to supply the SDK to a module that does not depend on it. See below. | |
| 63 |
| `ANTITHESIS_SKIP_TEST_FILES` | Set to `1` to leave `_test.go` files uninstrumented. | |
| 64 |
| `ANTITHESIS_SKIP_CATALOG` | Set to `1` to skip assertion cataloguing. | |
| 65 |
| `ANTITHESIS_SKIP_COVERAGE` | Set to `1` to skip coverage instrumentation. Leaving cataloguing on makes this the equivalent of `antithesis-go-instrumentor -assert_only`. | |
| 66 |
| `ANTITHESIS_VERBOSE` | `0`–`3`. Logs to stderr during the build. A compile that writes to stderr is not cached by the go command, so this also disables incremental builds — fine for diagnosis, not for a development loop. | |