Skip to content

Commit 6bceaf4

Browse files
authored
Disable doc generation when AUTOMETRICS_DISABLE_DOCS env var is present (#104)
* Disable doc generation when AUTOMETRICS_DISABLE_DOCS env var is present * Use env::var
1 parent 810cef5 commit 6bceaf4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
Autometrics now provides a `tracing_subscriber::Layer` that makes the specific `Span` fields
1919
available to the library, and autometrics will automatically attach those fields as exemplars
2020
on the counter and histogram metrics
21+
- `AUTOMETRICS_DISABLE_DOCS` environment variable can be set to disable doc comment generation
22+
(this is mainly for use with editor extensions that generate doc comments themselves)
2123

2224
### Changed
2325

autometrics-macros/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ fn instrument_function(args: &AutometricsArgs, item: ItemFn) -> Result<TokenStre
5757
let prometheus_url =
5858
env::var("PROMETHEUS_URL").unwrap_or_else(|_| DEFAULT_PROMETHEUS_URL.to_string());
5959

60-
// Build the documentation we'll add to the function's RustDocs
61-
let metrics_docs = create_metrics_docs(&prometheus_url, &function_name, args.track_concurrency);
60+
// Build the documentation we'll add to the function's RustDocs, unless it is disabled by the environment variable
61+
let metrics_docs = if env::var("AUTOMETRICS_DISABLE_DOCS").is_ok() {
62+
String::new()
63+
} else {
64+
create_metrics_docs(&prometheus_url, &function_name, args.track_concurrency)
65+
};
6266

6367
// Type annotation to allow type inference to work on return expressions (such as `.collect()`), as
6468
// well as prevent compiler type-inference from selecting the wrong branch in the `spez` macro later.

0 commit comments

Comments
 (0)