-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Universal profiling integration: Add stacktrace-IDs to transactions (#…
- Loading branch information
Showing
14 changed files
with
871 additions
and
25 deletions.
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
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.