From d4bfa3638ee0d6f4bb115ea0fb893ae2fd0dcf3f Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Fri, 10 Jan 2025 12:06:30 +0530 Subject: [PATCH 1/2] feat: add gcp client attributes in OpenTelemetry traces --- .../java/com/google/cloud/spanner/TraceWrapper.java | 10 ++++++++++ .../google/cloud/spanner/OpenTelemetrySpanTest.java | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TraceWrapper.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TraceWrapper.java index 3e01eec1fb2..606a54fe8b7 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TraceWrapper.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TraceWrapper.java @@ -16,6 +16,7 @@ package com.google.cloud.spanner; +import com.google.api.gax.core.GaxProperties; import com.google.cloud.spanner.Options.TagOption; import com.google.cloud.spanner.Options.TransactionOption; import com.google.cloud.spanner.SpannerOptions.TracingFramework; @@ -46,6 +47,12 @@ class TraceWrapper { private static final AttributeKey> DB_STATEMENT_ARRAY_KEY = AttributeKey.stringArrayKey("db.statement"); private static final AttributeKey DB_TABLE_NAME_KEY = AttributeKey.stringKey("db.table"); + private static final AttributeKey GCP_CLIENT_SERVICE_KEY = + AttributeKey.stringKey("gcp.client.service"); + private static final AttributeKey GCP_CLIENT_VERSION_KEY = + AttributeKey.stringKey("gcp.client.version"); + private static final AttributeKey GCP_CLIENT_REPO_KEY = + AttributeKey.stringKey("gcp.client.repo"); private static final AttributeKey THREAD_NAME_KEY = AttributeKey.stringKey("thread.name"); private final Tracer openCensusTracer; @@ -204,6 +211,9 @@ Attributes createCommonAttributes(DatabaseId db) { AttributesBuilder builder = Attributes.builder(); builder.put(DB_NAME_KEY, db.getDatabase()); builder.put(INSTANCE_NAME_KEY, db.getInstanceId().getInstance()); + builder.put(GCP_CLIENT_SERVICE_KEY, "spanner"); + builder.put(GCP_CLIENT_REPO_KEY, "googleapis/java-spanner"); + builder.put(GCP_CLIENT_VERSION_KEY, GaxProperties.getLibraryVersion(TraceWrapper.class)); return builder.build(); } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java index 27e9cdb31f9..cbc449815e7 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import com.google.api.gax.core.GaxProperties; import com.google.api.gax.grpc.testing.LocalChannelProvider; import com.google.cloud.NoCredentials; import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult; @@ -871,6 +872,13 @@ private static void verifySpans(List actualSpanItems, List expec private static void verifyCommonAttributes(SpanData span) { assertEquals(span.getAttributes().get(AttributeKey.stringKey("instance.name")), "my-instance"); assertEquals(span.getAttributes().get(AttributeKey.stringKey("db.name")), "my-database"); + assertEquals(span.getAttributes().get(AttributeKey.stringKey("gcp.client.service")), "spanner"); + assertEquals( + span.getAttributes().get(AttributeKey.stringKey("gcp.client.repo")), + "googleapis/java-spanner"); + assertEquals( + span.getAttributes().get(AttributeKey.stringKey("gcp.client.version")), + GaxProperties.getLibraryVersion(TraceWrapper.class)); } private static void verifyTableAttributes(SpanData span) { From 0f54d6f678712e97fb7f955e4d19f517472f404c Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Fri, 10 Jan 2025 07:00:59 +0000 Subject: [PATCH 2/2] chore: generate libraries at Fri Jan 10 06:58:52 UTC 2025 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a64487c221e..0718c5d7de8 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies: com.google.cloud google-cloud-spanner - 6.81.1 + 6.84.0 ```