Skip to content
Draft
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d71ecb5
CAUSEWAY-3975: Open Telemetry Integration
andi-huber Mar 20, 2026
743a259
CAUSEWAY-3975: work on simplified InteractionService
andi-huber Mar 20, 2026
67f8b8d
CAUSEWAY-3975: consolidating custom request processing logic (wicket)
andi-huber Mar 20, 2026
b48185e
CAUSEWAY-3975: interaction is too short lived
andi-huber Mar 20, 2026
1002386
CAUSEWAY-3975: interaction creation fixes
andi-huber Mar 21, 2026
e1ee5c6
CAUSEWAY-3975: proper observation scope closing
andi-huber Mar 21, 2026
88c5a0b
CAUSEWAY-3975: factors out RehydrationHandler
andi-huber Mar 21, 2026
b5a170b
CAUSEWAY-3975: adds observation 'Causeway Layered Interaction'
andi-huber Mar 21, 2026
7258e3d
CAUSEWAY-3975: cleaning up
andi-huber Mar 21, 2026
ee86612
CAUSEWAY-3975: separation of concerns (mm init)
andi-huber Mar 21, 2026
292dcd1
CAUSEWAY-3975: revert intro of TestSupport (1)
andi-huber Mar 21, 2026
708bbcb
CAUSEWAY-3975: revert intro of TestSupport (2)
andi-huber Mar 21, 2026
1479476
CAUSEWAY-3975: adds default
andi-huber Mar 22, 2026
a6a24de
CAUSEWAY-3975: adds request path to top level observation name
andi-huber Mar 22, 2026
125820d
CAUSEWAY-3975: on interaction start provide user info
andi-huber Mar 23, 2026
22c2176
CAUSEWAY-3975: renaming integration
andi-huber Mar 26, 2026
0dfb7f4
CAUSEWAY-3975: adds transaction observation
andi-huber Mar 26, 2026
ed6a660
CAUSEWAY-3975: use prefix for causeway tags
andi-huber Mar 26, 2026
430e258
CAUSEWAY-3975: adds telemetries for JpaEntityFacet
andi-huber Mar 27, 2026
3b6508a
CAUSEWAY-3975: proper span exporting filter
andi-huber Mar 27, 2026
7fd5e40
CAUSEWAY-3975: ajax detector
andi-huber Mar 27, 2026
a33c792
CAUSEWAY-3975: report interaction details (locale, clock, ..)
andi-huber Mar 27, 2026
ce13999
CAUSEWAY-3975: observe member execution (act invoke, prop change)
andi-huber Mar 27, 2026
3f12327
CAUSEWAY-3975: observe execution publishing
andi-huber Mar 27, 2026
60d7627
CAUSEWAY-3975: observing CausewayInteraction (wip)
andi-huber Mar 28, 2026
422f4a7
CAUSEWAY-3975: moves CausewayObservationIntegration to config, so we can
andi-huber Mar 28, 2026
1cb8252
CAUSEWAY-3975: fleshes out CausewayObservationAutoConfiguration
andi-huber Mar 28, 2026
442a90e
CAUSEWAY-3975: consolidates observation configuration in single class
andi-huber Mar 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/applib/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
requires transitive spring.web;
requires spring.tx;
requires org.slf4j;
requires micrometer.observation;

// JAXB viewmodels
opens org.apache.causeway.applib.annotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,71 @@
*/
package org.apache.causeway.applib.services.iactnlayer;

import org.jspecify.annotations.Nullable;

import org.apache.causeway.applib.services.iactn.Interaction;
import org.apache.causeway.commons.functional.Try;

/**
* Binds an {@link Interaction} ("what" is being executed) with
* an {@link InteractionContext} ("who" is executing, "when" and "where").
*
* <p>
* {@link InteractionLayer}s are so called because they may be nested (held in a stack). For example the
* <p> {@link InteractionLayer}s are so called because they may be nested (held in a stack). For example the
* {@link org.apache.causeway.applib.services.sudo.SudoService} creates a new temporary layer with a different
* {@link InteractionContext#getUser() user}, while fixtures that mock the clock switch out the
* {@link InteractionContext#getClock() clock}.
* </p>
*
* <p>
* The stack of layers is per-thread, managed by {@link InteractionService} as a thread-local).
* </p>
* <p> The stack of layers is per-thread, managed by {@link InteractionService} as a thread-local).
*
* @since 2.0 {@index}
*/
public record InteractionLayer(
@Nullable InteractionLayer parent,
/**
* Current thread's {@link Interaction} : &quot;what&quot; is being executed
* Current thread's {@link Interaction} : WHAT is being executed
*/
Interaction interaction,

/**
* &quot;who&quot; is performing this {@link #getInteraction()}, also
* &quot;when&quot; and &quot;where&quot;.
* WHO is performing this {@link #getInteraction()}, also
* WHEN and WHERE.
*/
InteractionContext interactionContext,
/**
* @since 4.0
*/
InteractionContext interactionContext
) {
Runnable onCloseCallback) implements AutoCloseable {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that as the final answer, because we don't really know how to handle potential exceptions of the runnable.


public boolean isRoot() {
return parent==null;
}

public int parentCount() {
return parent!=null
? 1 + parent.parentCount()
: 0;
}

public int totalLayerCount() {
return 1 + parentCount();
}

public InteractionLayer rootLayer() {
return parent!=null
? parent.rootLayer()
: this;
}

@Override
public void close() {
Try.run(onCloseCallback::run); // ignores exceptions
}

public void closeAll() {
close();
if(parent!=null) {
parent.closeAll();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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 org.apache.causeway.applib.services.iactnlayer;

import java.util.Optional;
import java.util.function.Predicate;

import org.jspecify.annotations.Nullable;

import org.apache.causeway.applib.services.iactn.Interaction;
import org.apache.causeway.commons.internal.observation.ObservationClosure;

import io.micrometer.observation.Observation;

public final class InteractionLayerStack {

// TODO: reading the javadoc for TransactionSynchronizationManager and looking at the implementations
// of TransactionSynchronization (in particular SpringSessionSynchronization), I suspect that this
// ThreadLocal would be considered bad practice and instead should be managed using the TransactionSynchronization mechanism.
private final ThreadLocal<InteractionLayer> threadLocalLayer = new ThreadLocal<>();

public Optional<InteractionLayer> currentLayer() {
return Optional.ofNullable(threadLocalLayer.get());
}

public InteractionLayer push(
final Interaction interaction,
final InteractionContext interactionContext,
final Observation observation) {
var parent = currentLayer().orElse(null);
@SuppressWarnings("resource")
var newLayer = new InteractionLayer(parent, interaction, interactionContext,
// on-close callback
new ObservationClosure().startAndOpenScope(observation)::close);
threadLocalLayer.set(newLayer);
return newLayer;
}

public void clear() {
currentLayer().ifPresent(InteractionLayer::closeAll);
threadLocalLayer.remove();
}

public boolean isEmpty() {
return threadLocalLayer.get()==null;
}

public int size() {
return currentLayer()
.map(InteractionLayer::totalLayerCount)
.orElse(0);
}

@Nullable
public InteractionLayer peek() {
return threadLocalLayer.get();
}

@Nullable
public InteractionLayer pop() {
var current = threadLocalLayer.get();
if(current==null) return null;

var newTop = current.parent();
current.close();
return set(newTop);
}

public void popWhile(final Predicate<InteractionLayer> condition) {
while(!isEmpty()) {
if(!condition.test(peek())) return;
pop();
}
}

// -- HELPER

private InteractionLayer set(@Nullable final InteractionLayer layer) {
if(layer != null) {
threadLocalLayer.set(layer);
} else {
threadLocalLayer.remove();
}
return layer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import java.util.concurrent.Callable;

import org.jspecify.annotations.NonNull;

import org.apache.causeway.commons.functional.ThrowingRunnable;
import org.apache.causeway.commons.functional.Try;

import org.jspecify.annotations.NonNull;

/**
* A low-level service to programmatically create a short-lived interaction or session.
*
Expand Down
12 changes: 12 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,18 @@ identified
<version>${jdom.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-opentelemetry</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions commons/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
exports org.apache.causeway.commons.internal.html;
exports org.apache.causeway.commons.internal.image;
exports org.apache.causeway.commons.internal.ioc;
exports org.apache.causeway.commons.internal.observation;
exports org.apache.causeway.commons.internal.os;
exports org.apache.causeway.commons.internal.primitives;
exports org.apache.causeway.commons.internal.proxy;
Expand All @@ -67,6 +68,8 @@
requires transitive tools.jackson.core;
requires transitive tools.jackson.databind;
requires transitive tools.jackson.module.jakarta.xmlbind;
requires transitive micrometer.commons;
requires transitive micrometer.observation;
requires transitive org.jdom2;
requires transitive org.jspecify;
requires transitive org.jsoup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.causeway.commons.having;

import java.util.Optional;
import java.util.function.Function;

public interface HasTypeSpecificAttributes {
Expand All @@ -31,6 +32,10 @@ public interface HasTypeSpecificAttributes {
/** get type specific attribute */
<T> T getAttribute(Class<T> type);

default <T> Optional<T> lookupAttribute(final Class<T> type) {
return Optional.ofNullable(getAttribute(type));
}

/** remove type specific attribute */
void removeAttribute(Class<?> type);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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 org.apache.causeway.commons.internal.observation;

import java.util.function.Supplier;

import org.jspecify.annotations.Nullable;

import lombok.Getter;
import lombok.experimental.Accessors;

import io.micrometer.common.KeyValue;
import io.micrometer.observation.Observation;
import io.micrometer.observation.Observation.Scope;

/**
* Helps if start and stop of an {@link Observation} happen in different code locations.
*/
@Getter @Accessors(fluent = true)
public final class ObservationClosure implements AutoCloseable {

public static final KeyValue DISCARD_KEY = KeyValue.of("causeway.discard", "");

private Observation observation;
private Scope scope;

public ObservationClosure startAndOpenScope(final Observation observation) {
if(observation==null) return this;
this.observation = observation.start();
this.scope = observation.openScope();
return this;
}

@Override
public void close() {
if(observation==null) return;
if(scope!=null) {
this.scope.close();
this.scope = null;
}
observation.stop();
}

public void onError(final Exception ex) {
if(observation==null) return;
// scope lifecycle terminates before exception handling
if(scope!=null) {
this.scope.close();
this.scope = null;
}
observation.error(ex);
}

public ObservationClosure tag(final String key, @Nullable final Supplier<? extends Object> valueSupplier) {
if(observation==null || valueSupplier == null) return this;
try {
observation.highCardinalityKeyValue(key, "" + valueSupplier.get());
} catch (Exception e) {
observation.highCardinalityKeyValue(key, "EXCEPTION: " + e.getMessage());
}
return this;
}

public void discard() {
discard(this.observation);
close();
}

// -- UTILITY

/**
* Denies span export, in collaboration with a Spring registered {@link DiscardedSpanExportingPredicate}.
*/
public static void discard(@Nullable final Observation obs) {
if(obs == null)
return;
obs.lowCardinalityKeyValue(DISCARD_KEY);
}

}
5 changes: 5 additions & 0 deletions core/config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
</dependency>

<!--
as per https://github.com/spring-projects/spring-boot/issues/30986, must be
Expand Down
7 changes: 6 additions & 1 deletion core/config/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
exports org.apache.causeway.core.config.metamodel.facets;
exports org.apache.causeway.core.config.metamodel.services;
exports org.apache.causeway.core.config.metamodel.specloader;
exports org.apache.causeway.core.config.observation;
exports org.apache.causeway.core.config.presets;
exports org.apache.causeway.core.config.progmodel;
exports org.apache.causeway.core.config.util;
Expand All @@ -44,12 +45,16 @@
requires jakarta.validation;
requires jakarta.inject;
requires org.hibernate.validator;
requires transitive micrometer.commons;
requires transitive micrometer.observation;
requires transitive micrometer.tracing;
requires transitive spring.boot;
requires spring.aop;
requires spring.beans;
requires transitive spring.boot;
requires spring.context;
requires spring.core;
requires spring.tx;
requires spring.boot.autoconfigure;
requires org.slf4j;

opens org.apache.causeway.core.config to spring.core, org.hibernate.validator;
Expand Down
Loading