-
Notifications
You must be signed in to change notification settings - Fork 324
Improve crashtracking payload and add build_id and relative address #10469
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
Open
amarziali
wants to merge
4
commits into
master
Choose a base branch
from
andrea.marziali/buildid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
104 changes: 104 additions & 0 deletions
104
...ent/agent-crashtracking/src/main/java/datadog/crashtracking/buildid/BuildIdCollector.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,104 @@ | ||
| package datadog.crashtracking.buildid; | ||
|
|
||
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
|
||
| import datadog.common.queue.Queues; | ||
| import datadog.trace.util.AgentTaskScheduler; | ||
| import java.nio.file.Path; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.locks.LockSupport; | ||
| import org.jctools.queues.MessagePassingQueue; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class BuildIdCollector { | ||
| static final Logger LOGGER = LoggerFactory.getLogger(BuildIdCollector.class); | ||
| static final BuildInfo EMPTY = new BuildInfo(null, null, null); | ||
|
|
||
| private final Map<String, BuildInfo> libraryBuildInfo = new ConcurrentHashMap<>(); | ||
| private final Set<String> processed = new HashSet<>(); | ||
| private final AtomicBoolean collecting = new AtomicBoolean(false); | ||
| private final MessagePassingQueue<Path> workQueue = Queues.spscArrayQueue(Short.MAX_VALUE); | ||
| private final CountDownLatch latch = new CountDownLatch(1); | ||
|
|
||
| class Collector implements Runnable { | ||
| private final BuildIdExtractor extractor = BuildIdExtractor.create(); | ||
| private final long deadline; | ||
|
|
||
| Collector(long timeout, TimeUnit unit) { | ||
| this.deadline = unit.toNanos(timeout) + System.nanoTime(); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| while (System.nanoTime() <= deadline) { | ||
| final Path path = workQueue.poll(); | ||
| if (path == null) { | ||
| if (!collecting.get()) { | ||
| break; | ||
| } | ||
| LockSupport.parkNanos(MILLISECONDS.toNanos(50)); | ||
| continue; | ||
| } | ||
| final String fileName = path.getFileName().toString(); | ||
| LOGGER.debug("Resolving build id for {} against {}", fileName, path); | ||
| final String buildId = extractor.extractBuildId(path); | ||
| if (buildId != null) { | ||
| LOGGER.debug("Found build id {} for library {}", buildId, fileName); | ||
| libraryBuildInfo.put( | ||
| fileName, new BuildInfo(buildId, extractor.buildIdType(), extractor.fileType())); | ||
| } | ||
| } | ||
| latch.countDown(); | ||
| } | ||
| } | ||
|
|
||
| public void addUnprocessedLibrary(String filename) { | ||
| if (!collecting.get()) { | ||
| libraryBuildInfo.putIfAbsent(filename, EMPTY); | ||
| } | ||
| } | ||
|
|
||
| public void resolveBuildId(Path path) { | ||
| if (collecting.compareAndSet(false, true)) { | ||
| AgentTaskScheduler.get().execute(new Collector(5, SECONDS)); | ||
| } | ||
| final String filename = path.getFileName().toString(); | ||
| if (!processed.add(filename)) { | ||
| return; | ||
| } | ||
| if (libraryBuildInfo.remove(filename) == null) { | ||
| // the library is not present in the collected ones part of the stackframe | ||
| LOGGER.debug( | ||
| "Skipping build id resolution for {} as it was not added to unprocessed", filename); | ||
|
|
||
| } else { | ||
| workQueue.offer(path); | ||
| } | ||
| } | ||
|
|
||
| public void awaitCollectionDone(final int timeoutSeconds) { | ||
| if (!collecting.compareAndSet(true, false)) { | ||
| return; | ||
| } | ||
| try { | ||
| if (!latch.await(timeoutSeconds, SECONDS)) { | ||
| LOGGER.warn("Build id collection incomplete."); | ||
| } | ||
| } catch (InterruptedException ie) { | ||
| Thread.currentThread().interrupt(); | ||
| LOGGER.warn("Interrupted while waiting for build id collection to finish"); | ||
| } | ||
| } | ||
|
|
||
| public BuildInfo getBuildInfo(String filename) { | ||
| return libraryBuildInfo.get(filename); | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
...ent/agent-crashtracking/src/main/java/datadog/crashtracking/buildid/BuildIdExtractor.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.crashtracking.buildid; | ||
|
|
||
| import datadog.environment.OperatingSystem; | ||
| import java.nio.file.Path; | ||
|
|
||
| /** | ||
| * Interface for extracting build IDs from native library binaries. Build IDs help identify exact | ||
| * library versions for symbolization of native stack traces. | ||
| */ | ||
| public interface BuildIdExtractor { | ||
| /** | ||
| * Extracts build ID from a binary file. | ||
| * | ||
| * @param file Path to the library file | ||
| * @return Build ID as hex string, or null if not found or on error | ||
| */ | ||
| String extractBuildId(Path file); | ||
|
|
||
| /** | ||
| * @return the file type this extractor operates for. | ||
| */ | ||
| BuildInfo.FileType fileType(); | ||
|
|
||
| /** | ||
| * @return the build id type this extractor is able to provide. | ||
| */ | ||
| BuildInfo.BuildIdType buildIdType(); | ||
|
|
||
| /** | ||
| * Factory method that returns appropriate extractor for the platform. | ||
| * | ||
| * @return Platform-specific build ID extractor | ||
| */ | ||
| static BuildIdExtractor create() { | ||
| if (OperatingSystem.isLinux()) { | ||
| return new ElfBuildIdExtractor(); | ||
| } else if (OperatingSystem.isWindows()) { | ||
| return new PeBuildIdExtractor(); | ||
| } | ||
| return new NoOpBuildIdExtractor(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
dd-java-agent/agent-crashtracking/src/main/java/datadog/crashtracking/buildid/BuildInfo.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,23 @@ | ||
| package datadog.crashtracking.buildid; | ||
|
|
||
| public class BuildInfo { | ||
| public enum BuildIdType { | ||
| SHA1, // ELF | ||
| PE // WIN | ||
| } | ||
|
|
||
| public enum FileType { | ||
| ELF, | ||
| PE, | ||
| } | ||
|
|
||
| public final String buildId; | ||
| public final BuildIdType buildIdType; | ||
| public final FileType fileType; | ||
|
|
||
| public BuildInfo(final String buildId, final BuildIdType buildIdType, final FileType fileType) { | ||
| this.buildId = buildId; | ||
| this.buildIdType = buildIdType; | ||
| this.fileType = fileType; | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.