Skip to content

Commit

Permalink
Fix quickstart instruction (#75)
Browse files Browse the repository at this point in the history
Apparently go-arg doesn't work with flag aliases
  • Loading branch information
gagbo authored Oct 31, 2023
1 parent 239584e commit 71cd848
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ versioning](https://go.dev/doc/modules/version-numbers).

### Added

- [All] `autometrics` the go-generator binary accepts an `--instrument-all` flag, to process all
- [All] `autometrics` the go-generator binary accepts an `--inst-all` flag, to process all
functions in the file even if they do not have any annotation
- [All] `autometrics` the go-generator binary accepts a `--rm-all` flag (that overrides the `--instrument-all` flag)
- [All] `autometrics` the go-generator binary accepts a `--rm-all` flag (that overrides the `--inst-all` flag)
to remove autometrics from all annotated functions. This is useful to offboard autometrics after trying it:
```bash
AM_RM_ALL=true go generate ./... # Will remove all godoc and instrumentation calls
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ compatibility comes out of the box).

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

#### 3a. The VERY quick way
#### 3a. The QUICKEST way

If you have [`am`](https://github.com/autometrics-dev/am) installed in version `0.6.0` or later, you can
use `am instrumtent single -e /vendor/ -l go .` to instrument everything (excluding a possible `/vendor` subdirectory)

#### 3b. 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:
Expand All @@ -125,15 +130,14 @@ the functions in all source files under the current directory:

``` bash
find . \
-type f \
-path ./vendor -prune -or \
-name '*.go*' \
-print0 | xargs -0 gsed -i -e '/package/{a\//go:generate autometrics --instrument-all --no-doc' -e ':a;n;ba}'
-type d -name vendor -prune -or \
-type f -name '*.go' \
-print0 | xargs -0 gsed -i -e '/package/{a\//go:generate autometrics --inst-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
#### 3c. The slower quick way

This grants you more control over what gets instrumented, but it is longer
to add.
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:"-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."`
ProcessAllFunctions bool `arg:"-i,--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 71cd848

Please sign in to comment.