Skip to content

Issue with default repo_url and service_name values #178

@DusterTheFirst

Description

@DusterTheFirst

In autometrics, the repo_url and service_name are both set from cargo environment variables.

.unwrap_or_else(|| env!("CARGO_PKG_REPOSITORY").to_string());

.unwrap_or_else(|| env!("CARGO_PKG_NAME").to_string()),

CARGO_PKG_REPOSITORY and CARGO_PKG_NAME are set by cargo to the current crate's values, not the top level project. This means that the values for repo_url and service_name, if not specified they will become https://github.com/autometrics-dev/autometrics-rs and autometrics respectively.

This problem does not exist for the labels from BuildInfoLabels since those are created in the expansion of the #[autometrics] macro, meaning the expanded env!() macros are located in the user's crate. A solution could be to expand these env!() macros along side the other BuildInfoLabels values.

A work around for now is to manually setup the autometrics settings using code like below:

autometrics::settings::AutometricsSettings::builder()
    .repo_url(env!("CARGO_PKG_REPOSITORY"))
    .service_name(env!("CARGO_PKG_NAME"))
    .init();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions