29
29
import org .junit .jupiter .api .BeforeEach ;
30
30
import org .junit .jupiter .api .extension .ExtendWith ;
31
31
import org .junit .jupiter .api .io .TempDir ;
32
+ import org .sonarsource .sonarlint .core .commons .monitoring .DogfoodEnvironmentDetectionService ;
32
33
import org .sonarsource .sonarlint .core .commons .monitoring .MonitoringService ;
33
34
import org .sonarsource .sonarlint .core .rpc .protocol .backend .analysis .AnalyzeFilesAndTrackParams ;
34
35
import org .sonarsource .sonarlint .core .rpc .protocol .backend .file .DidUpdateFileSystemParams ;
37
38
import org .sonarsource .sonarlint .core .rpc .protocol .common .Language ;
38
39
import org .sonarsource .sonarlint .core .test .utils .junit5 .SonarLintTest ;
39
40
import org .sonarsource .sonarlint .core .test .utils .junit5 .SonarLintTestHarness ;
41
+ import uk .org .webcompere .systemstubs .environment .EnvironmentVariables ;
42
+ import uk .org .webcompere .systemstubs .jupiter .SystemStub ;
40
43
import uk .org .webcompere .systemstubs .jupiter .SystemStubsExtension ;
41
44
import utils .TestPlugin ;
42
45
@@ -57,12 +60,16 @@ class MonitoringMediumTests {
57
60
private static final String CONFIGURATION_SCOPE_ID = "configScopeId" ;
58
61
private WireMockServer sentryServer ;
59
62
63
+ @ SystemStub
64
+ private EnvironmentVariables environmentVariables ;
65
+
60
66
@ BeforeEach
61
67
void setup () {
62
68
sentryServer = new WireMockServer (wireMockConfig ().dynamicPort ());
63
69
sentryServer .start ();
64
70
System .setProperty (MonitoringService .DSN_PROPERTY , createValidSentryDsn (sentryServer ));
65
71
System .setProperty (MonitoringService .TRACES_SAMPLE_RATE_PROPERTY , "1" );
72
+ environmentVariables .set (DogfoodEnvironmentDetectionService .SONARSOURCE_DOGFOODING_ENV_VAR_KEY , "1" );
66
73
setupSentryStubs ();
67
74
}
68
75
@@ -114,6 +121,9 @@ function writeMsg($fname) {
114
121
var issues = analyzeFileAndGetIssues (inputFile .toUri (), client , backend , CONFIGURATION_SCOPE_ID );
115
122
116
123
assertThat (issues ).extracting (RaisedIssueDto ::getRuleKey , i -> i .getTextRange ().getStartLine ()).contains (tuple ("php:S1172" , 2 ));
124
+
125
+ // The mock Sentry server receives 1 event for the analysis trace
126
+ await ().atMost (1 , TimeUnit .SECONDS ).untilAsserted (() -> assertThat (sentryServer .getAllServeEvents ()).hasSize (1 ));
117
127
}
118
128
119
129
@ SonarLintTest
@@ -148,6 +158,12 @@ function writeMsg($fname) {
148
158
.join ();
149
159
assertThat (analysisResult .getFailedAnalysisFiles ()).isEmpty ();
150
160
await ().during (2 , TimeUnit .SECONDS ).untilAsserted (() -> assertThat (client .getRaisedIssuesForScopeIdAsList (CONFIGURATION_SCOPE_ID )).isEmpty ());
161
+ // The mock Sentry server receives 2 events: one for the trace, one for the exception
162
+ await ().atMost (1 , TimeUnit .SECONDS ).untilAsserted (() -> assertThat (sentryServer .getAllServeEvents ()).hasSize (2 ));
163
+ assertThat (sentryServer .getAllServeEvents ())
164
+ .extracting (e -> e .getRequest ().getBodyAsString ())
165
+ // Server name should be removed from events
166
+ .noneMatch (m -> m .contains ("server_name" ));
151
167
}
152
168
153
169
@ SonarLintTest
0 commit comments