Skip to content

Commit 926fd8c

Browse files
authored
feat: adding gcp resource name span attribute (#2260)
Adding a new span attribute called `gcp.resource.name` which contains an identifier to a particular firestore database in the following format: ``` //firestore.googleapis.com/projects/{project}/databases/{database_id} ``` Example: ``` //firestore.googleapis.com/projects/my_project/databases/(default) ```
1 parent 5ade48a commit 926fd8c

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ private SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder)
283283
spanBuilder =
284284
spanBuilder.setAllAttributes(
285285
Attributes.builder()
286+
.put(
287+
ATTRIBUTE_GCP_RESOURCE_NAME,
288+
String.format(
289+
ATTRIBUTE_GCP_RESOURCE_NAME_FORMAT,
290+
firestoreOptions.getProjectId(),
291+
firestoreOptions.getDatabaseId()))
286292
.put(
287293
ATTRIBUTE_SERVICE_PREFIX + "settings.project_id",
288294
firestoreOptions.getProjectId())

google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/TraceUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public interface TraceUtil {
4040
String ATTRIBUTE_KEY_TRANSACTION_TYPE = "transaction_type";
4141
String ATTRIBUTE_KEY_ATTEMPTS_ALLOWED = "attempts_allowed";
4242
String ATTRIBUTE_KEY_ATTEMPTS_REMAINING = "attempts_remaining";
43+
String ATTRIBUTE_GCP_RESOURCE_NAME = "gcp.resource.name";
44+
String ATTRIBUTE_GCP_RESOURCE_NAME_FORMAT = "//firestore.googleapis.com/projects/%s/databases/%s";
4345

4446
String ENABLE_TRACING_ENV_VAR = "FIRESTORE_ENABLE_TRACING";
4547
String LIBRARY_NAME = "com.google.cloud.firestore";

google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITTracingTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ void assertHasExpectedAttributes(SpanData spanData, String... additionalExpected
281281
// All Firestore-generated spans have the settings attributes.
282282
List<String> expectedAttributes =
283283
Arrays.asList(
284+
"gcp.resource.name",
284285
"gcp.firestore.memory_utilization",
285286
"gcp.firestore.settings.host",
286287
"gcp.firestore.settings.project_id",

0 commit comments

Comments
 (0)