Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase Telemetry resource testing coverage #1646

Merged
merged 8 commits into from
Apr 3, 2024

Conversation

rogercoll
Copy link
Contributor

Fixes # #1624 (comment)

Changes

  • Test that all default providers (traces, logs, metrics) contain the corresponding Telemetry resource attributes (TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_NAME, TELEMETRY_SDK_VERSION).

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@rogercoll rogercoll requested a review from a team March 28, 2024 16:34
@rogercoll rogercoll changed the title test: increase telemetry resource coverage test: increase Telemetry resource testing coverage Mar 28, 2024
@rogercoll
Copy link
Contributor Author

Skip changelog?

Copy link

codecov bot commented Mar 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.2%. Comparing base (278f5c7) to head (5a45089).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1646     +/-   ##
=======================================
+ Coverage   68.9%   69.2%   +0.3%     
=======================================
  Files        136     136             
  Lines      19429   19625    +196     
=======================================
+ Hits       13396   13598    +202     
+ Misses      6033    6027      -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

};

// If users didn't provide a resource and there isn't a env var set. Use default one.
let default_config_provider = super::LoggerProvider::builder().build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's wrap it with temp_env. Just in case other tests contaminate the env var

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, added 611a3f3

})
.build();

assert_resource(&no_service_name, SERVICE_NAME, None);
Copy link
Member

Choose a reason for hiding this comment

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

nit - this test is redundant, and can be removed. As we are checking the length in the next test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense to me 7947daa

let user_provided_resource_config_provider = super::LoggerProvider::builder()
.with_config(Config {
resource: Cow::Owned(Resource::default().merge(&mut Resource::new(vec![
KeyValue::new("my-custom-key", "my-custom-value"),
Copy link
Member

Choose a reason for hiding this comment

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

should we also add here a resource attribute not present in the OTEL_RESOURCE_ATTRIBUTES env var, to validate it is merged properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Added 5a45089

provider.config().resource.get(TELEMETRY_SDK_VERSION.into()),
Some(Value::from(env!("CARGO_PKG_VERSION")))
);
};
Copy link
Member

Choose a reason for hiding this comment

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

Good to investigate (probably as a separate PR) if we can reuse the above validation function - assert_resource() and assert_telemetry_resource() across all the providers. One option could be to move them to testing directory, and they can take resource object instead of provider as an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would it make sense to add those functions in the resource module and make them available for the whole crate? or the testing directory is preferred?

draft pr moving the functions to the resource module: https://github.com/rogercoll/opentelemetry-rust/pull/1/files

"test_service",
)]))
.build();
assert_service_name(custom_meter_provider, Some("test_service"));
assert_resource(&custom_meter_provider, SERVICE_NAME, Some("test_service"));
Copy link
Member

Choose a reason for hiding this comment

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

nit - as earlier, this test is redundant, and can be removed. As we are checking the length in the next test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case we want to assert the custom defined service_name value ("test_service"), but also that no other resources are defined (like the telemetry ones)

@@ -310,7 +346,8 @@ mod tests {
.with_resource(Resource::empty())
.build();

assert_service_name(no_service_name, None);
assert_resource(&no_service_name, SERVICE_NAME, None);
Copy link
Member

Choose a reason for hiding this comment

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

nit - as earlier, this test is redundant, and can be removed. As we are checking the length in the next test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -357,6 +395,7 @@ mod tests {
})
.build();

assert_service_name(no_service_name, None);
assert_resource(&no_service_name, SERVICE_NAME, None);
Copy link
Member

Choose a reason for hiding this comment

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

nit - as earlier this test is redundant, and can be removed. As we are checking the length in the next test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

Thanks for improving the tests. LGTM, with nit suggestions.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

LGTM thanks for working on this!

@TommyCpp TommyCpp merged commit 04a800c into open-telemetry:main Apr 3, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants