Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 98275f5

Browse files
committed
chore: Add gcp resource name span attribute
1 parent da58b02 commit 98275f5

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class TraceWrapper {
5555
AttributeKey.stringKey("gcp.client.version");
5656
private static final AttributeKey<String> GCP_CLIENT_REPO_KEY =
5757
AttributeKey.stringKey("gcp.client.repo");
58+
private static final AttributeKey<String> GCP_RESOURCE_NAME_KEY =
59+
AttributeKey.stringKey("gcp.resource.name");
5860
private static final AttributeKey<String> THREAD_NAME_KEY = AttributeKey.stringKey("thread.name");
5961

6062
private final Tracer openCensusTracer;
@@ -219,6 +221,7 @@ Attributes createDatabaseAttributes(DatabaseId db) {
219221
AttributesBuilder builder = Attributes.builder();
220222
builder.put(DB_NAME_KEY, db.getDatabase());
221223
builder.put(INSTANCE_NAME_KEY, db.getInstanceId().getInstance());
224+
builder.put(GCP_RESOURCE_NAME_KEY, "//spanner.googleapis.com/" + db.getName());
222225
return builder.build();
223226
}
224227

google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,9 @@ private static void verifyCommonAttributes(SpanData span) {
912912
assertEquals(
913913
span.getAttributes().get(AttributeKey.stringKey("gcp.client.version")),
914914
GaxProperties.getLibraryVersion(TraceWrapper.class));
915+
assertEquals(
916+
span.getAttributes().get(AttributeKey.stringKey("gcp.resource.name")),
917+
"//spanner.googleapis.com/projects/my-project/instances/my-instance/databases/my-database");
915918
}
916919

917920
private static void verifyTableAttributes(SpanData span) {

0 commit comments

Comments
 (0)