Tutorial: Add a transformation in a workspace data collection rule by using the Azure portal

This tutorial walks you through configuration of a sample transformation in a workspace data collection rule (DCR) by using the Azure portal. Transformations in Azure Monitor allow you to filter or modify incoming data before it's sent to its destination. Workspace transformations provide support for ingestion-time transformations for workflows that don't yet use the Azure Monitor data ingestion pipeline.

Workspace transformations are stored together in a single DCR for the workspace, which is called the workspace DCR. Each transformation is associated with a particular table. The transformation will be applied to all data sent to this table from any workflow not using a DCR.

Note

This tutorial uses the Azure portal to configure a workspace transformation. For the same tutorial using Azure Resource Manager templates and REST API, see Tutorial: Add transformation in workspace data collection rule to Azure Monitor using resource manager templates.

In this tutorial, you learn how to:

  • Configure a workspace transformation for a table in a Log Analytics workspace.
  • Write a log query for a workspace transformation.

Prerequisites

To complete this tutorial, you need:

Overview of the tutorial

In this tutorial, you'll reduce the storage requirement for the LAQueryLogs table by filtering out certain records. You'll also remove the contents of a column while parsing the column data to store a piece of data in a custom column. The LAQueryLogs table is created when you enable log query auditing in a workspace. You can use this same basic process to create a transformation for any supported table in a Log Analytics workspace.

This tutorial uses the Azure portal, which provides a wizard to walk you through the process of creating an ingestion-time transformation. After you finish the steps, you'll see that the wizard:

  • Updates the table schema with any other columns from the query.
  • Creates a WorkspaceTransforms DCR and links it to the workspace if a default DCR isn't already linked to the workspace.
  • Creates an ingestion-time transformation and adds it to the DCR.

Enable query audit logs

You need to enable query auditing for your workspace to create the LAQueryLogs table that you'll be working with. This step isn't required for all ingestion time transformations. It's just to generate the sample data that we'll be working with.

  1. On the Log Analytics workspaces menu in the Azure portal, select Diagnostic settings > Add diagnostic setting.

    Screenshot that shows diagnostic settings.

  2. Enter a name for the diagnostic setting. Select the workspace so that the auditing data is stored in the same workspace. Select the Audit category and then select Save to save the diagnostic setting and close the Diagnostic setting page.

    Screenshot that shows the new diagnostic setting.

  3. Select Logs and then run some queries to populate LAQueryLogs with some data. These queries don't need to return data to be added to the audit log.

    Screenshot that shows sample log queries.

Add a transformation to the table

Now that the table's created, you can create the transformation for it.

  1. On the Log Analytics workspaces menu in the Azure portal, select Tables. Locate the LAQueryLogs table and select Create transformation.

    Screenshot that shows creating a new transformation.

  2. Because this transformation is the first one in the workspace, you must create a workspace transformation DCR. If you create transformations for other tables in the same workspace, they'll be stored in this same DCR. Select Create a new data collection rule. The Subscription and Resource group will already be populated for the workspace. Enter a name for the DCR and select Done.

    Screenshot that shows creating a new data collection rule.

  3. Select Next to view sample data from the table. As you define the transformation, the result will be applied to the sample data. For this reason, you can evaluate the results before you apply it to actual data. Select Transformation editor to define the transformation.

    Screenshot that shows sample data from the log table.

  4. In the transformation editor, you can see the transformation that will be applied to the data prior to its ingestion into the table. The incoming data is represented by a virtual table named source, which has the same set of columns as the destination table itself. The transformation initially contains a simple query that returns the source table with no changes.

  5. Modify the query to the following example:

    source
    | where QueryText !contains 'LAQueryLogs'
    | extend Context = parse_json(RequestContext)
    | extend Workspace_CF = tostring(Context['workspaces'][0])
    | project-away RequestContext, Context
    

    The modification makes the following changes:

    • Rows related to querying the LAQueryLogs table itself were dropped to save space because these log entries aren't useful.
    • A column for the name of the workspace that was queried was added.
    • Data from the RequestContext column was removed to save space.

    Note

    Using the Azure portal, the output of the transformation will initiate changes to the table schema if required. Columns will be added to match the transformation output if they don't already exist. Make sure that your output doesn't contain any columns that you don't want added to the table. If the output doesn't include columns that are already in the table, those columns won't be removed, but data won't be added.

    Any custom columns added to a built-in table must end in _CF. Columns added to a custom table don't need to have this suffix. A custom table has a name that ends in _CL.

  6. Copy the query into the transformation editor and select Run to view results from the sample data. You can verify that the new Workspace_CF column is in the query.

    Screenshot that shows the transformation editor.

  7. Select Apply to save the transformation and then select Next to review the configuration. Select Create to update the DCR with the new transformation.

    Screenshot that shows saving the transformation.

Test the transformation

Allow about 30 minutes for the transformation to take effect and then test it by running a query against the table. Only data sent to the table after the transformation was applied will be affected.

For this tutorial, run some sample queries to send data to the LAQueryLogs table. Include some queries against LAQueryLogs so that you can verify that the transformation filters these records. Now the output has the new Workspace_CF column, and there are no records for LAQueryLogs.

Troubleshooting

This section describes different error conditions you might receive and how to correct them.

IntelliSense in Log Analytics not recognizing new columns in the table

The cache that drives IntelliSense might take up to 24 hours to update.

Transformation on a dynamic column isn't working

A known issue currently affects dynamic columns. A temporary workaround is to explicitly parse dynamic column data by using parse_json() prior to performing any operations against them.

Next steps