Skip to content

Commit

Permalink
Nit change to flag descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jjti committed Dec 28, 2023
1 parent d1f1772 commit 007da05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ Usage of spanlint:
-enable-all
enable all checks, overriding individual check flags
-enable-record-error-check
enable the check for calling span.RecordError(err) when returning an error
enable check for a span.RecordError(err) call when returning an error
-enable-set-status-check
enable the check for calling span.SetStatus(codes.Error, msg) when returning an error
enable check for a span.SetStatus(codes.Error, msg) call when returning an error
-ignore-record-error-check-signatures string
comma-separated list of function signature regex that should disable the span.RecordError(err) checks on errors
comma-separated list of function signature regex that disable the span.RecordError(err) check on errors
-ignore-set-status-check-signatures string
comma-separated list of function signature regex that should disable the span.SetStatus(codes.Error, msg) checks on errors
comma-separated list of function signature regex that disable the span.SetStatus(codes.Error, msg) check on errors
```

Only the `span.End()` check is enabled by default. The others can be enabled with `-enable-all`, `-enable-record-error-check`, or `-enable-set-status-check`.

### Ignore check signatures

The `span.SetStatus()` and `span.RecordError()` checks warn when there is a path to return statement, with an error, without a call (to `SetStatus`, or `RecordError`, respectively). But it is convenient to set span's status and record errors from utility methods [1](https://andydote.co.uk/2023/09/19/tracing-is-better/#step-2-wrap-the-errors). To support that, the `ignore-*-check-signatures` settings can be used to ignore paths to return statements if that signature is present.
The `span.SetStatus()` and `span.RecordError()` checks warn when there is a path to return statement, with an error, without a call (to `SetStatus`, or `RecordError`, respectively). But it's convenient to set span's status and record errors from utility methods [[1](https://andydote.co.uk/2023/09/19/tracing-is-better/#step-2-wrap-the-errors)]. To support that, the `ignore-*-check-signatures` settings can be used to ignore paths to return statements if that signature is present.

For example, by default, the code below would have the warning shown:

Expand Down Expand Up @@ -104,6 +104,10 @@ OpenTelemetry docs: [Creating spans](https://opentelemetry.io/docs/instrumentati
Uptrace tutorial: [OpenTelemetry Go Tracing API](https://uptrace.dev/opentelemetry/go-tracing.html#quickstart)
## Checks
This linter supports three checks, each documented below. Only the check for `span.End()` is enabled by default. See [Configuration](#configuration) for instructions on enabling the others.
### `span.End()` Check
Not calling `End` can cause memory leaks and prevents spans from being closed.
Expand Down
8 changes: 4 additions & 4 deletions cmd/spanlint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func main() {
config := spanlint.NewDefaultConfig()
flag.BoolVar(&config.DisableEndCheck, "disable-end-check", config.DisableEndCheck, "disable the check for calling span.End() after span creation")
flag.BoolVar(&config.EnableAll, "enable-all", config.EnableAll, "enable all checks, overriding individual check flags")
flag.BoolVar(&config.EnableSetStatusCheck, "enable-set-status-check", config.EnableSetStatusCheck, "enable the check for calling span.SetStatus(codes.Error, msg) when returning an error")
ignoreSetStatusCheckSignatures := flag.String(ignoreSetStatusCheckSignatures, "", "comma-separated list of function signature regex that should disable the span.SetStatus(codes.Error, msg) checks on errors")
flag.BoolVar(&config.EnableRecordErrorCheck, "enable-record-error-check", config.EnableRecordErrorCheck, "enable the check for calling span.RecordError(err) when returning an error")
ignoreRecordErrorCheckSignatures := flag.String(ignoreRecordErrorCheckSignatures, "", "comma-separated list of function signature regex that should disable the span.RecordError(err) checks on errors")
flag.BoolVar(&config.EnableSetStatusCheck, "enable-set-status-check", config.EnableSetStatusCheck, "enable check for a span.SetStatus(codes.Error, msg) call when returning an error")
ignoreSetStatusCheckSignatures := flag.String(ignoreSetStatusCheckSignatures, "", "comma-separated list of function signature regex that disable the span.SetStatus(codes.Error, msg) check on errors")
flag.BoolVar(&config.EnableRecordErrorCheck, "enable-record-error-check", config.EnableRecordErrorCheck, "enable check for a span.RecordError(err) call when returning an error")
ignoreRecordErrorCheckSignatures := flag.String(ignoreRecordErrorCheckSignatures, "", "comma-separated list of function signature regex that disable the span.RecordError(err) check on errors")
flag.Parse()

// Parse the signatures.
Expand Down

0 comments on commit 007da05

Please sign in to comment.