Enable Data Jobs Monitoring for Spark on Amazon EMR

Join the Beta!

Data Jobs Monitoring is in private beta. Fill out this form to join the wait list.

Request Access

Data Jobs Monitoring gives visibility into the performance and reliability of Apache Spark applications on Amazon EMR.

Setup

Follow these steps to enable Data Jobs Monitoring for Amazon EMR.

  1. Store your Datadog API key in AWS Secrets Manager.
  2. Create and configure your EMR cluster.
  3. Grant API access to your EMR EC2 instance profile.
  4. Specify service tagging per Spark application.

Store your Datadog API key in AWS Secrets Manager

  1. Take note of your Datadog API key.
  2. In AWS Secrets Manager, choose Store a new secret.
    • Under Secret type, select Other type of secret.
    • Under Key/value pairs, add your Datadog API key as a key-value pair, where the key is dd_api_key.
      AWS Secrets Manager, Store a new secret. A section titled 'Key/value pairs'. On the left, a text box containing 'dd_api_key'. On the right, a text box containing a redacted API key.
    • Then, click Next.
  3. On the Configure secret page, enter a Secret name. You can use datadog/dd_api_key. Then, click Next.
  4. On the Configure rotation page, you can optionally turn on automatic rotation. Then, click Next.
  5. On the Review page, review your secret details. Then, click Store.
  6. In AWS Secrets Manager, open the secret you created. Take note of the Secret ARN.

Create and configure your EMR cluster

When you create a new EMR cluster in the Amazon EMR console, add a bootstrap action on the Create Cluster page:

  1. Save this init script to an S3 bucket that your EMR cluster can read. Take note of the path to this script.
  2. On the Create Cluster page, find the Bootstrap actions section. Click Add to bring up the Add bootstrap action dialog.
    Amazon EMR console, Create Cluster, Add Bootstrap Action dialog. Text fields for name, script location, and arguments.
    • For Name, give your bootstrap action a name. You can use datadog_agent.
    • For Script location, enter the path to where you stored the init script in S3.
    • For Arguments, enter two arguments separated by a space: your Datadog site, and the name of the secret in which you stored your Datadog API key. Example:
       datadog/dd_api_key
      
    • Click Add bootstrap action.

When your cluster is created, this bootstrap action installs the Datadog Agent and downloads the Java tracer on each node of the cluster.

Grant API access to your EMR EC2 instance profile

  1. In your Amazon EMR console, open the summary page for your newly created cluster. Take note of your cluster’s IAM role for instance profile.

    Alternatively, you can also find this value by running:

    aws emr describe-cluster --cluster-id <YOUR_CLUSTER_ID>
    

    Look for Ec2InstanceAttributes.IamInstanceProfile in the output.

  2. In your AWS IAM console, click on Access management > Roles in the left navigation bar.

  3. Click on the instance profile you saw in the previous step.

  4. On the next page, under the Permissions tab, find the Permissions policies section. Click on Add permissions > Create inline policy.

  5. On the Specify permissions page, find the Select a service section. Under Service, select Secrets Manager.

    AWS IAM console, Specify Permissions page.

    • Then, under Actions allowed, select GetSecretValue. This is a Read action.
    • Under Resources, select Specific. Then, next to Secret, click on Add ARNs and add the ARN of the secret you created in the first step on this page.
    • Click Next.
  6. On the next page, give your policy a name. Then, click Create policy.

Specify service tagging per Spark application

Tagging enables you to better filter, aggregate, and compare your telemetry in Datadog. You can configure tags by passing -Ddd.service, -Ddd.env, -Ddd.version, and -Ddd.tags options to your Spark driver and executor extraJavaOptions properties.

In Datadog, each job’s name corresponds to the value you set for -Ddd.service.

spark-submit \
 --conf spark.driver.extraJavaOptions="-Ddd.service=<JOB_NAME> -Ddd.env=<ENV> -Ddd.version=<VERSION> -Ddd.tags=<KEY_1>:<VALUE_1>,<KEY_2:VALUE_2>" \
 --conf spark.executor.extraJavaOptions="-Ddd.service=<JOB_NAME> -Ddd.env=<ENV> -Ddd.version=<VERSION> -Ddd.tags=<KEY_1>:<VALUE_1>,<KEY_2:VALUE_2>" \
 application.jar

Validation

In Datadog, view the Data Jobs Monitoring page to see a list of all your data processing jobs.

Tag spans at runtime

You can set tags on Spark spans at runtime. These tags are applied only to spans that start after the tag is added.

// Add tag for all next Spark computations
sparkContext.setLocalProperty("spark.datadog.tags.key", "value")
spark.read.parquet(...)

To remove a runtime tag:

// Remove tag for all next Spark computations
sparkContext.setLocalProperty("spark.datadog.tags.key", null)

Further Reading

Additional helpful documentation, links, and articles: