Skip to content

Commit 5aed1d6

Browse files
committed
setup testing macros to print to stdout for test purposes
1 parent 36c750b commit 5aed1d6

File tree

1 file changed

+75
-8
lines changed

1 file changed

+75
-8
lines changed

opentelemetry/src/global/internal_logging.rs

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
/// **internally within OpenTelemetry code** or for **custom exporters, processors and other plugins**. They are not designed
55
/// for general application logging and should not be used for that purpose.
66
///
7+
/// When running tests with `--nocapture`, these macros will print their output to stdout. This is useful for debugging
8+
/// test failures and understanding the flow of operations during testing.
9+
///
710
/// Macro for logging informational messages in OpenTelemetry.
811
///
912
/// # Fields:
@@ -25,7 +28,13 @@ macro_rules! otel_info {
2528
{
2629
tracing::info!( name: $name, target: env!("CARGO_PKG_NAME"), name = $name, "");
2730
}
28-
#[cfg(not(feature = "internal-logs"))]
31+
32+
#[cfg(test)]
33+
{
34+
print!("otel_info: name={}\n", $name);
35+
}
36+
37+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
2938
{
3039
let _ = $name; // Compiler will optimize this out as it's unused.
3140
}
@@ -35,7 +44,17 @@ macro_rules! otel_info {
3544
{
3645
tracing::info!(name: $name, target: env!("CARGO_PKG_NAME"), name = $name, $($key = $value),+, "");
3746
}
38-
#[cfg(not(feature = "internal-logs"))]
47+
48+
#[cfg(test)]
49+
{
50+
print!("otel_info: name={}", $name);
51+
$(
52+
print!(", {}={}", stringify!($key), $value);
53+
)+
54+
print!("\n");
55+
}
56+
57+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
3958
{
4059
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
4160
}
@@ -60,7 +79,13 @@ macro_rules! otel_warn {
6079
{
6180
tracing::warn!(name: $name, target: env!("CARGO_PKG_NAME"), name = $name, "");
6281
}
63-
#[cfg(not(feature = "internal-logs"))]
82+
83+
#[cfg(test)]
84+
{
85+
print!("otel_warn: name={}\n", $name);
86+
}
87+
88+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
6489
{
6590
let _ = $name; // Compiler will optimize this out as it's unused.
6691
}
@@ -77,7 +102,17 @@ macro_rules! otel_warn {
77102
""
78103
)
79104
}
80-
#[cfg(not(feature = "internal-logs"))]
105+
106+
#[cfg(test)]
107+
{
108+
print!("otel_warn: name={}", $name);
109+
$(
110+
print!(", {}={}", stringify!($key), $value);
111+
)+
112+
print!("\n");
113+
}
114+
115+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
81116
{
82117
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
83118
}
@@ -102,7 +137,13 @@ macro_rules! otel_debug {
102137
{
103138
tracing::debug!(name: $name, target: env!("CARGO_PKG_NAME"), name = $name, "");
104139
}
105-
#[cfg(not(feature = "internal-logs"))]
140+
141+
#[cfg(test)]
142+
{
143+
print!("otel_debug: name={}\n", $name);
144+
}
145+
146+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
106147
{
107148
let _ = $name; // Compiler will optimize this out as it's unused.
108149
}
@@ -112,7 +153,17 @@ macro_rules! otel_debug {
112153
{
113154
tracing::debug!(name: $name, target: env!("CARGO_PKG_NAME"), name = $name, $($key = $value),+, "");
114155
}
115-
#[cfg(not(feature = "internal-logs"))]
156+
157+
#[cfg(test)]
158+
{
159+
print!("otel_debug: name={}", $name);
160+
$(
161+
print!(", {}={}", stringify!($key), $value);
162+
)+
163+
print!("\n");
164+
}
165+
166+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
116167
{
117168
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
118169
}
@@ -137,7 +188,13 @@ macro_rules! otel_error {
137188
{
138189
tracing::error!(name: $name, target: env!("CARGO_PKG_NAME"), name = $name, "");
139190
}
140-
#[cfg(not(feature = "internal-logs"))]
191+
192+
#[cfg(test)]
193+
{
194+
print!("otel_error: name={}\n", $name);
195+
}
196+
197+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
141198
{
142199
let _ = $name; // Compiler will optimize this out as it's unused.
143200
}
@@ -154,7 +211,17 @@ macro_rules! otel_error {
154211
""
155212
)
156213
}
157-
#[cfg(not(feature = "internal-logs"))]
214+
215+
#[cfg(test)]
216+
{
217+
print!("otel_error: name={}", $name);
218+
$(
219+
print!(", {}={}", stringify!($key), $value);
220+
)+
221+
print!("\n");
222+
}
223+
224+
#[cfg(all(not(feature = "internal-logs"), not(test)))]
158225
{
159226
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
160227
}

0 commit comments

Comments
 (0)