Docs: Add mention of preferredVisualisationType in logs datasource guide (#31910)

* Add mention of preferredVisualisationType to get Log Panel to display

The instructions don't work right now. As described, it was necessary for me to set the preferredVisualisationType to 'logs' to get the log view in Explore. I spent several hours digging around the code to figure this out, so hopefully we can save others the time with this doc update.

* Update docs/sources/developers/plugins/build-a-logs-data-source-plugin.md

Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>

* Update docs/sources/developers/plugins/build-a-logs-data-source-plugin.md

Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>

* Update docs/sources/developers/plugins/build-a-logs-data-source-plugin.md

Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>

Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
This commit is contained in:
G Gordon Worley III 2021-03-18 02:44:53 -07:00 committed by GitHub
parent 69201bbf8c
commit 0fbe7f7f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ To add logs support to an existing data source, you need to:
- Enable logs support
- Construct the log data
- (Optional) Add preferred visualisation type hint to the data frame
### Enable logs support
@ -50,6 +51,25 @@ That's all you need to start returning log data from your data source. Go ahead
Congratulations, you just wrote your first logs data source plugin! Next, let's look at a couple of features that can further improve the experience for the user.
### (Optional) Add preferred visualisation type hint to the data frame
To make sure Grafana recognizes data as logs and shows logs visualization automatically in Explore you have do set `meta.preferredVisualisationType` to `'logs'` in the returned data frame. See [Selecting preferred visualisation section]({{< relref "add-support-for-explore-queries.md#selecting-preferred-visualisation" >}})
**Example:**
```ts
const frame = new MutableDataFrame({
refId: query.refId,
meta: {
preferredVisualisationType: 'logs',
},
fields: [
{ name: 'time', type: FieldType.time },
{ name: 'content', type: FieldType.string },
],
});
```
## Add labels to your logs
To help filter log lines, many log systems let you query logs based on metadata, or _labels_.