Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error with GCP Logging API in Go: rpc error: code = Canceled desc = The operation was cancelled

Hello,

I am encountering an intermittent issue while developing with Go and using the GCP Logging API to fetch log entries. The process fails with the following error message on the first attempt but succeeds on subsequent attempts:

error:

rpc error: code = Canceled desc = The operation was cancelled

 

ex)

func main() {

ctx := context.Background() client, err := logadmin.NewClient(ctx, "YOUR_PROJECT_ID")

if err != nil {

   log.Fatalf("Failed to create client: %v", err)

}

req := &logadmin.ListLogEntriesRequest{

   ResourceNames: []string{"projects/YOUR_PROJECT_ID"},

   Filter: `timestamp >= "2024-05-27T07:05:00Z" AND timestamp <= "2024-05-27T07:11:00Z"`,

}

it := client.Entries(ctx, req)

for {

    entry, err := it.Next()

    if err == iterator.Done {

               break

     }

  return

}


  1. What could be causing the What could be causing the rpc error: code = Canceled desc = The operation was cancelled error on the first attempt?

  2. Are there any specific configurations or additional settings I need to check or modify to resolve this issue?

 

1 0 300
0 REPLIES 0
Top Solution Authors