@@ -1879,6 +1879,124 @@ public void Logger_Dispose_DoesCaptureLog()
18791879 hub . Logger . Should ( ) . BeOfType < DefaultSentryStructuredLogger > ( ) ;
18801880 }
18811881
1882+ [ Fact ]
1883+ public void Metrics_IsDisabled_DoesNotCaptureMetric ( )
1884+ {
1885+ // Arrange
1886+ _fixture . Options . Experimental . EnableMetrics = false ;
1887+ var hub = _fixture . GetSut ( ) ;
1888+
1889+ // Act
1890+ hub . Metrics . EmitCounter ( "sentry_tests.hub_tests.counter" , 1 ) ;
1891+ hub . Metrics . Flush ( ) ;
1892+
1893+ // Assert
1894+ _fixture . Client . Received ( 0 ) . CaptureEnvelope (
1895+ Arg . Is < Envelope > ( envelope =>
1896+ envelope . Items . Single ( item => item . Header [ "type" ] . Equals ( "trace_metric" ) ) . Payload . GetType ( ) . IsAssignableFrom ( typeof ( JsonSerializable ) )
1897+ )
1898+ ) ;
1899+ hub . Metrics . Should ( ) . BeOfType < DisabledSentryTraceMetrics > ( ) ;
1900+ }
1901+
1902+ [ Fact ]
1903+ public void Metrics_IsEnabled_DoesCaptureMetric ( )
1904+ {
1905+ // Arrange
1906+ Assert . True ( _fixture . Options . Experimental . EnableMetrics ) ;
1907+ var hub = _fixture . GetSut ( ) ;
1908+
1909+ // Act
1910+ hub . Metrics . EmitCounter ( "sentry_tests.hub_tests.counter" , 1 ) ;
1911+ hub . Metrics . Flush ( ) ;
1912+
1913+ // Assert
1914+ _fixture . Client . Received ( 1 ) . CaptureEnvelope (
1915+ Arg . Is < Envelope > ( envelope =>
1916+ envelope . Items . Single ( item => item . Header [ "type" ] . Equals ( "trace_metric" ) ) . Payload . GetType ( ) . IsAssignableFrom ( typeof ( JsonSerializable ) )
1917+ )
1918+ ) ;
1919+ hub . Metrics . Should ( ) . BeOfType < DefaultSentryTraceMetrics > ( ) ;
1920+ }
1921+
1922+ [ Fact ]
1923+ public void Metrics_EnableAfterCreate_HasNoEffect ( )
1924+ {
1925+ // Arrange
1926+ _fixture . Options . Experimental . EnableMetrics = false ;
1927+ var hub = _fixture . GetSut ( ) ;
1928+
1929+ // Act
1930+ _fixture . Options . Experimental . EnableMetrics = true ;
1931+
1932+ // Assert
1933+ hub . Metrics . Should ( ) . BeOfType < DisabledSentryTraceMetrics > ( ) ;
1934+ }
1935+
1936+ [ Fact ]
1937+ public void Metrics_DisableAfterCreate_HasNoEffect ( )
1938+ {
1939+ // Arrange
1940+ Assert . True ( _fixture . Options . Experimental . EnableMetrics ) ;
1941+ var hub = _fixture . GetSut ( ) ;
1942+
1943+ // Act
1944+ _fixture . Options . Experimental . EnableMetrics = false ;
1945+
1946+ // Assert
1947+ hub . Metrics . Should ( ) . BeOfType < DefaultSentryTraceMetrics > ( ) ;
1948+ }
1949+
1950+ [ Fact ]
1951+ public async Task Metrics_FlushAsync_DoesCaptureMetric ( )
1952+ {
1953+ // Arrange
1954+ Assert . True ( _fixture . Options . Experimental . EnableMetrics ) ;
1955+ var hub = _fixture . GetSut ( ) ;
1956+
1957+ // Act
1958+ hub . Metrics . EmitCounter ( "sentry_tests.hub_tests.counter" , 1 ) ;
1959+ await hub . FlushAsync ( ) ;
1960+
1961+ // Assert
1962+ _fixture . Client . Received ( 1 ) . CaptureEnvelope (
1963+ Arg . Is < Envelope > ( envelope =>
1964+ envelope . Items . Single ( item => item . Header [ "type" ] . Equals ( "trace_metric" ) ) . Payload . GetType ( ) . IsAssignableFrom ( typeof ( JsonSerializable ) )
1965+ )
1966+ ) ;
1967+ await _fixture . Client . Received ( 1 ) . FlushAsync (
1968+ Arg . Is < TimeSpan > ( timeout =>
1969+ timeout . Equals ( _fixture . Options . FlushTimeout )
1970+ )
1971+ ) ;
1972+ hub . Metrics . Should ( ) . BeOfType < DefaultSentryTraceMetrics > ( ) ;
1973+ }
1974+
1975+ [ Fact ]
1976+ public void Metrics_Dispose_DoesCaptureMetric ( )
1977+ {
1978+ // Arrange
1979+ Assert . True ( _fixture . Options . Experimental . EnableMetrics ) ;
1980+ var hub = _fixture . GetSut ( ) ;
1981+
1982+ // Act
1983+ hub . Metrics . EmitCounter ( "sentry_tests.hub_tests.counter" , 1 ) ;
1984+ hub . Dispose ( ) ;
1985+
1986+ // Assert
1987+ _fixture . Client . Received ( 1 ) . CaptureEnvelope (
1988+ Arg . Is < Envelope > ( envelope =>
1989+ envelope . Items . Single ( item => item . Header [ "type" ] . Equals ( "trace_metric" ) ) . Payload . GetType ( ) . IsAssignableFrom ( typeof ( JsonSerializable ) )
1990+ )
1991+ ) ;
1992+ _fixture . Client . Received ( 1 ) . FlushAsync (
1993+ Arg . Is < TimeSpan > ( timeout =>
1994+ timeout . Equals ( _fixture . Options . ShutdownTimeout )
1995+ )
1996+ ) ;
1997+ hub . Metrics . Should ( ) . BeOfType < DefaultSentryTraceMetrics > ( ) ;
1998+ }
1999+
18822000 [ Fact ]
18832001 public void Dispose_IsEnabled_SetToFalse ( )
18842002 {
0 commit comments