-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate & improve dispatcher lifecycle
- Loading branch information
1 parent
e5ba2a2
commit aba72e4
Showing
16 changed files
with
268 additions
and
180 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
transactional-event-cdi-test/src/main/resources/testScoped.beans
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
com.github.jonasrutishauser.transactional.event.api.MPConfiguration | ||
com.github.jonasrutishauser.transactional.event.core.store.DispatcherImpl | ||
com.github.jonasrutishauser.transactional.event.core.store.Lifecycle | ||
com.github.jonasrutishauser.transactional.event.core.store.LockOwner | ||
com.github.jonasrutishauser.transactional.event.core.store.QueryAdapterFactory | ||
com.github.jonasrutishauser.transactional.event.core.store.PendingEventStore |
5 changes: 5 additions & 0 deletions
5
...-core/src/main/java/com/github/jonasrutishauser/transactional/event/core/cdi/Startup.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,5 @@ | ||
package com.github.jonasrutishauser.transactional.event.core.cdi; | ||
|
||
public interface Startup { | ||
|
||
} |
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
69 changes: 69 additions & 0 deletions
69
...ub/jonasrutishauser/transactional/event/core/opentelemetry/InstrumentedWorkProcessor.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,69 @@ | ||
package com.github.jonasrutishauser.transactional.event.core.opentelemetry; | ||
|
||
import static com.github.jonasrutishauser.transactional.event.core.opentelemetry.Instrumenter.EXCEPTION_ESCAPED; | ||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL; | ||
import static jakarta.interceptor.Interceptor.Priority.LIBRARY_BEFORE; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import com.github.jonasrutishauser.transactional.event.api.Events; | ||
import com.github.jonasrutishauser.transactional.event.core.store.WorkProcessor; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.StatusCode; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import jakarta.annotation.Priority; | ||
import jakarta.decorator.Decorator; | ||
import jakarta.decorator.Delegate; | ||
import jakarta.enterprise.inject.Any; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
|
||
@Decorator | ||
@Priority(LIBRARY_BEFORE) | ||
public class InstrumentedWorkProcessor implements WorkProcessor { | ||
|
||
private final WorkProcessor delegate; | ||
|
||
private final Tracer tracer; | ||
private final String lockOwnerId; | ||
|
||
InstrumentedWorkProcessor() { | ||
this(null, null, null); | ||
} | ||
|
||
@Inject | ||
InstrumentedWorkProcessor(@Delegate @Any WorkProcessor delegate, @Events Tracer tracer, | ||
@Named("lockOwner.id") String lockOwnerId) { | ||
this.delegate = delegate; | ||
this.tracer = tracer; | ||
this.lockOwnerId = lockOwnerId; | ||
} | ||
|
||
@Override | ||
public Callable<Boolean> get(String eventId) { | ||
Callable<Boolean> processor = delegate.get(eventId); | ||
return Context.current().wrap(() -> { | ||
Span span = tracer.spanBuilder("transactional-event process") // | ||
.setSpanKind(INTERNAL) // | ||
.setAttribute("messaging.system", "transactional-event") // | ||
.setAttribute("messaging.message_id", eventId) // | ||
.setAttribute("messaging.operation", "process") // | ||
.setAttribute("messaging.consumer_id", lockOwnerId) // | ||
.startSpan(); | ||
try (Scope unused = span.makeCurrent()) { | ||
return processor.call(); | ||
} catch (RuntimeException e) { | ||
span.setStatus(StatusCode.ERROR, e.getMessage()); | ||
span.recordException(e, Attributes.of(EXCEPTION_ESCAPED, true)); | ||
throw e; | ||
} finally { | ||
span.end(); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
Oops, something went wrong.