Skip to content

Commit

Permalink
Add --inst-all as alias, more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gagbo committed Oct 20, 2023
1 parent d08f8d1 commit 4dcbea2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ compatibility comes out of the box).

### 3. Add directives for each function you want to instrument

#### 3a. The VERY quick way

Use find and sed to insert a `//go:generate` directive that will instrument all
the functions in all source files under the current directory:

(Replace `gsed` with `sed` on linux; `gsed` is installed with `brew gsed`)

``` bash
find ./ \
-type f \
-name "*.go$" \
-print0 | xargs -0 gsed -i -e '/package/{i\//go:generate autometrics --instrument-all --no-doc' -e ':a;n;ba}'
```

You can remove the `--no-doc` to get the full experience, but the generator will add a lot of comments if so.

#### 3b. The slower quick way

This grants you more control over what gets instrumented, but it is longer
to add.

> **Warning**
> You must both add the `//go:generate` directive, and one `//autometrics:inst`
directive per function you want to instrument
Expand All @@ -133,7 +154,7 @@ subsection to see details:

Once it is done, you can call the [generator](#4-generate-the-documentation-and-instrumentation-code)

#### For error-returning functions
##### For error-returning functions

<details><summary><i>Expand to instrument error returning functions</i></summary>

Expand Down Expand Up @@ -165,7 +186,7 @@ _must_ name the error return value. This is why we recommend to name the error
value you return for the function you want to instrument.
</details>

#### For HTTP handler functions
##### For HTTP handler functions

<details><summary><i>Expand to instrument HTTP handlers functions</i></summary>

Expand Down Expand Up @@ -477,6 +498,23 @@ instrumentation only, you have multiple options:
$ AM_NO_DOCGEN=true go generate ./...
```

##### Offboarding

If for some reason you want to stop using autometrics, the easiest way includes 3 steps.

First is to use the environment variable `AM_RM_ALL` to remove all generated documentation
and code:

``` console
$ AM_RM_ALL=true go generate ./...
```

Second step is to use grep/your text-editor/your IDE of choice to remove all lines starting with
`//go:generate autometrics` from your files so `go generate` will stop creating autometrics code.

Last step is to use your text-editor IDE to remove remnants:
- a "go imports" cleaner to remove the `autometrics` imports (or grep-ing again)
- remove the `autometrics.Init` call from the main entrypoint of your code.

# Contributing

Expand Down
2 changes: 1 addition & 1 deletion cmd/autometrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type args struct {
UseOtel bool `arg:"--otel" default:"false" help:"Use OpenTelemetry client library to instrument code instead of default Prometheus."`
AllowCustomLatencies bool `arg:"--custom-latency" default:"false" help:"Allow non-default latencies to be used in latency-based SLOs."`
DisableDocGeneration bool `arg:"--no-doc,env:AM_NO_DOCGEN" default:"false" help:"Disable documentation links generation for all instrumented functions. Has the same effect as --no-doc in the //autometrics:inst directive."`
ProcessAllFunctions bool `arg:"--instrument-all,env:AM_INSTRUMENT_ALL" default:"false" help:"Instrument all function declared in the file to transform. Overwritten by the --rm-all argument if both are set."`
ProcessAllFunctions bool `arg:"-i,--instrument-all,--inst-all,env:AM_INSTRUMENT_ALL" default:"false" help:"Instrument all function declared in the file to transform. Overwritten by the --rm-all argument if both are set."`
RemoveAllFunctions bool `arg:"--rm-all,env:AM_RM_ALL" default:"false" help:"Remove all function instrumentation in the file to transform."`
}

Expand Down

0 comments on commit 4dcbea2

Please sign in to comment.