@@ -166,6 +166,7 @@ func (s) TestClientRPCEventsLogAll(t *testing.T) {
166166 if _ , err := ss .Client .UnaryCall (ctx , & grpc_testing.SimpleRequest {}); err != nil {
167167 t .Fatalf ("Unexpected error from UnaryCall: %v" , err )
168168 }
169+
169170 grpcLogEntriesWant := []* grpcLogEntry {
170171 {
171172 Type : eventTypeClientHeader ,
@@ -1056,6 +1057,65 @@ func (s) TestTranslateMetadata(t *testing.T) {
10561057 }
10571058}
10581059
1060+ // TestCloudLoggingAPICallsFiltered tests that the observability plugin does not
1061+ // emit logs for cloud logging API calls.
1062+ func (s ) TestCloudLoggingAPICallsFiltered (t * testing.T ) {
1063+ fle := & fakeLoggingExporter {
1064+ t : t ,
1065+ }
1066+
1067+ defer func (ne func (ctx context.Context , config * config ) (loggingExporter , error )) {
1068+ newLoggingExporter = ne
1069+ }(newLoggingExporter )
1070+
1071+ newLoggingExporter = func (ctx context.Context , config * config ) (loggingExporter , error ) {
1072+ return fle , nil
1073+ }
1074+ configLogAll := & config {
1075+ ProjectID : "fake" ,
1076+ CloudLogging : & cloudLogging {
1077+ ClientRPCEvents : []clientRPCEvents {
1078+ {
1079+ Methods : []string {"*" },
1080+ MaxMetadataBytes : 30 ,
1081+ MaxMessageBytes : 30 ,
1082+ },
1083+ },
1084+ },
1085+ }
1086+ cleanup , err := setupObservabilitySystemWithConfig (configLogAll )
1087+ if err != nil {
1088+ t .Fatalf ("error setting up observability %v" , err )
1089+ }
1090+ defer cleanup ()
1091+
1092+ ss := & stubserver.StubServer {}
1093+ if err := ss .Start (nil ); err != nil {
1094+ t .Fatalf ("Error starting endpoint server: %v" , err )
1095+ }
1096+ defer ss .Stop ()
1097+
1098+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
1099+ defer cancel ()
1100+
1101+ // Any of the three cloud logging API calls should not cause any logs to be
1102+ // emitted, even though the configuration specifies to log any rpc
1103+ // regardless of method.
1104+ req := & grpc_testing.SimpleRequest {}
1105+ resp := & grpc_testing.SimpleResponse {}
1106+
1107+ ss .CC .Invoke (ctx , "/google.logging.v2.LoggingServiceV2/some-method" , req , resp )
1108+ ss .CC .Invoke (ctx , "/google.monitoring.v3.MetricService/some-method" , req , resp )
1109+ ss .CC .Invoke (ctx , "/google.devtools.cloudtrace.v2.TraceService/some-method" , req , resp )
1110+ // The exporter should have received no new log entries due to these three
1111+ // calls, as they should be filtered out.
1112+ fle .mu .Lock ()
1113+ defer fle .mu .Unlock ()
1114+ if len (fle .entries ) != 0 {
1115+ t .Fatalf ("Unexpected length of entries %v, want 0" , len (fle .entries ))
1116+ }
1117+ }
1118+
10591119func (s ) TestMarshalJSON (t * testing.T ) {
10601120 logEntry := & grpcLogEntry {
10611121 CallID : "300-300-300" ,
0 commit comments