Stackdriver Extension Log Message Format

Are there more examples available for how/what can be sent to the Stackdriver extension via the metadata and message fields.

The schema from the extension is the following:

{
  "type": "object",
  "properties":
  {
    "logName":
    {
      "type": "string"
    },
    "metadata":
    {
      "type": "object",
      "description": "https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#MonitoredResourceMetadata"
    },
    "message":
    {
      "type": ["string", "object"],
      "description": "https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry"
    }
  },
  "required": ["logName", "message"]
}

On the LogEntry MonitoredResourceMetadata page it says that the metadata should look like:

{
  "systemLabels": {
    object
  },
  "userLabels": {
    string: string,
    ...
  }
}

I have tried adding a new label (see "test": "value" attribute below) to the existing sample logging request and the label did not show up in the log message in Stackdriver. I was able to successfully push a custom JSON object to the log.

{
        "logName": "test-log",
        "metadata": {
            "resource": {
                "type": "global",
                "labels": {
                    "project_id": "test",
                    "test": "value"
                }
            }
        },
        "message": {"requestContent" : {request.content}}
    }
Solved Solved
0 5 847
1 ACCEPTED SOLUTION

This worked for me. I have logged a ticket to update documentations.

8086-screen-shot-2019-01-30-at-23908-pm.png

Here is the JSON

 {
  logName: "extension-logs",  
  metadata: {    
        resource: {type: 'global'},    
        labels: { test:"value"} },  
  message: "Log string"
 }

View solution in original post

5 REPLIES 5

https://docs.apigee.com/api-platform/reference/extensions/google-stackdriver-logging/google-stackdri... References

metadataMetadata about the log entry.
For information about contents of the metadata resource property, see the MonitoredResource object in the Stackdriver Logging documentation.
JSONNone.No.

MonitoredResource

An object representing a resource that can be used for monitoring, logging, billing, or other purposes. Examples include virtual machine instances, databases, and storage devices such as disks. The type field identifies a MonitoredResourceDescriptor object that describes the resource's schema. Information in the labels field identifies the actual resource and its attributes according to the schema.

"type":"global"

does not have labels [porject_id, test]

Do you want to add custom labels to the log message?

Yes I want to add custom labels. I have figured out how to define a custom log messages but can't figure out the correct format for metadata attribute.

The Apigee documentation includes a project_id metadata attribute in the example. I was just extending the example to see if the "test" attribute would show up in the log message in Stackdriver. When I include it in the API request the "test" label does not show up in Stackdriver but the "project_id" label does.

https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy#using_flow_variable...

This worked for me. I have logged a ticket to update documentations.

8086-screen-shot-2019-01-30-at-23908-pm.png

Here is the JSON

 {
  logName: "extension-logs",  
  metadata: {    
        resource: {type: 'global'},    
        labels: { test:"value"} },  
  message: "Log string"
 }

Thanks!

I was looking at the different resource types that can be passed to Stackdriver and I thought that the api resource looked like a good fit (see https://cloud.google.com/logging/docs/api/v2/resource-list).

Does Apigee recommend using one of the resource types (for example api) or should we be using global and defining our own labels?

I would recommend to follow StackDriver best practice. Apigee has no opinion on this.