From 0fbe7f7f52f12ba7e9c9c749ee20dd3f65aab595 Mon Sep 17 00:00:00 2001 From: G Gordon Worley III Date: Thu, 18 Mar 2021 02:44:53 -0700 Subject: [PATCH] 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 * Update docs/sources/developers/plugins/build-a-logs-data-source-plugin.md Co-authored-by: Andrej Ocenas * Update docs/sources/developers/plugins/build-a-logs-data-source-plugin.md Co-authored-by: Andrej Ocenas Co-authored-by: Andrej Ocenas --- .../build-a-logs-data-source-plugin.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/sources/developers/plugins/build-a-logs-data-source-plugin.md b/docs/sources/developers/plugins/build-a-logs-data-source-plugin.md index 0f08bf96448..c94921650b1 100644 --- a/docs/sources/developers/plugins/build-a-logs-data-source-plugin.md +++ b/docs/sources/developers/plugins/build-a-logs-data-source-plugin.md @@ -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_.