Reduce logging costs

After logging is enabled, you are responsible for setting up how you would like to route, store, and retain your logs. You may incur extra Google Cloud costs for log ingestion and retention if you exceed the usage and retention limits for no charge. See Google Cloud Observability pricing.

However, you can control logging costs by using any of the following approaches described in the following sections.

Reduce logging usage

You can limit the amount of log data that is ingested by excluding certain log entries. See Excluding logs for more details.

The following examples demonstrate common Fleet Engine scenarios and how to filter out specific log messages to reduce costs.

Filter by method

You can filter out read-only methods since these are typically not need for data analysis or troubleshooting.

The following command updates the _Default logging bucket to exclude GetVehicle logs.

gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineGetVehicle,\
filter='jsonPayload.@type:"type.googleapis.com/maps.fleetengine.v1.GetVehicleLog"'

The following command updates the _Default logging bucket to exclude GetTrip logs.

gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineGetTrip,filter=\
'jsonPayload.@type:"type.googleapis.com/maps.fleetengine.v1.GetTripLog"'

Create a debug attribute

You can reduce logs to specific vehicles only by setting a debug attribute. Any vehicle that does not have the debug attribute will now be excluded.

The following command updates the _Default logging bucket to exclude vehicles without the debug attribute from the UpdateVehicle logs.

gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineNonDebug,\
filter='resource.type="fleetengine.googleapis.com/Fleet"
log_name:"logs/fleetengine.googleapis.com%2Fupdate_vehicle"
jsonPayload.@type="type.googleapis.com/maps.fleetengine.v1.UpdateVehicleLog"
NOT jsonPayload.response.attributes.key="debug"'

Filter empty restricted use logs

When enabled, restricted use logs create a child log for every regular log, even if the operation doesn't populate restricted fields. Filtering out these empty restricted logs can reduce costs.

The following command updates the RestrictedLogs logging bucket to exclude empty restricted UpdateVehicle logs.

gcloud logging sinks update RestrictedLogs \
--add-exclusion=name=ExcludeFleetengineEmptyRestrictedVehicleLogs,\
filter='resource.type="fleetengine.googleapis.com/Fleet"
log_name:"logs/fleetengine.googleapis.com%2Fupdate_vehicle_restricted"
NOT jsonPayload.request.vehicle.currentRouteSegment:*
NOT jsonPayload.response.currentRouteSegment:*
NOT jsonPayload.response.waypoints:*'

Export or route logs

You can route logs to other Google Cloud or external destinations to avoid the default ingestion and storage costs. Make sure you turn off log ingestion, as described in the next section, to avoid ingestion costs.

See Cloud Logging Exports and Exporting logs.

Turn off log ingestion

If you don't intend to use Fleet Engine logs, you can avoid potential Cloud Logging charges by turning off ingestion. By default, Fleet Engine logs are routed to the _Default log bucket.

The following command updates the _Default logging bucket to not ingest Fleet Engine logs.

    gcloud logging sinks update _Default \
    --log-filter='NOT LOG_ID("cloudaudit.googleapis.com/activity")
    AND NOT LOG_ID("externalaudit.googleapis.com/activity")
    AND NOT LOG_ID("cloudaudit.googleapis.com/system_event")
    AND NOT LOG_ID("externalaudit.googleapis.com/system_event")
    AND NOT LOG_ID("cloudaudit.googleapis.com/access_transparency")
    AND NOT LOG_ID("externalaudit.googleapis.com/access_transparency")
    AND NOT resource.type:"fleetengine.googleapis.com"'

See also Four steps to managing your Cloud Logging costs on a budget.