Skip to content

Commit ce9fe47

Browse files
committed
chore(x-goog-spanner-request-id): set span attribute x_goog_spanner_request_id
This sets the span attribute x_goog_spanner_request_id so as to enable correlation with distributed tracing with OpenTelemetry. Updates #3537
1 parent 0906eac commit ce9fe47

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/XGoogSpannerRequestId.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,8 @@ public XGoogSpannerRequestId nextRequestId(long channelId, int attempt) {
159159
return XGoogSpannerRequestId.of(1, 1, 1, 0);
160160
}
161161
}
162+
163+
public static String getRequestIdFromMetadata(Metadata md) {
164+
return md.get(REQUEST_HEADER_KEY);
165+
}
162166
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.cloud.spanner.CompositeTracer;
2929
import com.google.cloud.spanner.SpannerExceptionFactory;
3030
import com.google.cloud.spanner.SpannerRpcMetrics;
31+
import com.google.cloud.spanner.XGoogSpannerRequestId;
3132
import com.google.common.cache.Cache;
3233
import com.google.common.cache.CacheBuilder;
3334
import com.google.spanner.admin.database.v1.DatabaseName;
@@ -174,6 +175,10 @@ private void processHeader(
174175
}
175176
if (span != null) {
176177
span.setAttribute("gfe_latency", String.valueOf(gfeLatency));
178+
String reqId = XGoogSpannerRequestId.getRequestIdFromMetadata(metadata);
179+
if (reqId != null) {
180+
span.setAttribute("x_goog_spanner_request_id", reqId);
181+
}
177182
}
178183
} else {
179184
measureMap.put(SPANNER_GFE_HEADER_MISSING_COUNT, 1L).record(tagContext);

0 commit comments

Comments
 (0)