Lineage for AWS Glue ETL jobs
AWS Glue captures data lineage from Apache Spark jobs that write data and publishes it to the AWS Glue Data Catalog, so you can trace how data flows from table to table and column to column across jobs for impact analysis, debugging, and governance. Lineage capture means that, for each job run, AWS Glue records the datasets the job read and wrote, and how each output column was derived, and sends that record to the Data Catalog as an OpenLineage event. Lineage capture is enabled by default with AWS Glue version 6.1 or later. You don't install any additional library, change your job script, or set any job parameters.
How it works
When a job run starts, AWS Glue adds the AWS Glue lineage library, an extended build of the OpenLineage Spark integration, to the Spark classpath and registers the OpenLineage Spark listener in the driver with the following configuration.
| Property | Value |
|---|---|
spark.extraListeners |
io.openlineage.spark.agent.OpenLineageSparkListener |
spark.openlineage.transport.type |
amazon_glue_api |
spark.openlineage.transport.region |
The Region where the job runs |
spark.glue.accountId |
The AWS account ID that runs the job |
spark.openlineage.columnLineage.datasetLineageEnabled |
true |
spark.openlineage.facets.custom_environment_variables |
[GLUE_VERSION;GLUE_COMMAND_CRITERIA;GLUE_PYTHON_VERSION;] |
You can also set the following optional property yourself.
| Property | Value |
|---|---|
spark.openlineage.transport.proxyEndpoint |
http://{YOUR_IP}:{PORT}, an HTTP proxy endpoint for routing AWS Glue
requests |
Each time a Spark action writes data, the listener reads the query plan, builds an
OpenLineage run event, and calls PostLineageEvent with the credentials of the
job's IAM role. One job run sends one set of events for each write action.
The AWS Glue lineage library is built on the open-source OpenLineage
Spark integrationamazon_glue_api),
which sends events to the Data Catalog with SigV4-signed requests; support for fine-grained
access control; and AWS identity context, which records the account and the roles that ran the
job in each event. For details, see aws_runContext. Also, the
OpenLineage Spark documentation
Capture runs asynchronously in the Spark driver, so it doesn't change your job's results or add noticeable overhead. For details of the shared capture path, see Automatic lineage capture from AWS services.
After lineage events are published to the AWS Glue Data Catalog, you can view the lineage graphs and, optionally, persist the lineage events to S3 Tables. For instructions, see Viewing data lineage and Turning on the lineage system table.
The settings that AWS Glue adds take precedence over your own. If you set
spark.openlineage.transport.type to another value, such as console,
but don't register the listener yourself, AWS Glue replaces it with
amazon_glue_api and the job still publishes lineage to the Data Catalog. To use
your own OpenLineage configuration instead, add
io.openlineage.spark.agent.OpenLineageSparkListener to
spark.extraListeners in the job's --conf. When the listener is
already registered, AWS Glue adds no lineage settings and preserves your
spark.openlineage.* settings. To publish to the Data Catalog with your own
configuration, set spark.openlineage.transport.type to
amazon_glue_api, which is the default destination.
Supported job types
| Job type | Lineage captured | AWS Glue version |
|---|---|---|
Spark ETL scripts (glueetl) |
Yes | AWS Glue version 6.1 or later |
Spark streaming jobs (gluestreaming) |
Yes | AWS Glue version 6.1 or later |
| Notebooks and interactive sessions | Yes (Spark sessions; Ray sessions aren't supported) | AWS Glue version 6.1 or later |
What AWS Glue captures
OpenLineage facets are structured metadata fields that add context to lineage entities and events, such as:
-
Spark SQL statements and DataFrame operations that create or change data, such as
CREATE TABLE AS SELECT,INSERT,MERGE,UPDATE,DELETE, and DataFrame writes. -
Data definition statements, such as
CREATE TABLEandALTER TABLE. -
Input and output datasets. Tables in your Data Catalog resolve to their table ARN regardless of how the job refers to them, such as
orders,sales_db.orders, orawsdatacatalog.sales_db.orders. -
Column lineage, when Spark can derive it from the query plan.
-
Run context, including the account, Region, platform, job name, job run ID, and the job's IAM role.
The full list can be found in the OpenLineage
Spark documentation
Prerequisites
Version
AWS Glue version 6.1 or later.
Permission
The AWSGlueServiceRole managed policy grants it through its
glue:* statement, so roles that use that policy need no change. If your role uses
a scoped-down policy instead, the job's IAM role needs glue:PostLineageEvent
permissions.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowLineageEmission", "Effect": "Allow", "Action": "glue:PostLineageEvent", "Resource": "*" } ] }
Network
By default, AWS Glue routes the lineage call through the AWS Glue managed network path, so no VPC change is needed, including for jobs that use a VPC connection.
| Job configuration | VPC action required |
|---|---|
| Default | None. The call routes through the AWS Glue managed path. |
--disable-proxy-v2 set to true |
Add an AWS Glue interface VPC endpoint, or a NAT route, to the connection's VPC. Without one, the call fails and the job sends no lineage. |
For more information about the proxy, see Configuring AWS calls to go through your VPC.
View the lineage for a dataset
Run a job that writes to a table in the Data Catalog.
df = spark.sql( "SELECT order_date, sum(amount) AS total FROM sales_db.orders GROUP BY order_date" ) df.write.mode("overwrite").saveAsTable("analytics.daily_sales")
To view the lineage graph in the console
-
Sign in to the AWS Management Console and open the AWS Glue console at https://console.aws.amazon.com/glue/
. -
In the navigation pane, choose Data Catalog, then choose Tables.
-
Choose the output table,
daily_sales. -
Choose the Lineage tab.
The graph shows the job, its input tables, and the output table. To retrieve the graph with the API or the AWS CLI, see Viewing data lineage.
Turn off lineage capture
To turn off lineage events, set the job parameter --conf to
spark.openlineage.disabled=true. The job runs normally. The listener stays
registered and the AWS Glue settings remain in the job's configuration, but the listener
publishes nothing.
In a notebook, set the same property with the %%configure magic.
%%configure -f { "--conf": "spark.openlineage.disabled=true" }
To stop lineage for every job that uses a given role, deny
glue:PostLineageEvent in an IAM policy or a service control policy.
To keep AWS Glue from adding any lineage settings, register the OpenLineage listener yourself instead. See the note in How it works.
Turn off a facet
Set spark.openlineage.facets.facetName.disabled=true. The job skips building
that facet and keeps publishing lineage.
Lineage facets added by AWS Glue
AWS Glue extends the open-source OpenLineage
Spark integration
| Facet | Location in event | Purpose |
|---|---|---|
aws_runContext |
run.facets |
Where the job ran and which identity ran it |
spark_session |
run.facets |
The Spark session and SQL execution behind the event |
spark_metrics |
run.facets |
Aggregate executor and memory metrics |
spark_activityMetadata |
job.facets |
Functions referenced, Spark action, statement and query type |
columnsAccessed |
inputs[].inputFacets |
Columns and filters applied to each input dataset |
aws_runContext
Run facet recording the job's AWS location and identity. Resolved from service-set configuration and environment variables, with no network calls.
| Field | Type | Description |
|---|---|---|
accountId |
string | Account that ran the job |
region |
string | Region the job ran in |
platform |
string | Always included. GLUE_ETL, EMR_SERVERLESS,
EMR_ON_EC2, EMR_ON_EKS, EMR_MANAGED_COMPUTE,
or OTHER |
resourceId |
string | Job name or session ID |
platformRunId |
string | Job run ID |
identity |
object | IAM context, and identity context via trusted identity propagation. Omitted when no execution role resolves |
identity fields:
| Field | Type | Description |
|---|---|---|
executionRole |
string | Always included. IAM role the job ran as |
submittedBy |
string | Principal that submitted the job |
onBehalfOfUserId |
string | User the job ran for, from the identity context via trusted identity propagation |
onBehalfOfIdentityStoreArn |
string | Identity store holding that user |
onBehalfOfSubject |
string | Subject claim for that user |
onBehalfOfSubjectType |
string | Type of the subject claim |
onBehalfOfIssuer |
string | Identity provider that issued the claim |
onBehalfOfIdentityCenterInstanceArn |
string | Instance that provided the identity context via trusted identity propagation |
onBehalfOfType |
string | Kind of on-behalf-of attribution |
spark_session
Run facet linking the event to the session and SQL execution that produced it.
| Field | Type | Description |
|---|---|---|
sessionUUID |
string | Always included. Identifies the Spark session, distinct per session within one application |
executionId |
long | Spark SQL execution ID, matching the Spark UI SQL tab. Omitted for non-SQL runs |
spark_metrics
Run facet of metrics accumulated from completed tasks. Values are running totals at send time and are final on the run's last event, so compare runs using that event. Omitted when all three are zero, which means no task completed.
| Field | Type | Description |
|---|---|---|
distinctExecutors |
integer | Distinct executors that ran tasks for the run |
peakTaskMemoryBytes |
long | Highest peak execution memory on any single task, in bytes |
totalExecutorRunTimeMs |
long | Executor run time summed across tasks, in milliseconds |
spark_activityMetadata
Job facet describing what the query did, derived from the query plan Spark ran. Omitted when no plan is available.
| Field | Type | Description |
|---|---|---|
functions |
array | Always included. Functions that the query referenced, for example
PYTHON_UDF or HIVE_UDF. Empty when the query referenced
none. |
sparkAction |
string | Action that triggered execution, such as collect,
count, or command. Omitted when Spark reports none |
statementType |
string | Statement classification. Present only when sparkAction is
absent |
queryType |
string | What the query does to data, that is, READ, WRITE,
READ_WRITE, NONE, or UNKNOWN. |
columnsAccessed
Input facet on each input dataset, scoped to that dataset alone. Derived after Spark optimizes the query, so it reports what Spark read from storage rather than what the query text named; pruned columns don't appear.
| Field | Type | Description |
|---|---|---|
columns |
array of strings | Always included. Columns the query projected, filtered, joined, grouped, or aggregated on |
filters |
string | Predicates applied to this dataset, joined with AND. Omitted when
none |
Considerations
-
filterscomes from the optimized plan, so it can differ from what you wrote. Spark folds constants and adds null checks, renderingWHERE b > 30as((b > 30) AND isnotnull(b)). -
A filter spanning two joined tables appears on both datasets, because it constrains each read.
-
Columns used only by a filter the data source evaluates itself aren't reported. Apache Iceberg and other DataSource V2 sources apply such predicates during the scan, and Spark then drops both the filter and the column from the plan.
-
Under fine-grained access control,
columnsreports the authorized columns andfiltersstill reports your predicates. -
Streaming jobs attach the facet to every micro-batch. Turn it off on high-frequency streams if event size matters.
Considerations and limitations
-
Jobs that disable the AWS Glue proxy. A job that sets
--disable-proxy-v2routes the lineage call through your VPC and needs a route to AWS Glue. See Prerequisites. -
Repeated writes of the same DataFrame. When you write one DataFrame to several destinations in sequence, Spark can reuse the execution plan, and only the first write produces lineage.
-
Fine-grained access control. Jobs that use fine-grained access control can send lineage only with the
amazon_glue_apitransport. Other OpenLineage transports aren't supported. In FGAC mode, the system driver sends the lineage events. -
OpenLineage facets in FGAC mode. Not all facets can be generated in system space because of security restrictions; namely,
spark_unknown,debug,spark.logicalPlan,spark.exception, anderrorMessage. -
Jobs tagged for Amazon DataZone. If a job or session has the resource tag
AmazonDataZoneProjectwith a non-empty value, AWS Glue adds no lineage settings to it, because Amazon DataZone or Amazon SageMaker Unified Studio manages that run's lineage. The job sends no lineage to the Data Catalog, and nothing in the driver log points to the tag. Don't use this tag key for other purposes.
Lineage is best effort. AWS Glue doesn't guarantee an event for every job run, for example when a role lacks permission or a request is throttled. Don't use lineage as a compliance audit log. For access auditing, use AWS CloudTrail and AWS Lake Formation audit logs.
If the job role doesn't have the glue:PostLineageEvent permission, the job
runs normally but sends no lineage. AccessDenied errors for this action appear
in AWS CloudTrail and in the Spark driver's stderr logs. These errors don't fail your job;
Spark simply logs them and continues. To silence these log messages, you can either Turn off lineage capture or grant the missing
glue:PostLineageEvent permission.
For limitations that apply to every lineage source, including per-Region scope, see Automatic lineage capture from AWS services.
Known issues in the OpenLineage Spark integration
For known issues, see the open issues
in the OpenLineage repository
Earlier versions
AWS Glue versions earlier than 6.1 don't support the AWS Glue Data Catalog Lineage feature. To capture lineage in the Data Catalog, upgrade the job to AWS Glue version 6.1 or later.
If the job previously sent lineage to Amazon DataZone, clear Generate lineage
events in the job details and remove the Amazon DataZone lineage properties,
including spark.openlineage.transport.domainId, before you upgrade. Also remove
the AmazonDataZoneProject tag if you want the job's lineage in the Data Catalog.