This ticket is about the code here.
If you use the logging api, and specify the MonitoredResource
in theLogEntry
like so:
var logEntry = LogEntry.newBuilder(jsonPayload)
.setDestination(destination)
.setSeverity(severity)
.setLogName(logName)
.setTimestamp(request.timestamp())
.setResource(monitoredResource)
.build();
logging.write(List.of(logEntry));
A new MonitoredResource
will be constructed here. This can result in an HTTP-call (going through MonitoredResourceUtil::detectResourceType
and com.google.cloud.MetadataConfig#getAttribute
), which has a big performance impact.
A workaround is to change the above example to:
var logEntry = LogEntry.newBuilder(jsonPayload)
.setDestination(destination)
.setSeverity(severity)
.setLogName(logName)
.setTimestamp(request.timestamp())
.setResource(monitoredResource)
.build();
logging.write(List.of(logEntry), Logging.WriteOption.resource(monitoredResource));
But this shouldn't be needed if the LogEntry
has the MonitoredResource
.