-
Notifications
You must be signed in to change notification settings - Fork 333
Spark instrumentation: capture emr step id when spark runs as EMR step #10670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 13 commits into
master
from
adrien.boitreaud/capture-emr-step-id
Feb 26, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2d6992e
make span attr for emr step id captured from workdir
aboitreaud 1a62eb6
capture step id for launcher spans
aboitreaud 369fce0
step id extraction error resilience
aboitreaud 594e9cf
add class as helper
aboitreaud bbf7b20
debug log
aboitreaud 95b82cc
rename to EmrUtils
aboitreaud 3aea275
Add unit tests
aboitreaud ee7c12e
Gate emr_step_id attribute to emr-detected runtimes
aboitreaud cfa491c
spotless apply
aboitreaud a8fdf19
switch to keys contain .emr. check
aboitreaud d3c7ebb
remove isRunningOnEMR
aboitreaud 34af8f9
early returns to avoid deep nesting
aboitreaud e0bec00
Merge branch 'master' into adrien.boitreaud/capture-emr-step-id
aboitreaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...tation/spark/spark-common/src/main/java/datadog/trace/instrumentation/spark/EmrUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package datadog.trace.instrumentation.spark; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import javax.annotation.Nullable; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** Extracts the AWS EMR Step ID from the working directory name (e.g. s-07767992IY7VC5NVV854). */ | ||
| class EmrUtils { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(EmrUtils.class); | ||
|
|
||
| /** EMR step ID is a 20 character string with numbers and uppercase letters only */ | ||
| private static final Pattern EMR_STEP_ID_PATTERN = Pattern.compile("^(s-[0-9A-Z]{20})$"); | ||
|
|
||
| @Nullable | ||
| static String getEmrStepId() { | ||
| try { | ||
| String userDir = System.getProperty("user.dir"); | ||
| if (userDir == null) { | ||
| return null; | ||
| } | ||
| Path workDir = Paths.get(userDir).getFileName(); | ||
| if (workDir == null) { | ||
| return null; | ||
| } | ||
| Matcher matcher = EMR_STEP_ID_PATTERN.matcher(workDir.toString()); | ||
| if (matcher.matches()) { | ||
| log.debug("EMR step ID extracted: {}", matcher.group(1)); | ||
| return matcher.group(1); | ||
| } | ||
| } catch (Throwable t) { | ||
| log.debug("Unable to extract EMR step ID from working directory", t); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private EmrUtils() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...on/spark/spark-common/src/test/java/datadog/trace/instrumentation/spark/EmrUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package datadog.trace.instrumentation.spark; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class EmrUtilsTest { | ||
|
|
||
| private String originalUserDir; | ||
|
|
||
| @BeforeEach | ||
| void saveUserDir() { | ||
| originalUserDir = System.getProperty("user.dir"); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void restoreUserDir() { | ||
| System.setProperty("user.dir", originalUserDir); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsStepIdWhenWorkdirMatchesEmrPattern() { | ||
| System.setProperty("user.dir", "/mnt/var/lib/hadoop/steps/s-07767992IY7VC5NVV854"); | ||
| assertEquals("s-07767992IY7VC5NVV854", EmrUtils.getEmrStepId()); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsNullWhenWorkdirDoesNotMatchEmrPattern() { | ||
| System.setProperty("user.dir", "/home/hadoop"); | ||
| assertNull(EmrUtils.getEmrStepId()); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsNullForApplicationIdWorkdir() { | ||
| System.setProperty("user.dir", "/home/hadoop/application_1234567890_0001"); | ||
| assertNull(EmrUtils.getEmrStepId()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also add a tag this is EMR launcher? does it make sense?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spark.application are tagged them with step id, above in the other Listener.
regarding marking these as emr launcher, I think the span operation name
spark.launcher.launchalready tells us this is a launcher + seeing step_id means we're necessarily on EMR, so I'd say we don't need more than that but let me know how you feel