Skip to content

Commit 56e28bc

Browse files
authored
Change the gRPC o11y logName when sending logs to GCP. (grpc#9145)
* Change the gRPC o11y logName when sending logs to GCP.
1 parent ecb2210 commit 56e28bc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

gcp-observability/src/main/java/io/grpc/gcp/observability/logging/GcpLogSink.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class GcpLogSink implements Sink {
4747

4848
// TODO(DNVindhya): Make cloud logging service a configurable value
4949
private static final String SERVICE_TO_EXCLUDE = "google.logging.v2.LoggingServiceV2";
50-
private static final String DEFAULT_LOG_NAME = "grpc";
50+
private static final String DEFAULT_LOG_NAME =
51+
"microservices.googleapis.com%2Fobservability%2Fgrpc";
5152
private static final String K8S_MONITORED_RESOURCE_TYPE = "k8s_container";
5253
private static final Set<String> kubernetesResourceLabelSet
5354
= ImmutableSet.of("project_id", "location", "cluster_name", "namespace_name",
@@ -202,4 +203,4 @@ public synchronized void close() {
202203
logger.log(Level.SEVERE, "Caught exception while closing", e);
203204
}
204205
}
205-
}
206+
}

gcp-observability/src/test/java/io/grpc/gcp/observability/logging/GcpLogSinkTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class GcpLogSinkTest {
6565
private static final Map<String, String> customTags = ImmutableMap.of("KEY1", "Value1",
6666
"KEY2", "VALUE2");
6767
private static final long flushLimit = 10L;
68+
// gRPC is expected to alway use this log name when reporting to GCP cloud logging.
69+
private static final String expectedLogName =
70+
"microservices.googleapis.com%2Fobservability%2Fgrpc";
6871
private final long seqId = 1;
6972
private final String destProjectName = "PROJECT";
7073
private final String serviceName = "service";
@@ -122,6 +125,7 @@ public void verifyWrite() throws Exception {
122125
LogEntry entry = it.next();
123126
System.out.println(entry);
124127
assertThat(entry.getPayload().getData()).isEqualTo(expectedStructLogProto);
128+
assertThat(entry.getLogName()).isEqualTo(expectedLogName);
125129
}
126130
verifyNoMoreInteractions(mockLogging);
127131
}
@@ -143,6 +147,7 @@ public void verifyWriteWithTags() {
143147
assertThat(entry.getResource()).isEqualTo(expectedMonitoredResource);
144148
assertThat(entry.getLabels()).isEqualTo(customTags);
145149
assertThat(entry.getPayload().getData()).isEqualTo(expectedStructLogProto);
150+
assertThat(entry.getLogName()).isEqualTo(expectedLogName);
146151
}
147152
verifyNoMoreInteractions(mockLogging);
148153
}

0 commit comments

Comments
 (0)