Skip to content

Google Cloud Logging: ‎LoggingImpl::populateMetadata calls MonitoredResourceUtil::getResource, even when LogEntry contains a MonitoredResource #1788

@tschut

Description

@tschut

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.

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/java-logging API.priority: p3Desirable enhancement or fix. May not be included in next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions