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! Go to Solution.
This worked for me. I have logged a ticket to update documentations.
Here is the JSON
{ logName: "extension-logs", metadata: { resource: {type: 'global'}, labels: { test:"value"} }, message: "Log string" }
metadata | Metadata about the log entry. For information about contents of the metadata resource property, see the MonitoredResource object in the Stackdriver Logging documentation. | JSON | None. | No. |
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.
This worked for me. I have logged a ticket to update documentations.
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.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |