@@ -48,12 +48,28 @@ fn sent_when_enabled() {
4848 } if name == "test" ) ) ;
4949}
5050
51+ /// Test that metrics are sent by default.
52+ #[ test]
53+ fn metrics_enabled_by_default ( ) {
54+ let options = ClientOptions :: default ( ) ;
55+
56+ let envelopes =
57+ test:: with_captured_envelopes_options ( || metrics:: counter ( "test" , 1 ) . capture ( ) , options) ;
58+ assert_eq ! (
59+ envelopes. len( ) ,
60+ 1 ,
61+ "expected exactly one envelope when metrics are enabled by default"
62+ )
63+ }
64+
5165/// Test that metrics are disabled (not sent) when disabled in the
5266/// [`ClientOptions`].
5367#[ test]
54- fn metrics_disabled_by_default ( ) {
55- // Metrics are disabled by default.
56- let options: ClientOptions = Default :: default ( ) ;
68+ fn metrics_disabled_when_configured ( ) {
69+ let options = ClientOptions {
70+ enable_metrics : false ,
71+ ..Default :: default ( )
72+ } ;
5773
5874 let envelopes =
5975 test:: with_captured_envelopes_options ( || metrics:: counter ( "test" , 1 ) . capture ( ) , options) ;
@@ -67,10 +83,7 @@ fn metrics_disabled_by_default() {
6783/// metrics enabled
6884#[ test]
6985fn noop_sends_nothing ( ) {
70- let options = ClientOptions {
71- enable_metrics : true ,
72- ..Default :: default ( )
73- } ;
86+ let options = ClientOptions :: default ( ) ;
7487
7588 let envelopes = test:: with_captured_envelopes_options ( || ( ) , options) ;
7689
@@ -80,10 +93,7 @@ fn noop_sends_nothing() {
8093/// Test that 100 metrics are sent in a single envelope.
8194#[ test]
8295fn test_metrics_batching_at_limit ( ) {
83- let options = ClientOptions {
84- enable_metrics : true ,
85- ..Default :: default ( )
86- } ;
96+ let options = ClientOptions :: default ( ) ;
8797
8898 let envelopes = test:: with_captured_envelopes_options (
8999 || {
@@ -133,10 +143,7 @@ fn test_metrics_batching_at_limit() {
133143/// Test that 101 envelopes are sent in two separate envelopes
134144#[ test]
135145fn test_metrics_batching_over_limit ( ) {
136- let options = ClientOptions {
137- enable_metrics : true ,
138- ..Default :: default ( )
139- } ;
146+ let options = ClientOptions :: default ( ) ;
140147
141148 let mut envelopes = test:: with_captured_envelopes_options (
142149 || {
@@ -207,10 +214,7 @@ fn test_metrics_batching_over_limit() {
207214
208215#[ test]
209216fn metric_attributes_are_captured ( ) {
210- let options = ClientOptions {
211- enable_metrics : true ,
212- ..Default :: default ( )
213- } ;
217+ let options = ClientOptions :: default ( ) ;
214218
215219 let envelopes = test:: with_captured_envelopes_options (
216220 || {
@@ -265,10 +269,7 @@ fn metric_attributes_are_captured() {
265269
266270#[ test]
267271fn metric_unit_is_captured ( ) {
268- let options = ClientOptions {
269- enable_metrics : true ,
270- ..Default :: default ( )
271- } ;
272+ let options = ClientOptions :: default ( ) ;
272273
273274 let envelopes = test:: with_captured_envelopes_options (
274275 || metrics:: gauge ( "test" , 42 ) . unit ( Unit :: Millisecond ) . capture ( ) ,
@@ -311,10 +312,7 @@ fn metric_unit_is_captured() {
311312/// This tests that trace ID is set from the propagation context when there is no active span.
312313#[ test]
313314fn metrics_share_trace_id_without_active_span ( ) {
314- let options = ClientOptions {
315- enable_metrics : true ,
316- ..Default :: default ( )
317- } ;
315+ let options = ClientOptions :: default ( ) ;
318316
319317 let envelopes = test:: with_captured_envelopes_options (
320318 || {
@@ -348,10 +346,7 @@ fn metrics_share_trace_id_without_active_span() {
348346/// Test that span_id is set from the active span when one is present.
349347#[ test]
350348fn metrics_span_id_from_active_span ( ) {
351- let options = ClientOptions {
352- enable_metrics : true ,
353- ..Default :: default ( )
354- } ;
349+ let options = ClientOptions :: default ( ) ;
355350
356351 let mut expected_span_id = None ;
357352 let envelopes = test:: with_captured_envelopes_options (
@@ -389,7 +384,6 @@ fn metrics_span_id_from_active_span() {
389384#[ test]
390385fn default_attributes_attached ( ) {
391386 let options = ClientOptions {
392- enable_metrics : true ,
393387 environment : Some ( "test-env" . into ( ) ) ,
394388 release : Some ( "1.0.0" . into ( ) ) ,
395389 server_name : Some ( "test-server" . into ( ) ) ,
@@ -417,10 +411,7 @@ fn default_attributes_attached() {
417411/// Test that optional default attributes are omitted when not configured.
418412#[ test]
419413fn optional_default_attributes_omitted_when_not_configured ( ) {
420- let options = ClientOptions {
421- enable_metrics : true ,
422- ..Default :: default ( )
423- } ;
414+ let options = ClientOptions :: default ( ) ;
424415
425416 let envelopes =
426417 test:: with_captured_envelopes_options ( || metrics:: counter ( "test" , 1 ) . capture ( ) , options) ;
@@ -442,7 +433,6 @@ fn optional_default_attributes_omitted_when_not_configured() {
442433#[ test]
443434fn default_attributes_do_not_overwrite_explicit ( ) {
444435 let options = ClientOptions {
445- enable_metrics : true ,
446436 environment : Some ( "default-env" . into ( ) ) ,
447437 ..Default :: default ( )
448438 } ;
@@ -475,7 +465,6 @@ fn default_attributes_do_not_overwrite_explicit() {
475465#[ test]
476466fn user_attributes_absent_without_send_default_pii ( ) {
477467 let options = ClientOptions {
478- enable_metrics : true ,
479468 send_default_pii : false ,
480469 ..Default :: default ( )
481470 } ;
@@ -513,7 +502,6 @@ fn user_attributes_absent_without_send_default_pii() {
513502#[ test]
514503fn metric_user_attributes_from_scope_are_applied_with_send_default_pii ( ) {
515504 let options = ClientOptions {
516- enable_metrics : true ,
517505 send_default_pii : true ,
518506 ..Default :: default ( )
519507 } ;
@@ -553,7 +541,6 @@ fn metric_user_attributes_from_scope_are_applied_with_send_default_pii() {
553541#[ test]
554542fn metric_user_attributes_do_not_overwrite_explicit ( ) {
555543 let options = ClientOptions {
556- enable_metrics : true ,
557544 send_default_pii : true ,
558545 ..Default :: default ( )
559546 } ;
@@ -594,7 +581,6 @@ fn metric_user_attributes_do_not_overwrite_explicit() {
594581#[ test]
595582fn before_send_metric_can_drop ( ) {
596583 let options = ClientOptions {
597- enable_metrics : true ,
598584 before_send_metric : Some ( Arc :: new ( |_| None ) ) ,
599585 ..Default :: default ( )
600586 } ;
@@ -611,7 +597,6 @@ fn before_send_metric_can_drop() {
611597#[ test]
612598fn before_send_metric_can_modify ( ) {
613599 let options = ClientOptions {
614- enable_metrics : true ,
615600 before_send_metric : Some ( Arc :: new ( |mut metric| {
616601 metric
617602 . attributes
0 commit comments