Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Disable doc generation when AUTOMETRICS_DISABLE_DOCS env var is present
  • Loading branch information
emschwartz committed May 26, 2023
commit 0e7e614523116f43e403b5a60db0ccff5939ecca
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Autometrics now provides a `tracing_subscriber::Layer` that makes the specific `Span` fields
available to the library, and autometrics will automatically attach those fields as exemplars
on the counter and histogram metrics
- `AUTOMETRICS_DISABLE_DOCS` environment variable can be set to disable doc comment generation
(this is mainly for use with editor extensions that generate doc comments themselves)

### Changed

Expand Down
8 changes: 6 additions & 2 deletions autometrics-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ fn instrument_function(args: &AutometricsArgs, item: ItemFn) -> Result<TokenStre
let prometheus_url =
env::var("PROMETHEUS_URL").unwrap_or_else(|_| DEFAULT_PROMETHEUS_URL.to_string());

// Build the documentation we'll add to the function's RustDocs
let metrics_docs = create_metrics_docs(&prometheus_url, &function_name, args.track_concurrency);
// Build the documentation we'll add to the function's RustDocs, unless it is disabled by the environment variable
let metrics_docs = if option_env!("AUTOMETRICS_DISABLE_DOCS").is_some() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option_env! works at compile-time. Is that really what we want? I see PROMETHEUS_URL uses the regular env::var() function, which I think I would've expected here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I'm not sure it makes a difference because the macros are only run at compile time. But I can change it anyway

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also found it hard to reason about what it means for something to be done at compile-time for a macro. Maybe avoiding the confusion is reason enough :)

String::new()
} else {
create_metrics_docs(&prometheus_url, &function_name, args.track_concurrency)
};

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