Skip to content

Commit

Permalink
Fixes #4474 - Add a TraceExtension for tracing purposes (#4489)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Jan 10, 2025
1 parent 2cffc81 commit f6c0e29
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 1 deletion.
3 changes: 2 additions & 1 deletion feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
<module>impl</module>
<module>isolatedwebapp</module>
<module>logging</module>
<module>pid</module>
<module>trace</module>
<module>webapp</module>
<module>webapps</module>
<module>pid</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
49 changes: 49 additions & 0 deletions feature/trace/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>cloud.piranha.feature</groupId>
<artifactId>project</artifactId>
<version>25.1.0-SNAPSHOT</version>
</parent>

<artifactId>piranha-feature-trace</artifactId>
<packaging>jar</packaging>

<name>Piranha - Feature - Trace</name>

<dependencies>
<dependency>
<groupId>cloud.piranha.core</groupId>
<artifactId>piranha-core-impl</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-fileupload</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cloud.piranha.feature</groupId>
<artifactId>piranha-feature-impl</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cloud.piranha.http</groupId>
<artifactId>piranha-http-webapp</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2002-2025 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.feature.trace;

import cloud.piranha.core.impl.DefaultFilterChain;
import cloud.piranha.core.impl.DefaultInvocationFinder;
import cloud.piranha.core.impl.DefaultServletRequestManager;
import cloud.piranha.core.impl.DefaultWebApplication;
import cloud.piranha.core.impl.DefaultWebApplicationInputStream;
import cloud.piranha.core.impl.DefaultWebApplicationOutputStream;
import cloud.piranha.extension.fileupload.FileUploadMultiPartManager;
import cloud.piranha.feature.impl.DefaultFeature;
import cloud.piranha.http.webapp.HttpWebApplicationServer;
import cloud.piranha.http.webapp.HttpWebApplicationServerRequestMapper;
import static java.util.logging.Level.FINEST;
import java.util.logging.Logger;

/**
* The Trace feature.
*
* @author Manfred Riem ([email protected])
*/
public class TraceFeature extends DefaultFeature {

@Override
public void init() {
boolean enabled = Boolean.parseBoolean("CLOUD_PIRANHA_FEATURE_TRACE_ENABLED");
if (!enabled) {
enabled = Boolean.parseBoolean(
System.getProperty("cloud.piranha.feature.trace.enabled", "false"));
}
if (enabled) {
Logger logger = Logger.getLogger(DefaultFilterChain.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(DefaultInvocationFinder.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(DefaultServletRequestManager.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(DefaultWebApplication.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(DefaultWebApplication.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(DefaultWebApplicationInputStream.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(DefaultWebApplicationOutputStream.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(HttpWebApplicationServer.class.getName());
logger.setLevel(FINEST);
logger = Logger.getLogger(HttpWebApplicationServerRequestMapper.class.getName());
logger.setLevel(FINEST);

/*
* The following uses a try / catch as the extension is optionally
* available depending on the runtime.
*/
try {
logger = Logger.getLogger(FileUploadMultiPartManager.class.getName());
logger.setLevel(FINEST);
} catch(Throwable t) {
// swallow up
}
}
}
}
43 changes: 43 additions & 0 deletions feature/trace/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2025 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* This module delivers the TraceFeature.
*
* @author Manfred Riem ([email protected])
*/
module cloud.piranha.feature.trace {

exports cloud.piranha.feature.trace;
opens cloud.piranha.feature.trace;
requires transitive cloud.piranha.core.impl;
requires static cloud.piranha.extension.fileupload;
requires transitive cloud.piranha.feature.impl;
requires transitive cloud.piranha.http.webapp;
requires transitive java.logging;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2002-2025 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.feature.trace.tests;

import cloud.piranha.core.impl.DefaultFilterChain;
import cloud.piranha.feature.trace.TraceFeature;
import java.lang.System.Logger;
import static java.lang.System.Logger.Level.TRACE;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

/**
* The JUnit tests for the TraceFeature class.
*
* @author Manfred Riem ([email protected])
*/
class TraceFeatureTest {

/**
* Test init method
*/
@Test
void testInit() {
TraceFeature feature = new TraceFeature();
feature.init();
}
}
40 changes: 40 additions & 0 deletions feature/trace/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2002-2025 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* This module delivers the tests for the TraceFeature.
*
* @author Manfred Riem ([email protected])
*/
module cloud.piranha.feature.trace.tests {

exports cloud.piranha.feature.trace.tests;
opens cloud.piranha.feature.trace.tests;
requires cloud.piranha.feature.trace;
requires org.junit.jupiter.api;
}

0 comments on commit f6c0e29

Please sign in to comment.