-
Notifications
You must be signed in to change notification settings - Fork 324
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
Universal profiling integration: Add stacktrace-IDs to transactions #3615
Merged
JonasKunz
merged 10 commits into
elastic:main
from
JonasKunz:stacktraces-on-transactions
May 6, 2024
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7b30a4e
Ported correlator
JonasKunz d1b257d
Implemented correlation
JonasKunz e8c41e1
Added tests and fixed uncovered bugs
JonasKunz 701af9f
Remove lambda
JonasKunz b2bdeac
Removed more java 8 usages, added missing license headers
JonasKunz d186c90
Fix test flake, fix native lib visibility issues
JonasKunz cd5760f
made config options public
JonasKunz 9986a3e
Added changelog
JonasKunz 50b902e
Fix reporting if correlation is not active
JonasKunz c2ef064
Reduce log spam
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 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 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 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
18 changes: 18 additions & 0 deletions
18
...nt-core/src/main/java/co/elastic/apm/agent/report/serialize/Base64SerializationUtils.java
This file contains 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
31 changes: 31 additions & 0 deletions
31
apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/Clock.java
This file contains 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,31 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.agent.universalprofiling; | ||
|
||
public interface Clock { | ||
|
||
Clock SYSTEM_NANOTIME = new Clock() { | ||
@Override | ||
public long getNanos() { | ||
return System.nanoTime(); | ||
} | ||
}; | ||
|
||
long getNanos(); | ||
} |
30 changes: 30 additions & 0 deletions
30
apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/MoveableEvent.java
This file contains 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,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.agent.universalprofiling; | ||
|
||
public interface MoveableEvent<SELF extends MoveableEvent<?>> { | ||
|
||
/** | ||
* Moves the content from this event into the provided other event. This event should be in a | ||
* resetted state after the call. | ||
*/ | ||
void moveInto(SELF other); | ||
|
||
void clear(); | ||
} |
90 changes: 90 additions & 0 deletions
90
apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/PeekingPoller.java
This file contains 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,90 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.agent.universalprofiling; | ||
|
||
import com.lmax.disruptor.EventFactory; | ||
import com.lmax.disruptor.EventPoller; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Wrapper around {@link EventPoller} which allows to "peek" elements. The provided event handling | ||
* callback can decide to not handle an event. In that case, the event will be provided again as | ||
* first element on the next call to {@link #poll(Handler)}. | ||
*/ | ||
public class PeekingPoller<Event extends MoveableEvent<Event>> { | ||
|
||
public interface Handler<Event extends MoveableEvent<Event>> { | ||
|
||
/** | ||
* Handles an event fetched from the ring buffer. | ||
* | ||
* @return true, if the event was handled and shall be removed. False if the event was not | ||
* handled, no further invocations of handleEvent are desired and the same event shall be | ||
* provided for the next {@link PeekingPoller#poll(Handler)} call. | ||
*/ | ||
boolean handleEvent(Event e); | ||
} | ||
|
||
private final EventPoller<Event> poller; | ||
private final Event peekedEvent; | ||
private boolean peekedEventPopulated; | ||
|
||
Handler<? super Event> currentHandler; | ||
private final EventPoller.Handler<Event> subHandler = new EventPoller.Handler<Event>() { | ||
@Override | ||
public boolean onEvent(Event event, long sequence, boolean endOfBatch) throws Exception { | ||
return handleEvent(event, sequence, endOfBatch); | ||
} | ||
}; | ||
|
||
public PeekingPoller(EventPoller<Event> wrappedPoller, EventFactory<Event> emptyEventFactory) { | ||
this.poller = wrappedPoller; | ||
peekedEvent = emptyEventFactory.newInstance(); | ||
peekedEventPopulated = false; | ||
} | ||
|
||
public synchronized void poll(Handler<? super Event> handler) throws Exception { | ||
if (peekedEventPopulated) { | ||
boolean handled = handler.handleEvent(peekedEvent); | ||
if (!handled) { | ||
return; | ||
} | ||
peekedEvent.clear(); | ||
peekedEventPopulated = false; | ||
} | ||
currentHandler = handler; | ||
try { | ||
poller.poll(subHandler); | ||
} finally { | ||
currentHandler = null; | ||
} | ||
} | ||
|
||
private boolean handleEvent(Event event, long sequence, boolean endOfBatch) { | ||
boolean handled = currentHandler.handleEvent(event); | ||
if (handled) { | ||
return true; | ||
} else { | ||
peekedEventPopulated = true; | ||
event.moveInto(peekedEvent); | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
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.
This class and the tests are a copy of https://github.com/elastic/elastic-otel-java/blob/main/universal-profiling-integration/src/main/java/co/elastic/otel/disruptor/PeekingPoller.java.
The only changes made are removal of Java-8 feature usages.