View a markdown version of this page

Lineage for Amazon EMR - AWS Glue

Lineage for Amazon EMR

Amazon EMR 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 is enabled by default with Amazon EMR release emr-spark-8.2.0 and later, on Amazon EMR on EC2, Amazon EMR Serverless, and Amazon EMR on EKS, with some Considerations and limitations. You don't install any additional library, change your job script, or set any job parameters.

How it works

When a cluster, application, or job starts, Amazon EMR 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

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 role that runs the job. One Spark application sends one set of events for each write action.

The AWS Glue lineage library is built on version 1.49.0 of the open-source OpenLineage Spark integration on the GitHub website. AWS extends the library with the AWS Glue transport (amazon_glue_api), which sends events to the Data Catalog in requests signed with Signature Version 4. The library also supports fine-grained access control, and it adds AWS identity context that records the account and the roles that ran the job in each event. For details, see aws_runContext. Also, the OpenLineage Spark documentation contains additional Spark properties that you can set to further configure lineage.

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.

Note

AWS EMR adds io.openlineage.spark.agent.OpenLineageSparkListener to spark.extraListeners and removes duplicate entries. If your configuration already includes this listener, AWS EMR preserves your spark.openlineage.* settings.

spark.openlineage.transport.type must be set to amazon_glue_api, which is the default destination. If you configure another transport type, the job doesn't publish lineage to AWS Glue Data Catalog.

What Amazon EMR 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 TABLE and ALTER 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, or awsdatacatalog.sales_db.orders.

  • Column lineage, when Spark can derive it from the query plan.

  • Run context, including the account, Region, platform, cluster or application, Spark application ID, and the roles that run the job.

The full list can be found in the OpenLineage Spark documentation.

Prerequisites

Release

Amazon EMR release emr-spark-8.2.0 or later.

Permission

The role that runs the job needs glue:PostLineageEvent. Check that your role grants it, and add it to custom roles, including roles that you created before emr-spark-8.2.0.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowLineageEmission", "Effect": "Allow", "Action": "glue:PostLineageEvent", "Resource": "*" } ] }

The role that runs the job, which sends lineage events, differs by deployment option.

Deployment option Role that sends lineage events
Amazon EMR on EC2 The runtime role, for steps that use one. Otherwise, the cluster's EC2 instance profile.
Amazon EMR Serverless The job runtime role that you pass in --execution-role-arn.
Amazon EMR on EKS The job execution role. For jobs that use fine-grained access control, the query engine role in your security configuration.

If the role doesn't have the permission, the job runs normally, sends no lineage, and the driver log records a warning.

Network

Clusters and jobs in private subnets need a route to the AWS Glue endpoint. See Connect private subnets to AWS Glue.

Connect private subnets to AWS Glue

Lineage uses the same AWS Glue endpoint as Data Catalog reads. If your jobs already reach Data Catalog tables from the subnet, the route exists. Check that any endpoint policy you attached also allows glue:PostLineageEvent.

  • Amazon EMR on EC2. Amazon EMR on EC2 provisions an AWS Glue interface VPC endpoint (with private DNS enabled) when a cluster launches in a private subnet that can't already reach AWS Glue, so lineage works without extra setup.

  • Amazon EMR Serverless and Amazon EMR on EKS. Create an interface VPC endpoint for AWS Glue with the service name com.amazonaws.region.glue. The endpoint's security group must allow inbound HTTPS on port 443 from your job subnets.

View the lineage for a dataset

Run a job that writes to a table in the Data Catalog.

CREATE TABLE analytics.daily_sales AS SELECT order_date, sum(amount) AS total FROM sales_db.orders GROUP BY order_date;

To view the lineage graph in the console

  1. Sign in to the AWS Management Console and open the AWS Glue console at https://console.aws.amazon.com/glue/.

  2. In the navigation pane, choose Data Catalog, then choose Tables.

  3. Choose the output table, daily_sales.

  4. 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

Set the Spark property spark.openlineage.disabled to true on the cluster, application, or job. The job runs normally and sends no lineage.

Amazon EMR on EC2. Add the property to the cluster or step configuration.

[ { "Classification": "spark-defaults", "Properties": { "spark.openlineage.disabled": "true" } } ]

Amazon EMR Serverless. Add the property to the job run.

aws emr-serverless start-job-run \ --application-id 00example \ --execution-role-arn arn:aws:iam::111122223333:role/MyJobRole \ --job-driver '{"sparkSubmit":{"entryPoint":"s3://amzn-s3-demo-bucket/job.py","sparkSubmitParameters":"--conf spark.openlineage.disabled=true"}}'

Amazon EMR on EKS. Add the property to sparkSubmitParameters in the job run.

aws emr-containers start-job-run \ --virtual-cluster-id 00example \ --execution-role-arn arn:aws:iam::111122223333:role/MyJobRole \ --release-label emr-spark-8.2.0 \ --job-driver '{"sparkSubmitJobDriver":{"entryPoint":"s3://amzn-s3-demo-bucket/job.py","sparkSubmitParameters":"--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.

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 Amazon EMR

Amazon EMR extends the open-source OpenLineage Spark integration with five additional facets that record where a job ran, who ran it, what the query did, and which columns it read. They are on by default, need no configuration, and are additive: standard OpenLineage facets are unchanged. Unresolvable fields are omitted; generation is best-effort.

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 Required. GLUE_ETL, EMR_SERVERLESS, EMR_ON_EC2, EMR_ON_EKS, EMR_MANAGED_COMPUTE, or OTHER
resourceId string Cluster ID (EMR on EC2), application ID (EMR Serverless), virtual cluster ID (EMR on EKS), or job name or session ID (AWS Glue)
platformRunId string Step ID (EMR on EC2), job run ID (EMR Serverless, EMR on EKS, AWS Glue), or session or kernel ID for interactive runs
identity object IAM and IAM Identity Center context. Omitted when no execution role resolves

identity fields:

Field Type Description
executionRole string Required. IAM role the job ran as
submittedBy string Principal that submitted the job
onBehalfOfUserId string IAM Identity Center user the job ran for
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 IAM Identity Center instance
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 Required. 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 Required. 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 Required. Columns the query projected, filtered, joined, grouped, or aggregated on
filters string Predicates applied to this dataset, joined with AND. Omitted when none

Considerations

  • filters comes from the optimized plan, so it can differ from what you wrote. Spark folds constants and adds null checks, rendering WHERE b > 30 as ((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, columns reports the authorized columns and filters still 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

  • Amazon EMR on EKS operators. Jobs that you submit with a Kubernetes operator, such as the Spark operator, don't publish lineage automatically. These jobs bypass the Amazon EMR control plane that adds the lineage configuration, so you must set the Spark properties explicitly.

  • Fine-grained access control. Jobs that use fine-grained access control can send lineage only with the amazon_glue_api transport. 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, and errorMessage.

Important

Lineage is best effort. Amazon EMR 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 your execution roles or instance profiles lack the glue:PostLineageEvent permission, AccessDenied errors for this action appear in 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 open issues in the OpenLineage repository on the GitHub website.