33
33
import jdk .jfr .consumer .RecordedEvent ;
34
34
import jdk .jfr .consumer .RecordingFile ;
35
35
import oracle .jdbc .DatabaseFunction ;
36
+ import oracle .jdbc .driver .OracleConnection ;
36
37
import oracle .jdbc .provider .TestProperties ;
37
38
import oracle .jdbc .provider .observability .configuration .ObservabilityConfiguration ;
38
39
@@ -70,11 +71,13 @@ public void JFRTraceTest(boolean sensitiveDataEnabled) throws Exception {
70
71
ObservabilityConfiguration .getInstance ().setEnabledTracers ("JFR" );
71
72
ObservabilityConfiguration .getInstance ().setSensitiveDataEnabled (sensitiveDataEnabled );
72
73
Configuration configuration = Configuration .getConfiguration ("default" );
74
+ String connectionId = null ;
73
75
try (Recording recording = new Recording (configuration )) {
74
76
recording .start ();
75
77
try (Connection connection = DriverManager .getConnection (url , userName , password );
76
78
Statement statement = connection .createStatement ();
77
79
ResultSet resultSet = statement .executeQuery ("SELECT 'OK' FROM DUAL" )) {
80
+ connectionId = ((OracleConnection )connection ).getNetConnectionId ();
78
81
while (resultSet .next ()) {
79
82
assertEquals ("OK" , resultSet .getString (1 ));
80
83
}
@@ -88,7 +91,7 @@ public void JFRTraceTest(boolean sensitiveDataEnabled) throws Exception {
88
91
if (event .getEventType ().getCategoryNames ().contains ("Round trips" )) {
89
92
switch (event .getEventType ().getName ()) {
90
93
case SESSION_KEY :
91
- assertNotNull ( event .getString ("connectionID" ));
94
+ assertEquals ( connectionId , event .getString ("connectionID" ));
92
95
assertNotNull (event .getString ("databaseOperation" ));
93
96
// assertNull(event.getString("tenant"));
94
97
assertNull (event .getString ("sqlID" ));
@@ -97,7 +100,7 @@ public void JFRTraceTest(boolean sensitiveDataEnabled) throws Exception {
97
100
assertEquals (sensitiveDataEnabled , event .getString ("databaseUser" ) != null );
98
101
break ;
99
102
case AUTH_CALL :
100
- assertNotNull ( event .getString ("connectionID" ));
103
+ assertEquals ( connectionId , event .getString ("connectionID" ));
101
104
assertNotNull (event .getString ("databaseOperation" ));
102
105
// assertNull(event.getString("tenant"));
103
106
assertNull (event .getString ("sqlID" ));
@@ -107,7 +110,7 @@ public void JFRTraceTest(boolean sensitiveDataEnabled) throws Exception {
107
110
108
111
break ;
109
112
case EXECUTE_QUERY :
110
- assertNotNull ( event .getString ("connectionID" ));
113
+ assertEquals ( connectionId , event .getString ("connectionID" ));
111
114
assertNotNull (event .getString ("databaseOperation" ));
112
115
// assertNotNull(event.getString("tenant"));
113
116
assertNotNull (event .getString ("sqlID" ));
@@ -116,7 +119,7 @@ public void JFRTraceTest(boolean sensitiveDataEnabled) throws Exception {
116
119
assertEquals (sensitiveDataEnabled , event .getString ("databaseUser" ) != null );
117
120
break ;
118
121
case LOGOFF :
119
- assertNotNull ( event .getString ("connectionID" ));
122
+ assertEquals ( connectionId , event .getString ("connectionID" ));
120
123
assertNotNull (event .getString ("databaseOperation" ));
121
124
// assertNotNull(event.getString("tenant"));
122
125
assertNull (event .getString ("sqlID" ));
@@ -141,10 +144,11 @@ public void OTELTraceTest(boolean sensitiveDataEnabled) throws Exception {
141
144
ObservabilityConfiguration .getInstance ().setEnabledTracers ("OTEL" );
142
145
ObservabilityConfiguration .getInstance ().setSensitiveDataEnabled (sensitiveDataEnabled );
143
146
String otelUrl = url + "?oracle.jdbc.provider.traceEventListener=observability-trace-event-listener-provider" ;
147
+ String connectionId = null ;
144
148
try (Connection connection = DriverManager .getConnection (otelUrl , userName , password );
145
149
Statement statement = connection .createStatement ();
146
150
ResultSet resultSet = statement .executeQuery ("SELECT 'OK' FROM DUAL" )) {
147
-
151
+ connectionId = (( OracleConnection ) connection ). getNetConnectionId ();
148
152
while (resultSet .next ()) {
149
153
assertEquals ("OK" , resultSet .getString (1 ));
150
154
}
@@ -157,6 +161,7 @@ public void OTELTraceTest(boolean sensitiveDataEnabled) throws Exception {
157
161
Mockito .verify (spanBuilder , atLeastOnce ()).startSpan ();
158
162
Mockito .verify (spanBuilder , Mockito .atLeast (4 )).setAttribute ("thread.id" , Thread .currentThread ().getId ());
159
163
Mockito .verify (spanBuilder , Mockito .atLeast (4 )).setAttribute ("thread.name" , Thread .currentThread ().getName ());
164
+ Mockito .verify (spanBuilder , Mockito .atLeast (1 )).setAttribute ("Connection ID" , connectionId );
160
165
Mockito .verify (spanBuilder , Mockito .times (1 )).setAttribute ("Database Operation" , DatabaseFunction .SESSION_KEY .getDescription ());
161
166
Mockito .verify (spanBuilder , Mockito .times (1 )).setAttribute ("Database Operation" , DatabaseFunction .AUTH_CALL .getDescription ());
162
167
Mockito .verify (spanBuilder , Mockito .times (1 )).setAttribute ("Database Operation" , DatabaseFunction .EXECUTE_QUERY .getDescription ());
0 commit comments