Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/java/org/apache/unomi/api/ContextResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.unomi.api.conditions.Condition;
import org.apache.unomi.api.services.RulesService;
import org.apache.unomi.tracing.api.TraceNode;

import java.io.Serializable;
import java.util.*;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class ContextResponse implements Serializable {

private Map<String, Consent> consents = new LinkedHashMap<>();

private TraceNode requestTracing;

/**
* Retrieves the profile identifier associated with the profile of the user on behalf of which the client performed the context request.
*
Expand Down Expand Up @@ -285,4 +288,12 @@ public Map<String, Consent> getConsents() {
public void setConsents(Map<String, Consent> consents) {
this.consents = consents;
}

public TraceNode getRequestTracing() {
return requestTracing;
}

public void setRequestTracing(TraceNode requestTracing) {
this.requestTracing = requestTracing;
}
}
15 changes: 15 additions & 0 deletions bom/artifacts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@
<artifactId>graphql-providers-sample</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-impl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-web-servlets</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-plugins-base</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion extensions/geonames/services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-impl</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
Expand Down
13 changes: 13 additions & 0 deletions extensions/groovy-actions/services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
<artifactId>unomi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-impl</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-metrics</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@
import org.apache.unomi.api.actions.Action;
import org.apache.unomi.api.actions.ActionDispatcher;
import org.apache.unomi.api.services.DefinitionsService;
import org.apache.unomi.api.services.EventService;
import org.apache.unomi.groovy.actions.services.GroovyActionsService;
import org.apache.unomi.metrics.MetricAdapter;
import org.apache.unomi.metrics.MetricsService;
import org.apache.unomi.services.actions.ActionExecutorDispatcher;
import org.apache.unomi.tracing.api.TracerService;
import org.apache.unomi.tracing.api.RequestTracer;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;

/**
* High-performance ActionDispatcher for pre-compiled Groovy scripts.
* Executes scripts without GroovyShell overhead using isolated instances.
Expand All @@ -46,6 +53,7 @@ public class GroovyActionDispatcher implements ActionDispatcher {
private GroovyActionsService groovyActionsService;
private DefinitionsService definitionsService;
private ActionExecutorDispatcher actionExecutorDispatcher;
private TracerService tracerService;

@Reference
public void setMetricsService(MetricsService metricsService) {
Expand All @@ -67,32 +75,57 @@ public void setActionExecutorDispatcher(ActionExecutorDispatcher actionExecutorD
this.actionExecutorDispatcher = actionExecutorDispatcher;
}

@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
public void setTracerService(TracerService tracerService) {
this.tracerService = tracerService;
}

public void unsetTracerService(TracerService tracerService) {
this.tracerService = null;
}

public String getPrefix() {
return GROOVY_PREFIX;
}

public Integer execute(Action action, Event event, String actionName) {
Class<? extends Script> scriptClass = groovyActionsService.getCompiledScript(actionName);
if (scriptClass == null) {
LOGGER.warn("Couldn't find a Groovy action with name {}, action will not execute!", actionName);
return 0;
final RequestTracer tracer = (tracerService != null && tracerService.isTracingEnabled())
? tracerService.getCurrentTracer() : null;
if (tracer != null) {
tracer.startOperation("groovy-action", "Executing Groovy action", new HashMap<String, Object>() {{
put("action.name", actionName);
put("action.type", action.getActionTypeId());
put("event.type", event.getEventType());
}});
}

Comment thread
sergehuber marked this conversation as resolved.
try {
Script script = scriptClass.getDeclaredConstructor().newInstance();
setScriptVariables(script, action, event);

return new MetricAdapter<Integer>(metricsService, this.getClass().getName() + ".action.groovy." + actionName) {
@Override
public Integer execute(Object... args) throws Exception {
return (Integer) script.invokeMethod("execute", null);
}
}.runWithTimer();

} catch (Exception e) {
LOGGER.error("Error executing Groovy action with key={}", actionName, e);
Class<? extends Script> scriptClass = groovyActionsService.getCompiledScript(actionName);
if (scriptClass == null) {
LOGGER.warn("Couldn't find a Groovy action with name {}, action will not execute!", actionName);
if (tracer != null) tracer.trace("Action not found", null);
return EventService.NO_CHANGE;
}

try {
Script script = scriptClass.getDeclaredConstructor().newInstance();
setScriptVariables(script, action, event);

return new MetricAdapter<Integer>(metricsService, this.getClass().getName() + ".action.groovy." + actionName) {
@Override
public Integer execute(Object... args) throws Exception {
return (Integer) script.invokeMethod("execute", null);
}
}.runWithTimer();

} catch (Exception e) {
LOGGER.error("Error executing Groovy action with key={}", actionName, e);
if (tracer != null) tracer.trace("Error executing action", e);
return EventService.NO_CHANGE;
}
} finally {
if (tracer != null) tracer.endOperation(null, "Completed Groovy action execution");
}
return 0;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions extensions/json-schema/services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
<artifactId>unomi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-impl</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-persistence-spi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.apache.unomi.schema.api.ValidationError;
import org.apache.unomi.schema.api.ValidationException;
import org.apache.unomi.schema.keyword.ScopeKeyword;
import org.apache.unomi.tracing.api.RequestTracer;
import org.apache.unomi.tracing.api.TracerService;
import org.apache.unomi.services.common.cache.AbstractMultiTypeCachingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -78,6 +80,7 @@ public class SchemaServiceImpl extends AbstractMultiTypeCachingService implement
private Integer jsonSchemaRefreshInterval = 1000;

private ScopeService scopeService;
private TracerService tracerService;

// Map to store tenant-specific JsonSchemaFactory instances
private final ConcurrentMap<String, JsonSchemaFactory> tenantJsonSchemaFactories = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -375,6 +378,14 @@ private Set<ValidationError> validate(JsonNode jsonNode, JsonSchema jsonSchema)
}
}

// Add validation info to trace if tracing is enabled
if (tracerService != null) {
RequestTracer tracer = tracerService.getCurrentTracer();
if (tracer != null && tracer.isEnabled()) {
tracer.addValidationInfo(validationMessages, jsonSchema.getCurrentUri().toString());
}
}

return validationMessages != null ?
validationMessages.stream()
.map(validationMessage -> new ValidationError(validationMessage.getMessage()))
Expand Down Expand Up @@ -594,6 +605,10 @@ public void setJsonSchemaRefreshInterval(Integer jsonSchemaRefreshInterval) {
this.jsonSchemaRefreshInterval = jsonSchemaRefreshInterval;
}

public void setTracerService(TracerService tracerService) {
this.tracerService = tracerService;
}

/**
* Refreshes schema extensions and factories with the provided schemas map.
* This method encapsulates the common logic needed after schema changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<reference id="scopeService" interface="org.apache.unomi.api.services.ScopeService"/>
<reference id="tenantService" interface="org.apache.unomi.api.tenants.TenantService"/>
<reference id="contextManager" interface="org.apache.unomi.api.services.ExecutionContextManager"/>
<reference id="tracerService" interface="org.apache.unomi.tracing.api.TracerService"/>
<reference id="schedulerService" interface="org.apache.unomi.api.services.SchedulerService" timeout="2000"/>
<reference id="cacheService" interface="org.apache.unomi.api.services.cache.MultiTypeCacheService" />

Expand All @@ -44,6 +45,7 @@
<property name="scopeService" ref="scopeService"/>
<property name="tenantService" ref="tenantService"/>
<property name="contextManager" ref="contextManager"/>
<property name="tracerService" ref="tracerService"/>
<property name="jsonSchemaRefreshInterval" value="${json.schema.refresh.interval}"/>
<property name="schedulerService" ref="schedulerService"/>
<property name="bundleContext" ref="blueprintBundleContext" />
Expand Down
8 changes: 7 additions & 1 deletion extensions/router/router-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-impl</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
Expand Down
8 changes: 7 additions & 1 deletion itests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
<artifactId>awaitility</artifactId>
<version>3.1.6</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
Expand Down
5 changes: 5 additions & 0 deletions kar/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
<bundle>mvn:org.apache.unomi/unomi-lifecycle-watcher/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-api/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-common/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-tracing-api/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-tracing-impl/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-scripting/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-metrics/${project.version}</bundle>
<bundle>mvn:org.apache.unomi/unomi-persistence-spi/${project.version}</bundle>
Expand Down Expand Up @@ -130,10 +132,13 @@
<feature>unomi-cxs-privacy-extension-services</feature>
<configfile finalname="/etc/org.apache.unomi.schema.cfg">mvn:org.apache.unomi/unomi-json-schema-services/${project.version}/cfg/schemacfg</configfile>
<configfile finalname="/etc/org.apache.unomi.rest.authentication.cfg">mvn:org.apache.unomi/unomi-rest/${project.version}/cfg/restauth</configfile>
<!-- Legacy servlet forwarders (HTTP Whiteboard) and their configuration -->
<configfile finalname="/etc/org.apache.unomi.web.cfg">mvn:org.apache.unomi/unomi-web-servlets/${project.version}/cfg/unomicfg</configfile>
<bundle start="false">mvn:org.apache.unomi/unomi-json-schema-services/${project.version}</bundle>
<bundle start="false">mvn:org.apache.unomi/unomi-rest/${project.version}</bundle>
<bundle start="false">mvn:org.apache.unomi/unomi-json-schema-rest/${project.version}</bundle>
<bundle start="false">mvn:org.apache.unomi/cxs-lists-extension-actions/${project.version}</bundle>
<bundle start="false">mvn:org.apache.unomi/unomi-web-servlets/${project.version}</bundle>
</feature>

<feature name="unomi-cxs-lists-extension" description="Apache Unomi :: Extensions :: Lists" version="${project.version}">
Expand Down
2 changes: 1 addition & 1 deletion package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<artifactItems>
<artifactItem>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-wab</artifactId>
<artifactId>unomi-web-servlets</artifactId>
<classifier>unomicfg</classifier>
<type>cfg</type>
<outputDirectory>${project.build.directory}/assembly/etc</outputDirectory>
Expand Down
7 changes: 7 additions & 0 deletions persistence-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
<artifactId>unomi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-tracing-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.unomi</groupId>
<artifactId>unomi-scripting</artifactId>
Expand Down
Loading
Loading