Area: Ingestion Issues
Sub-Area: Spark Lineage / Databricks Runtime Configuration
Applies to: OSS + Cloud
Issue
You want the DataHub Spark agent (acryl-spark-lineage) to send lineage from a Databricks Runtime 17.3 LTS cluster (Spark 4.0, Scala 2.13, Java 17). Several settings must all be right before lineage shows up in DataHub. These are the usual failures:
- The driver fails at startup with a
ClassNotFoundExceptionfordatahub.spark.DatahubSparkListener, because the jar was not on the driver classpath when Spark started. - The SparkContext stops on the first Spark job with a
NoSuchMethodError, because the cluster runs the wrong Scala build or an agent version older than 1.7.0.8. - The agent's writes to DataHub fail with HTTP 403 (
User urn:li:corpuser:<id> is unauthorized to modify entity: ...), because the token's user lacks write privileges. - The Spark job appears in DataHub, but its lineage points at datasets that are not the ones your Unity Catalog ingestion created, because the dataset URNs don't match.
You Might Be Asking
- Which jar and version of
acryl-spark-lineagedo I use on DBR 17.3 LTS? - Why do I get
ClassNotFoundException: datahub.spark.DatahubSparkListenerwhen the jar is attached as a cluster library? - Why does the SparkContext stop with a
NoSuchMethodErroron the first job? - Why does DataHub show my Spark job but not the links to my Unity Catalog tables?
- Does the agent support Spark 4.2?
Solution
Step 1: Pick the right jar and version
- Spark 4 needs the Scala 2.13 build:
io.acryl:acryl-spark-lineage_2.13. Read the Scala version from the runtime name (17.3.x-scala2.13) and hard-code_2.13in your init script. Don't try to detect it from jar file names in/databricks/jars. If detection picks the 2.12 build on a 2.13 runtime, the jar loads and then stops the SparkContext with aNoSuchMethodErroron the first job. - Use agent version 1.7.0.8 or later. Before 1.7.0.8, the
_2.13jar shipped classes compiled for Scala 2.12. On Spark 4 a plain Parquet scan then fails withNoSuchMethodError(for example onFileScanRDD.filePartitions()), and Spark shuts down the SparkContext. This affects every version before 1.7.0.8, not only 1.7.0. - Pin an exact released version. Release candidates (versions with
rc) are also published to Maven Central, so don't resolve "latest". Check the agent changelog and Maven Central for the newest release. The newest release on Maven Central is not always the one you need. For catalog-qualified Unity Catalog names or Spark 4.2, use 1.7.0.20 (Step 5). - The agent needs Java 17 or newer. DBR 17.3 LTS runs Java 17. Databricks Runtime 15.4 LTS and older run Java 8 or 11 and are not supported.
The Maven coordinate io.acryl:acryl-spark-lineage_2.13:<version> is not a file name. The file is acryl-spark-lineage_2.13-<version>.jar, with a hyphen before the version.
Step 2: Install the jar with an init script
Spark creates the classes in spark.extraListeners while the SparkContext starts. The jar must already be in /databricks/jars at that point. Jars you add as cluster libraries or with spark.jars.packages arrive too late, and the driver fails with ClassNotFoundException: datahub.spark.DatahubSparkListener. Use a cluster init script that puts the jar in /databricks/jars. Follow the jar steps in the DataHub Databricks instructions, but store the script in workspace files or a volume. Those instructions still show DBFS.
This script downloads the jar from Maven Central. Set VERSION to an exact release, 1.7.0.8 or later:
#!/bin/bash
set -euo pipefail
VERSION="<agent-version>"
JAR_NAME="acryl-spark-lineage_2.13-${VERSION}.jar"
curl -sSL --fail \
-o "/databricks/jars/${JAR_NAME}" \
"https://repo1.maven.org/maven2/io/acryl/acryl-spark-lineage_2.13/${VERSION}/${JAR_NAME}"
If the cluster can't reach Maven Central, upload the jar to a Unity Catalog volume and copy it instead:
#!/bin/bash
set -euo pipefail
cp /Volumes/<catalog>/<schema>/<volume>/acryl-spark-lineage_2.13-<version>.jar /databricks/jars/
set -euo pipefail makes a failed download or copy fail the cluster start, so you see an init script error and not a ClassNotFoundException later. Store the init script in workspace files or a volume, not on DBFS.
After the cluster starts, check that exactly one agent jar is present:
%sh
ls -la /databricks/jars | grep -i acryl
You should see one acryl-spark-lineage_2.13-<version>.jar. If a _2.12 jar or a second version is also there, another init script installs it. Remove that script and restart the cluster.
Step 3: Set the Spark configuration
Add these lines to the cluster's Spark config (Advanced Options > Spark):
spark.extraListeners datahub.spark.DatahubSparkListener
spark.datahub.rest.server https://<your-datahub-host>/gms
spark.datahub.rest.token {{secrets/<scope>/<key>}}
spark.datahub.metadata.dataset.hivePlatformAlias databricks
spark.datahub.flow_name <name-for-this-workflow>
-
spark.datahub.rest.tokenreads the DataHub token from a Databricks secret. Don't put the token in plain text in the Spark config, init scripts or notebooks. -
spark.datahub.metadata.dataset.hivePlatformAlias databricksmakes the agent emit table URNs on thedatabricksplatform. The default ishive. The DataHub Unity Catalog source ingests tables on thedatabricksplatform, so you need this setting for lineage to attach to those tables. Step 5 covers the table name. -
spark.datahub.flow_nameis optional. It sets the DataFlow name. Without it, the agent uses the Spark app name.
All keys are in the configuration options.
Step 4: Use a token whose user can write the agent's entities
The agent writes data flows, data jobs, data process instances and dataset lineage to DataHub. If the token's user lacks Edit Entity on those entity types, every write fails with HTTP 403 and the job doesn't appear in DataHub. Use a service account so the token doesn't depend on a person's account:
- Go to Settings > Users & Groups > Service Accounts and create a service account.
- Give it the Editor role. The default Editor policies grant Edit Entity on datasets, data flows, data jobs and data process instances.
- Go to Settings > Access Tokens, click Generate new token, select Service Account as the token type and pick the service account.
- Store the token in a Databricks secret scope and reference it as
{{secrets/<scope>/<key>}}(Step 3). The cluster's user must be able to read that secret scope. - Revoke any personal token you used in the Spark config before.
Step 5: Match the table names to Unity Catalog ingestion
The DataHub Unity Catalog source names tables <catalog>.<schema>.<table> on the databricks platform (without include_metastore or a platform instance). The Spark agent's URN must match exactly, or the job links to a different dataset.
Open the data job in DataHub, follow a lineage link to a table, and compare that dataset's URN with the URN of the same table from Unity Catalog ingestion.
- The platform is
hiveand notdatabricks: setspark.datahub.metadata.dataset.hivePlatformAlias databricks(Step 3). - The name is
<schema>.<table>, without the catalog: your agent version doesn't emit catalog-qualified names. Agent 1.7.0.20 and agent 1.8.0 emit catalog-qualified<catalog>.<schema>.<table>names. They do this when Unity Catalog is enabled and symlink resolution is on. Symlink resolution is on whenspark.datahub.disableSymlinkResolution=false, which is the default. Use agent 1.7.0.20 or 1.8.0. Do not use a release candidate (a version withrc). For example, 1.8.0rc4 bundles OpenLineage 1.50, which is older. The Breaking Changes page lists this change under DataHub v1.9.0. - If you set
spark.datahub.metadata.dataset.platformInstanceto the catalog name as a workaround, remove it when you upgrade. The agent keeps a configured platform instance, so leaving it set produces<catalog>.<catalog>.<schema>.<table>.
After you change the names, rerun the job. The agent does not move lineage it already wrote under the old URNs. Remove those stale edges or datasets with your normal cleanup process.
The tables must also exist in DataHub. If your Unity Catalog ingestion source doesn't cover the catalog that the job uses, the lineage points at datasets with no metadata. Add that catalog to the ingestion source.
Step 6: Validate end to end
- Restart the cluster and confirm one agent jar (Step 2).
- Run
SELECT 1to confirm the driver starts. - Run a CREATE TABLE AS SELECT between two Unity Catalog tables:
CREATE OR REPLACE TABLE <catalog>.<schema>.<target_table> AS
SELECT * FROM <catalog>.<schema>.<source_table>
- In DataHub, open the data job and check that the Lineage tab links to the Unity Catalog datasets for both tables.
Additional Notes
- Spark 4.0 is supported through the Scala 2.13 build, and DataHub tests the agent on Apache Spark 4.0. Spark 4.2 support comes from OpenLineage 1.53 and later. Agent 1.7.0.20 bundles OpenLineage 1.53, and agent 1.8.0 bundles OpenLineage 1.55. DataHub's own tests don't cover Spark 4.2.
- Databricks has ended support for cluster-scoped init scripts on DBFS. Keep the init script and the jar in workspace files or a Unity Catalog volume.