-
Notifications
You must be signed in to change notification settings - Fork 324
Universal profiling integration: Added serialization of stacktrace IDs as profiler_stack_trace_ids otel attributes #3607
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
232c46f
Added ability to store correlation IDs on transactions
JonasKunz 7198c95
Implemented serialization of profiling IDs
JonasKunz fd7b0e5
Add explicity generic type
JonasKunz 877870d
Fix thread safety issues
JonasKunz 743cdc6
Merge remote-tracking branch 'elastic/main' into profiling-serialization
JonasKunz 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
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
43 changes: 43 additions & 0 deletions
43
...nt-core/src/main/java/co/elastic/apm/agent/report/serialize/Base64SerializationUtils.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,43 @@ | ||
package co.elastic.apm.agent.report.serialize; | ||
|
||
import com.dslplatform.json.JsonWriter; | ||
|
||
public class Base64SerializationUtils { | ||
|
||
private static final byte[] BASE64_URL_CHARS = new byte[]{ | ||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', | ||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', | ||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', | ||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', | ||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', | ||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', | ||
'w', 'x', 'y', 'z', '0', '1', '2', '3', | ||
'4', '5', '6', '7', '8', '9', '-', '_', | ||
}; | ||
|
||
|
||
public static void writeBytesAsBase64UrlSafe(byte[] data, JsonWriter jw) { | ||
int i = 0; | ||
for (; i + 2 < data.length; i += 3) { | ||
int b0 = ((int) data[i]) & 0xFF; | ||
int b1 = ((int) data[i + 1]) & 0xFF; | ||
int b2 = ((int) data[i + 2]) & 0xFF; | ||
jw.writeByte(BASE64_URL_CHARS[b0 >> 2]); | ||
jw.writeByte(BASE64_URL_CHARS[((b0 << 4) & 63) | (b1 >> 4)]); | ||
jw.writeByte(BASE64_URL_CHARS[((b1 << 2) & 63) | (b2 >> 6)]); | ||
jw.writeByte(BASE64_URL_CHARS[b2 & 63]); | ||
} | ||
int leftOver = data.length - i; | ||
if (leftOver == 1) { | ||
int b0 = ((int) data[i]) & 0xFF; | ||
jw.writeByte(BASE64_URL_CHARS[b0 >> 2]); | ||
jw.writeByte(BASE64_URL_CHARS[(b0 << 4) & 63]); | ||
} else if (leftOver == 2) { | ||
int b0 = ((int) data[i]) & 0xFF; | ||
int b1 = ((int) data[i + 1]) & 0xFF; | ||
jw.writeByte(BASE64_URL_CHARS[b0 >> 2]); | ||
jw.writeByte(BASE64_URL_CHARS[((b0 << 4) & 63) | (b1 >> 4)]); | ||
jw.writeByte(BASE64_URL_CHARS[(b1 << 2) & 63]); | ||
} | ||
} | ||
} |
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
...core/src/test/java/co/elastic/apm/agent/report/serialize/Base64SerializationUtilTest.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 co.elastic.apm.agent.report.serialize; | ||
|
||
import com.dslplatform.json.DslJson; | ||
import com.dslplatform.json.JsonWriter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Base64; | ||
import java.util.Random; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class Base64SerializationUtilTest { | ||
|
||
@Test | ||
public void empty() { | ||
JsonWriter jw = new DslJson<>(new DslJson.Settings<>()).newWriter(); | ||
Base64SerializationUtils.writeBytesAsBase64UrlSafe(new byte[0], jw); | ||
assertThat(jw.size()).isEqualTo(0); | ||
} | ||
|
||
@Test | ||
public void randomInputs() { | ||
DslJson<Object> dslJson = new DslJson<>(new DslJson.Settings<>()); | ||
|
||
Base64.Encoder reference = Base64.getUrlEncoder().withoutPadding(); | ||
|
||
Random rnd = new Random(42); | ||
for (int i = 0; i < 100_000; i++) { | ||
int len = rnd.nextInt(31) + 1; | ||
byte[] data = new byte[len]; | ||
rnd.nextBytes(data); | ||
|
||
String expectedResult = reference.encodeToString(data); | ||
|
||
JsonWriter jw = dslJson.newWriter(); | ||
Base64SerializationUtils.writeBytesAsBase64UrlSafe(data, jw); | ||
|
||
assertThat(jw.toString()).isEqualTo(expectedResult); | ||
} | ||
} | ||
} |
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.
The java
Base64
class used in the otel-distro is only available in Java 8+, that's why we need to add a custom implementation here. Also this implementation is allocation free, keeping it in line with the rest of the agent design.