@@ -91,14 +91,14 @@ class JdbcConnection extends AbstractJdbcConnection {
91
91
92
92
private final Metrics metrics ;
93
93
94
- private final Attributes openTelemetryAttributes ;
94
+ private final Attributes openTelemetryMetricsAttributes ;
95
95
96
96
JdbcConnection (String connectionUrl , ConnectionOptions options ) throws SQLException {
97
97
super (connectionUrl , options );
98
98
this .useLegacyIsValidCheck = useLegacyValidCheck ();
99
99
OpenTelemetry openTelemetry = getSpanner ().getOptions ().getOpenTelemetry ();
100
- this .openTelemetryAttributes =
101
- createOpenTelemetryAttributes (getConnectionOptions ().getDatabaseId ());
100
+ this .openTelemetryMetricsAttributes =
101
+ createOpenTelemetryAttributes (getConnectionOptions ().getDatabaseId (), false );
102
102
this .metrics = new Metrics (openTelemetry );
103
103
}
104
104
@@ -114,17 +114,21 @@ static boolean useLegacyValidCheck() {
114
114
}
115
115
116
116
@ VisibleForTesting
117
- static Attributes createOpenTelemetryAttributes (DatabaseId databaseId ) {
117
+ static Attributes createOpenTelemetryAttributes (
118
+ DatabaseId databaseId , boolean includeConnectionId ) {
118
119
AttributesBuilder attributesBuilder = Attributes .builder ();
119
- attributesBuilder .put ("connection_id" , UUID .randomUUID ().toString ());
120
+ // A unique connection ID should only be included for tracing and not for metrics.
121
+ if (includeConnectionId ) {
122
+ attributesBuilder .put ("connection_id" , UUID .randomUUID ().toString ());
123
+ }
120
124
attributesBuilder .put ("database" , databaseId .getDatabase ());
121
125
attributesBuilder .put ("instance_id" , databaseId .getInstanceId ().getInstance ());
122
126
attributesBuilder .put ("project_id" , databaseId .getInstanceId ().getProject ());
123
127
return attributesBuilder .build ();
124
128
}
125
129
126
130
public void recordClientLibLatencyMetric (long value ) {
127
- metrics .recordClientLibLatency (value , openTelemetryAttributes );
131
+ metrics .recordClientLibLatency (value , openTelemetryMetricsAttributes );
128
132
}
129
133
130
134
@ Override
0 commit comments