Bucket-scoped log-based metrics

This document summarizes the characteristics of bucket-scoped log-based metricsand describes how they differ from project-scoped log-based metrics.

Characteristics of bucket-scoped log-based metrics

Bucket-scoped log-based metrics are user-defined log-based metricsthat evaluate log entries routed to a specific log bucket. With bucket-scopedlog-based metrics, you can create log-based metrics that extract data fromlogs in the following cases:

  • Logs that are routed from one project to a bucket in another project.
  • Logs that are routed into a bucket through an aggregated sink.

Like project-scoped log-based metrics, bucket-scoped log-based metricsare defined within a Google Cloud project, not at the folder or organizationlevel. If you want to track the folder or organization from which a logentry was routed to the bucket, then you can define labels in thelog-based metric to record that information.

Bucket-scoped log-based metrics have several differences from project-scopedlog based metrics.

Projects and metrics scopes

Bucket-scoped log-based metrics are defined in the same project that containsthe source bucket. By default, only the project that defines a bucket-scopedlog-based metric can see the metric data for the log bucket.However, if your project appears in the metrics scope of other projects,those projects can also see your metrics.

The Google Cloud projects that routelogs to the bucketdo not need to be in the metrics scope of anyproject.

For more information aboutlog-based-metrics and metrics scopes,seeVisibility to metrics scopes.

When the logs are received atthe bucket, the routed log metric data derived is visible toany project that includes the bucket's project in its metrics scope.If a project routing logs is not in the metrics scope of any project,then other information in the routing project is not visible.

When using bucket-scoped log-based metrics, the following statements apply:

  • You define the log-based metric in the project with the destination bucket.
  • Your bucket-scoped log-based metrics evaluates all log entries routed tothe bucket, regardless of whether the log is from the same project as thebucket or from a different project.
  • The metric data is visible to any other project that includes the projectwith the bucket in its metrics scope.
  • Projects routing logs don't need to be in any project's metrics scope.

Monitored-resource type:logging_bucket

Bucket-scoped log-based metrics use the monitored-resource typelogging_bucket when writing time-series data to Cloud Monitoring. Thelogging_bucket resource type includes the followinglabels:

  • project_id: The identifier of your Google Cloud project, a string likemy-test-project.
  • bucket_id: The name of the log bucket associated with thelog-based metric, a string likemy-test-bucket.
  • location: The location of the log bucket.
  • monitored_resource_type: The type of the monitored resource that producedthis log entry; the value comes from thetype field from theMonitoredResource structure contained in theresourcefield of the log entry.
  • source_resource_container: The identifier for the project, folder, ororganization from which the log entry was sent, a string in one of thefollowing forms:
    • projects/PROJECT_ID
    • organizations/ORGANIZATION_ID
    • folders/FOLDER_ID

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.