Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ opentelemetry-semantic-conventions = { version = "0.28", features = [
] }
criterion = "0.5"

[workspace.lints.rust]
rust_2024_compatibility = { level = "warn", priority = -1 }
# No need to enable those, because it is either unnecessary or results in ugly syntax
if_let_rescope = "allow"
tail_expr_drop_order = "allow"

[workspace.lints.clippy]
all = { level = "warn", priority = 1 }
3 changes: 2 additions & 1 deletion opentelemetry-aws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ opentelemetry-http = { workspace = true }
opentelemetry-stdout = { workspace = true, features = ["trace"] }
hyper = { version = "1.4.1" }
tokio = { version = "1.0", features = ["macros", "rt"] }
sealed_test = "1.1.0"
sealed_test = "1.1"
temp-env = "0.3"

[package.metadata.cargo-machete]
ignored = ["tracing"]
Expand Down
79 changes: 38 additions & 41 deletions opentelemetry-aws/src/detector/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,54 +59,51 @@ impl ResourceDetector for LambdaResourceDetector {
mod tests {
use super::*;
use sealed_test::prelude::*;
use std::env::{remove_var, set_var};

#[sealed_test]
fn test_aws_lambda_detector() {
set_var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR, "my-lambda-function");
set_var(AWS_REGION_ENV_VAR, "eu-west-3");
set_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR, "$LATEST");
set_var(
AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR,
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
);
set_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR, "128");
set_var(
AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR,
"/aws/lambda/my-lambda-function",
);

let expected = Resource::builder_empty()
.with_attributes([
KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"),
KeyValue::new(semconv::resource::CLOUD_REGION, "eu-west-3"),
KeyValue::new(
semconv::resource::FAAS_INSTANCE,
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
temp_env::with_vars(
[
(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR, Some("my-lambda-function")),
(AWS_REGION_ENV_VAR, Some("eu-west-3")),
(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR, Some("$LATEST")),
(
AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR,
Some("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"),
),
KeyValue::new(semconv::resource::FAAS_NAME, "my-lambda-function"),
KeyValue::new(semconv::resource::FAAS_VERSION, "$LATEST"),
KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, 128 * 1024 * 1024),
KeyValue::new(
semconv::resource::AWS_LOG_GROUP_NAMES,
Value::Array(Array::from(vec![StringValue::from(
"/aws/lambda/my-lambda-function".to_string(),
)])),
(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR, Some("128")),
(
AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR,
Some("/aws/lambda/my-lambda-function"),
),
])
.build();
],
|| {
let expected = Resource::builder_empty()
.with_attributes([
KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"),
KeyValue::new(semconv::resource::CLOUD_REGION, "eu-west-3"),
KeyValue::new(
semconv::resource::FAAS_INSTANCE,
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
),
KeyValue::new(semconv::resource::FAAS_NAME, "my-lambda-function"),
KeyValue::new(semconv::resource::FAAS_VERSION, "$LATEST"),
KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, 128 * 1024 * 1024),
KeyValue::new(
semconv::resource::AWS_LOG_GROUP_NAMES,
Value::Array(Array::from(vec![StringValue::from(
"/aws/lambda/my-lambda-function".to_string(),
)])),
),
])
.build();

let detector = LambdaResourceDetector {};
let got = detector.detect();

assert_eq!(expected, got);
let detector = LambdaResourceDetector {};
let got = detector.detect();

remove_var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR);
remove_var(AWS_REGION_ENV_VAR);
remove_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR);
remove_var(AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR);
remove_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR);
remove_var(AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR);
assert_eq!(expected, got);
},
);
}

#[sealed_test]
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-datadog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ hyper = "1"
hyper-util = { version = "0.1.6", features = ["client", "full"] }
hyperlocal = "0.9.1"
http-body-util = "0.1.2"
temp-env = "0.3"

[[bench]]
name = "datadog_exporter"
Expand Down
42 changes: 21 additions & 21 deletions opentelemetry-datadog/src/exporter/model/unified_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,34 @@ mod tests {

#[test]
fn test_service() {
std::env::set_var("DD_SERVICE", "test-SERVICE");
let mut unified_tags = UnifiedTags::new();
assert_eq!("test-service", unified_tags.service.value.clone().unwrap());
unified_tags.set_service(Some(String::from("new_service")));
assert_eq!("new_service", unified_tags.service().unwrap());
std::env::remove_var("DD_SERVICE");
temp_env::with_var("DD_SERVICE", Some("test-SERVICE"), || {
let mut unified_tags = UnifiedTags::new();
assert_eq!("test-service", unified_tags.service.value.clone().unwrap());
unified_tags.set_service(Some(String::from("new_service")));
assert_eq!("new_service", unified_tags.service().unwrap());
});
}

#[test]
fn test_env() {
std::env::set_var("DD_ENV", "test-env");
let mut unified_tags = UnifiedTags::new();
assert_eq!("test-env", unified_tags.env.value.clone().unwrap());
unified_tags.set_env(Some(String::from("new_env")));
assert_eq!("new_env", unified_tags.env.value.unwrap());
std::env::remove_var("DD_ENV");
temp_env::with_var("DD_ENV", Some("test-env"), || {
let mut unified_tags = UnifiedTags::new();
assert_eq!("test-env", unified_tags.env.value.clone().unwrap());
unified_tags.set_env(Some(String::from("new_env")));
assert_eq!("new_env", unified_tags.env.value.unwrap());
});
}

#[test]
fn test_version() {
std::env::set_var("DD_VERSION", "test-version-1.2.3");
let mut unified_tags = UnifiedTags::new();
assert_eq!(
"test-version-1.2.3",
unified_tags.version.value.clone().unwrap()
);
unified_tags.set_version(Some(String::from("new_version")));
assert_eq!("new_version", unified_tags.version.value.unwrap());
std::env::remove_var("DD_VERSION");
temp_env::with_var("DD_VERSION", Some("test-version-1.2.3"), || {
let mut unified_tags = UnifiedTags::new();
assert_eq!(
"test-version-1.2.3",
unified_tags.version.value.clone().unwrap()
);
unified_tags.set_version(Some(String::from("new_version")));
assert_eq!("new_version", unified_tags.version.value.unwrap());
});
}
}
2 changes: 1 addition & 1 deletion opentelemetry-user-events-metrics/src/tracepoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
// If tracepoint doesn't exist, it will create one automatically
let result = panic::catch_unwind(|| {
// CStr::from_bytes_with_nul_unchecked is ok because METRICS_EVENT_DEF ends with "\0".
trace_point.register(ffi::CStr::from_bytes_with_nul_unchecked(METRICS_EVENT_DEF))
unsafe { trace_point.register(ffi::CStr::from_bytes_with_nul_unchecked(METRICS_EVENT_DEF)) }

Check warning on line 88 in opentelemetry-user-events-metrics/src/tracepoint/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-user-events-metrics/src/tracepoint/mod.rs#L88

Added line #L88 was not covered by tests
});

match result {
Expand Down
2 changes: 1 addition & 1 deletion stress/src/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
#[inline(always)]
unsafe fn increment(&self, i: usize) {
let value = self.slice[i].get();
(*value).count += 1;
unsafe { (*value).count += 1 };

Check warning on line 158 in stress/src/throughput.rs

View check run for this annotation

Codecov / codecov/patch

stress/src/throughput.rs#L158

Added line #L158 was not covered by tests
}

#[inline(always)]
Expand Down
Loading