Reporting Logs

This page describes how to use Google Service Control to enable services to send logs to both service producers and service consumers.

Service Control accepts structured or unstructured log data, which it batches and forwards to Stackdriver Logging. Both service consumers and service producers can use Google Cloud Console and Google API Console to view the log data, or use the Stackdriver Logging API to access the data programmatically.

Whereas Stackdriver Logging alone allows a service to produce logs for the sake of the service's producer, Service Control also lets you produce logs that are intended for the service consumers. This makes it possible for service consumers to understand and diagnose their use of the service.

Configuring logs

Before you send logs to Service Control, you need to specify three different bits of information in your service configuration:

  • Log names: You can have one or more distinct logs. Each log is identified by a unique name. Individual logs make it possible for you to isolate distinct types of data if it makes the data easier to visualize or use.

  • Monitored resources: Monitored resource types control the shape of the data that is held within a given log. Stackdriver Logging provides a well-known set of monitored resource types that you can chose from.

  • Log configuration: Lets you specify the monitored resource associated with any log stream and the destination (producer or consumer) where each log should be sent.

In the following example of service configuration state, the log activity_log is configured to be sent to the service consumer. See service.proto for details on service configuration.

# The monitored resource to be used.
monitored_resources:
- type: api
  labels:
  - key: cloud.googleapis.com/location
  - key: serviceruntime.googleapis.com/api_version
  - key: serviceruntime.googleapis.com/api_method
  - key: cloud.googleapis.com/project
  - key: cloud.googleapis.com/service

# The log name to be used.
logs:
- name: activity_log

# The logging configuration.
logging:
  consumer_destinations:
  - monitored_resource: api
    logs:
    - activity_log

Reporting logs

Once you have configured logs in the service configuration and pushed the configuration to Google Service Management, you can call the Service Control API to report log entries. The following example uses the gcurl command to demonstrate the call; see Getting Started for how to set this up.

gcurl -d "{
  'operations': [ {
    'operationId': 'e8bf36ef-f9b5-4274-b4f9-079a3731e6e5',
    'operationName': 'google.example.hello.v1.HelloService.GetHello',
    'consumerId': 'project:endpointsapis-consumer',
    'startTime': '`date +%FT%T%:z`',
    'endTime': '`date +%FT%T%:z`',
    'labels': {
      'cloud.googleapis.com/location': 'global',
      'serviceruntime.googleapis.com/api_version': 'v1',
      'serviceruntime.googleapis.com/api_method': 'google.example.hello.v1.HelloService.GetHello',
      'cloud.googleapis.com/project': 'proven-catcher-789',
      'cloud.googleapis.com/service': 'endpointsapis.appspot.com'
    },
    'logEntries': [ {
      'severity': 'INFO',
      'textPayload': 'new book arrived',
      'name': 'activity_log'
    } ]
  } ]
}" https://servicecontrol.googleapis.com/v1/services/endpointsapis.appspot.com:report

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.