This document describes the rules Google Cloud Observability uses to determine the
Logging monitored resource type for log data
that is ingested by the Telemetry API. The monitored resource describes the
source of log data, and in a LogEntry, it is represented by using
labels. Google Cloud Observability determines the values of those labels by using the
OTLP resource attributes.
General structure of OTLP-formatted log data
When log data is sent to Google Cloud by using the Telemetry API, this data must be in a format that is consistent with OTLP. The general structure for this data is as shown:
"resourceLogs": [
{
"resource": {
"attributes": [...]
},
"scopeLogs": [
{
"logRecords": [...]
}
]
}
]
Notice that OpenTelemetry batches individual logs, each of which is represented by
a logRecord structure, with information about the source of those logs,
which is represented by the resource structure.
When Google Cloud Observability receives a resourceLogs object, it constructs one
LogEntry for each logRecord. Unlike OTLP which batches source
information with a collection of individual logs, each LogEntry structure
contains information about the source of the log and the log itself.
To learn more about the structure of OTLP-formatted log data,
see the OpenTelemetry logs.proto.
Set OTLP resource attributes by using the Google Cloud resource detector
To set OTLP resource attributes in your OTLP log data, use a Google Cloud resource detector. These detectors attach to telemetry the OTLP resource attributes that describe the source of the telemetry:
For collector-based export, configure resource detection as part of the collector's processors. For example, your collector might specify two resource detectors:
resourcedetection: detectors: ["env", "gcp"]The following documents provide examples of collectors that export metric or trace data:
- Deploy and use the collector: Describes how to send metric data to the Telemetry API.
- Deploy Google-Built OpenTelemetry Collector on Google Kubernetes Engine: Describes how to collect log, metric, and trace data when running on Google Kubernetes Engine. The collector sends trace data to the Telemetry API and metric data to a Prometheus exporter.
If you are using direct export, then use the appropriate Google Cloud resource detector for your language:
How resource labels are set
Each log entry contains a set of labels that identifies the source of the log entry, which is a also known as a Logging monitored resource. The following illustrates the labels for Google Kubernetes Engine.
resource: {
labels: {
cluster_name: "my-cluster"
container_name: "server"
location: "us-central1"
namespace_name: "default"
pod_name: "my-pod"
project_id: "my-project"
}
type: "k8s_container"
}
As shown, a monitored resource has a type field and one or more labels.
At a minimum, the labels for a monitored resource include either project_id or
resource_container.
The following table describes the rules that Google Cloud Observability uses to map OTLP resource attributes
to a monitored resource. The table is ordered. That is, if the resource attributes include
cloud.platform and the value is gcp_compute_engine, then the monitored
resource type is set to gce_instance. To determine the value of a
monitored resource's label, Google Cloud Observability uses prioritized list of resource attributes.
The value of a label is an empty string when none of the resource attributes are available.
| OTLP attribute and value attached to a log record |
Cloud Logging monitored resource type |
Monitored resource label values as determined from OTLP resource attributes, by priority |
|---|---|---|
cloud.platformhas value gcp_compute_engine |
gce_instance |
|
cloud.platformhas value gcp_app_engine |
gae_app |
|
cloud.platformhas value aws_ec2 |
aws_ec2_instance |
|
cloud.platformhas value gcp_bare_metal_solution |
baremetal instance |
|
service.name andservice.instance.idare not empty |
generic_task |
|
faas.name andfaas.instanceare not empty |
generic_task |
|
k8s.cluster.name andk8s.container.nameare not empty |
k8s_container |
|
k8s.cluster.name andk8s.pod.nameare not empty |
k8s_pod |
|
k8s.cluster.name andk8s.node.nameare not empty |
k8s_node |
|
k8s.cluster.nameis not empty |
k8s_cluster |
|
| No other label matches | generic_node |
|
Infer project or resource container ID label value
All Logging monitored resource types have either a
project_id label or a resource_container label.
The system searches the following attributes, in order, to determine the value of those labels:
project_idgcp.project.idgcp.project_idgcp.dest_project_idgcp.resource.containerresource_containercloud.account.idcloud.account_id