You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2019/10/18 11:27:06 UTC
[isis] 02/03: ISIS-2164: Dummy example
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2164
in repository https://gitbox.apache.org/repos/asf/isis.git
commit baaedf59ab90f1668a4562abf3ab944ed768df29
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Oct 18 12:10:04 2019 +0100
ISIS-2164: Dummy example
---
core/pom.xml | 49 ++++--
core/runtime/pom.xml | 27 ++--
.../isis/core/webapp/OpenTracingBootstrapper.java | 95 ++++++++++++
.../isis/core/webapp/TracingZipkinFilter.java | 115 --------------
core/tracing/pom.xml | 79 ++++++++++
.../integration/wicket/WebRequestCycleForIsis.java | 169 +++++++++++++--------
.../viewer/wicket/ui/ComponentFactoryAbstract.java | 14 +-
.../CollectionContentsAsAjaxTablePanel.java | 2 +-
example/application/helloworld/pom.xml | 37 -----
.../helloworld/src/main/java/Dummy.java | 152 ++++++++++++++++++
.../java/domainapp/dom/impl/HelloWorldObjects.java | 18 ++-
.../src/main/java/tracing/ThreadLocalScope2.java | 37 +++++
.../java/tracing/ThreadLocalScopeManager2.java | 90 +++++++++++
.../src/main/webapp/WEB-INF/logging.properties | 4 +-
.../helloworld/src/main/webapp/WEB-INF/web.xml | 23 +--
15 files changed, 646 insertions(+), 265 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index 92567b7..14da3c6 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -180,9 +180,11 @@
<javax-mail.version>1.4.7</javax-mail.version>
<jboss-jaxrs-api_2.0_spec.version>1.0.0.Final</jboss-jaxrs-api_2.0_spec.version>
- <brave.version>5.8.0</brave.version>
- <okhttp.version>3.9.1</okhttp.version>
- <brave-opentracing.version>0.34.2</brave-opentracing.version>
+ <jaeger-client.version>1.0.0</jaeger-client.version>
+
+ <lombok.version>1.18.8</lombok.version>
+ <opentracing-web-servlet-filter.version>0.4.0</opentracing-web-servlet-filter.version>
+ <opentracing-metrics-micrometer.version>0.3.0</opentracing-metrics-micrometer.version>
</properties>
<scm>
@@ -2059,23 +2061,33 @@ ${license.additional-notes}
</dependency>
<dependency>
- <groupId>io.zipkin.brave</groupId>
- <artifactId>brave-bom</artifactId>
- <version>${brave.version}</version>
- <type>pom</type>
- <scope>import</scope>
+ <groupId>io.jaegertracing</groupId>
+ <artifactId>jaeger-client</artifactId>
+ <version>${jaeger-client.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.jaegertracing</groupId>
+ <artifactId>jaeger-core</artifactId>
+ <version>${jaeger-client.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.jaegertracing</groupId>
+ <artifactId>jaeger-micrometer</artifactId>
+ <version>${jaeger-client.version}</version>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp3</groupId>
- <artifactId>okhttp</artifactId>
- <version>${okhttp.version}</version>
+ <groupId>io.opentracing.contrib</groupId>
+ <artifactId>opentracing-web-servlet-filter</artifactId>
+ <version>${opentracing-web-servlet-filter.version}</version>
</dependency>
<dependency>
- <groupId>io.opentracing.brave</groupId>
- <artifactId>brave-opentracing</artifactId>
- <version>${brave-opentracing.version}</version>
+ <groupId>io.opentracing.contrib</groupId>
+ <artifactId>opentracing-metrics-micrometer</artifactId>
+ <version>${opentracing-metrics-micrometer.version}</version>
</dependency>
</dependencies>
@@ -2112,6 +2124,15 @@ ${license.additional-notes}
<artifactId>objenesis</artifactId>
<scope>test</scope>
</dependency>
+
+ <!-- PROVIDED DEPENDENCIES -->
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>${lombok.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<profiles>
diff --git a/core/runtime/pom.xml b/core/runtime/pom.xml
index db0c10c..fbec4b2 100644
--- a/core/runtime/pom.xml
+++ b/core/runtime/pom.xml
@@ -128,33 +128,40 @@
</dependency>
<dependency>
- <groupId>io.zipkin.brave</groupId>
- <artifactId>brave-instrumentation-servlet</artifactId>
- <version>${brave.version}</version>
+ <groupId>io.jaegertracing</groupId>
+ <artifactId>jaeger-client</artifactId>
</dependency>
<dependency>
- <groupId>io.zipkin.reporter2</groupId>
- <artifactId>zipkin-sender-okhttp3</artifactId>
- <version>${zipkin-sender-okhttp3.version}</version>
+ <groupId>io.jaegertracing</groupId>
+ <artifactId>jaeger-core</artifactId>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp3</groupId>
- <artifactId>okhttp</artifactId>
+ <groupId>io.opentracing.contrib</groupId>
+ <artifactId>opentracing-web-servlet-filter</artifactId>
</dependency>
<dependency>
- <groupId>io.opentracing.brave</groupId>
- <artifactId>brave-opentracing</artifactId>
+ <groupId>io.jaegertracing</groupId>
+ <artifactId>jaeger-micrometer</artifactId>
</dependency>
+
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- PROVIDED DEPENDENCIES -->
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>${lombok.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<profiles>
diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/OpenTracingBootstrapper.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/OpenTracingBootstrapper.java
new file mode 100644
index 0000000..337423c
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/OpenTracingBootstrapper.java
@@ -0,0 +1,95 @@
+/*
+ * 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.isis.core.webapp;
+
+import java.util.concurrent.Callable;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import io.jaegertracing.Configuration;
+import io.jaegertracing.internal.samplers.ConstSampler;
+import io.jaegertracing.micrometer.MicrometerMetricsFactory;
+import io.opentracing.Tracer;
+import io.opentracing.util.GlobalTracer;
+import lombok.val;
+
+public class OpenTracingBootstrapper implements ServletContextListener {
+
+
+ @Override
+ public void contextInitialized(final ServletContextEvent servletContextEvent) {
+
+ final String openTracingServiceName =
+ initParamFrom(servletContextEvent, "openTracingServiceName", "apache-isis-app");
+
+ GlobalTracer.registerIfAbsent(new Callable<Tracer>() {
+ @Override public Tracer call() {
+
+ val samplerConfig = Configuration.SamplerConfiguration.fromEnv()
+ .withType(ConstSampler.TYPE)
+ .withParam(1);
+
+ // to demo, use:
+ //
+ // * docker run -d -p 5775:5775/udp -p 16686:16686 jaegertracing/all-in-one:latest
+ // * access at http://localhost:16686)
+ //
+ // * run the app with:
+ //
+ // -DJAEGER_AGENT_HOST=localhost -DJAEGER_AGENT_PORT=5775
+ //
+ val reporterConfig = Configuration.ReporterConfiguration.fromEnv()
+ .withLogSpans(true)
+ .withSender(Configuration.SenderConfiguration.fromEnv());
+
+
+ val config = new Configuration(openTracingServiceName)
+ .withSampler(samplerConfig)
+ .withReporter(reporterConfig)
+ ;
+
+ // https://github.com/jaegertracing/jaeger-client-java/tree/master/jaeger-micrometer
+ val metricsReporter = new MicrometerMetricsFactory();
+
+ return config
+ .getTracerBuilder()
+ .withMetricsFactory(metricsReporter)
+ .build();
+ }
+ });
+
+ }
+
+ @Override
+ public void contextDestroyed(final ServletContextEvent servletContextEvent) {
+
+ }
+
+ private static String initParamFrom(
+ final ServletContextEvent ev,
+ final String paramName,
+ final String defaultValue) {
+ final String value = ev.getServletContext().getInitParameter(paramName);
+ return value != null ? value : defaultValue;
+ }
+
+
+}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/TracingZipkinFilter.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/TracingZipkinFilter.java
deleted file mode 100644
index 51820fe..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/webapp/TracingZipkinFilter.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.isis.core.webapp;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import brave.Tracer;
-import brave.Tracing;
-import brave.propagation.B3Propagation;
-import brave.propagation.ExtraFieldPropagation;
-import brave.servlet.TracingFilter;
-import zipkin2.Span;
-import zipkin2.reporter.AsyncReporter;
-import zipkin2.reporter.Sender;
-import zipkin2.reporter.okhttp3.OkHttpSender;
-
-public class TracingZipkinFilter implements Filter {
-
- Sender sender;
- AsyncReporter<Span> spanReporter;
- Tracing tracing;
- Filter delegate ;
- ExtraFieldPropagation.Factory propagationFactory;
- Tracer tracer;
-
- @Override
- public void init(final FilterConfig filterConfig) {
-
- final String tracingEndpoint = initParamFrom(filterConfig, "tracingEndpoint", null);
- if(tracingEndpoint == null) {
- return;
- }
- sender = OkHttpSender.create(tracingEndpoint);
- spanReporter = AsyncReporter.create(sender);
-
- propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
- .addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id"))
- .build();
-
- final String tracingLocalServiceName = initParamFrom(filterConfig, "tracingLocalServiceName", "apache-isis-app");
- tracing = Tracing.newBuilder()
- .localServiceName(tracingLocalServiceName)
- .propagationFactory(propagationFactory)
- .spanReporter(spanReporter)
- .build();
-
- tracer = tracing.tracer();
-
-// tracer = BraveTracer.create(tracing);
- delegate = TracingFilter.create(tracing);
- }
-
- private static String initParamFrom(
- final FilterConfig filterConfig,
- final String paramName,
- final String defaultValue) {
- final String value = filterConfig.getInitParameter(paramName);
- return value != null ? value : defaultValue;
- }
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws IOException, ServletException {
- if(delegate != null) {
-
- request.setAttribute("isis.tracer.zipkin.brave", tracer);
-
- delegate.doFilter(request, response, chain);
- } else {
- chain.doFilter(request, response);
- }
- }
-
- @Override
- public void destroy() {
- try {
- if(tracing != null) {
- tracing.close(); // disables Tracing.current()
- }
- if(spanReporter != null) {
- spanReporter.close(); // stops reporting thread and flushes data
- }
- if(sender != null) {
- sender.close(); // closes any transport resources
- }
- } catch (IOException e) {
- // do something real
- }
- }
-}
diff --git a/core/tracing/pom.xml b/core/tracing/pom.xml
new file mode 100644
index 0000000..46ea738
--- /dev/null
+++ b/core/tracing/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<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 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis</artifactId>
+ <version>${revision}</version>
+ </parent>
+
+ <artifactId>isis-core-tracing</artifactId>
+ <name>Apache Isis Tracing Impls</name>
+
+ <properties>
+ <jar-plugin.automaticModuleName>org.apache.isis.core.tracing</jar-plugin.automaticModuleName>
+ <git-plugin.propertiesDir>org/apache/isis/core/tracing</git-plugin.propertiesDir>
+ </properties>
+
+ <dependencies>
+
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>flatten</id>
+ <activation>
+ <property>
+ <name>!skip.flatten</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>flatten-maven-plugin</artifactId>
+ <version>1.0.0</version>
+ <executions>
+ <execution>
+ <id>flatten</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>flatten</goal>
+ </goals>
+ <configuration>
+ <flattenMode>defaults</flattenMode>
+ <updatePomFile>true</updatePomFile>
+ <pomElements>
+ <name>resolve</name>
+ <description>resolve</description>
+ <dependencies>resolve</dependencies>
+ </pomElements>
+ </configuration>
+ </execution>
+ <execution>
+ <id>flatten.clean</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+
+</project>
diff --git a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
index b315a4b..5c3abf2 100644
--- a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
+++ b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
@@ -23,8 +23,6 @@ import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Set;
-import javax.servlet.http.HttpServletRequest;
-
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
@@ -75,10 +73,10 @@ import org.apache.isis.viewer.wicket.ui.pages.login.WicketSignInPage;
import org.apache.isis.viewer.wicket.ui.pages.mmverror.MmvErrorPage;
import org.apache.isis.viewer.wicket.ui.panels.PromptFormAbstract;
-import brave.Span;
-import brave.Tracer;
-import brave.opentracing.BraveTracer;
-import brave.propagation.ThreadLocalSpan;
+//import brave.Span;
+//import brave.Tracer;
+//import brave.opentracing.BraveTracer;
+//import brave.propagation.ThreadLocalSpan;
/**
* Isis-specific implementation of the Wicket's {@link RequestCycle},
@@ -106,6 +104,12 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
return;
}
+// final Span span = GlobalTracer.get().activeSpan();
+// final Span onBeginRequest = GlobalTracer.get().buildSpan("wicket-request-cycle")
+// .withTag("started-by", "onBeginRequest")
+// .withTag("requestCycle.request.url", requestCycle.getRequest().getUrl().toString())
+// .start();
+
// final Span span = ThreadLocalSpan.CURRENT_TRACER.next()
// .name("WebRequestCycleForIsis#onBeginRequest")
// .tag("started-by", "onBeginRequest")
@@ -123,18 +127,18 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
}
- private static BraveTracer tracerFrom(final RequestCycle requestCycle) {
- final Object containerRequest = requestCycle.getRequest().getContainerRequest();
- if (!(containerRequest instanceof HttpServletRequest)) {
- return null;
- }
- final HttpServletRequest httpServletRequest = (HttpServletRequest) containerRequest;
- final Object tracerObj = httpServletRequest.getAttribute("isis.tracer.zipkin.brave");
- if (!(tracerObj instanceof BraveTracer)) {
- return null;
- }
- return (BraveTracer) tracerObj;
- }
+// private static BraveTracer tracerFrom(final RequestCycle requestCycle) {
+// final Object containerRequest = requestCycle.getRequest().getContainerRequest();
+// if (!(containerRequest instanceof HttpServletRequest)) {
+// return null;
+// }
+// final HttpServletRequest httpServletRequest = (HttpServletRequest) containerRequest;
+// final Object tracerObj = httpServletRequest.getAttribute("isis.tracer.zipkin.brave");
+// if (!(tracerObj instanceof BraveTracer)) {
+// return null;
+// }
+// return (BraveTracer) tracerObj;
+// }
@Override
public void onRequestHandlerResolved(final RequestCycle cycle, final IRequestHandler handler) {
@@ -172,31 +176,33 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
AdapterManager.ConcurrencyChecking.reset(AdapterManager.ConcurrencyChecking.CHECK);
}
- final ThreadLocalSpan tracer = ThreadLocalSpan.CURRENT_TRACER;
- final Tracer tracerIfAny = tracerFrom(cycle);
+// final ThreadLocalSpan tracer = ThreadLocalSpan.CURRENT_TRACER;
+// final Tracer tracerIfAny = tracerFrom(cycle);
if (getIsisSessionFactory().inSession()) {
try {
// will commit (or abort) the transaction;
// an abort will cause the exception to be thrown.
getTransactionManager().endTransaction();
- final Span span = tracer.remove();
- if(span != null) {
- span.tag("finished-by", "onRequestHandlerExecuted");
- span.finish();
- }
+
+// final Span span = tracer.remove();
+// if(span != null) {
+// span.tag("finished-by", "onRequestHandlerExecuted");
+// span.finish();
+// }
+
// if(tracerIfAny != null) {
// final Span span = tracerIfAny.currentSpan();
// span.finish();
// }
} catch(Exception ex) {
- final Span span = tracer.remove();
- if(span != null) {
- span.tag("errored-by", "onRequestHandlerExecuted");
- span.error(ex);
- }
-
- final Span nextSpan = tracer.next().name("restart response after fail to commit xactn").start();
+// final Span span = tracer.remove();
+// if(span != null) {
+// span.tag("errored-by", "onRequestHandlerExecuted");
+// span.error(ex);
+// }
+//
+// final Span nextSpan = tracer.next().name("restart response after fail to commit xactn").start();
// if(tracerIfAny != null) {
// final Span span = tracerIfAny.currentSpan();
@@ -241,12 +247,17 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
getIsisSessionFactory().closeSession();
}
}
- final Span span = ThreadLocalSpan.CURRENT_TRACER.remove();
- if(span != null) {
- span.tag("finished-by", "onEndRequest");
- span.finish();
- }
-// final Tracer tracerIfAny = tracerFrom(cycle);
+
+ // final Span span = GlobalTracer.get().activeSpan();
+// span.setTag("finished-by", "onEndRequest").finish();
+
+// final Span span = ThreadLocalSpan.CURRENT_TRACER.remove();
+// if(span != null) {
+// span.tag("finished-by", "onEndRequest");
+// span.finish();
+// }
+
+ // final Tracer tracerIfAny = tracerFrom(cycle);
// if(tracerIfAny != null) {
// final Span span = tracerIfAny.currentSpan();
// span.finish();
@@ -259,11 +270,14 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
LOG.debug("onException");
- final Span span = ThreadLocalSpan.CURRENT_TRACER.remove();
- if(span != null) {
- span.tag("errored-by", "onException");
- span.error(ex);
- }
+// GlobalTracer.get().activeSpan().setTag("errored-by", "onException").setTag("error", Throwables.getStackTraceAsString(ex)).finish();
+
+// final Span span = ThreadLocalSpan.CURRENT_TRACER.remove();
+// if(span != null) {
+// span.tag("errored-by", "onException");
+// span.error(ex);
+// }
+
// final Tracer tracerIfAny = tracerFrom(cycle);
// if(tracerIfAny != null) {
// final Span span = tracerIfAny.currentSpan();
@@ -275,9 +289,14 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
final Set<String> validationErrors = mmie.getValidationErrors();
final MmvErrorPage mmvErrorPage = new MmvErrorPage(validationErrors);
- final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("redirect to error page on MetaModelInvalidException")
- .tag("started-by", "onException")
- .start();
+// GlobalTracer.get().buildSpan("redirect to error page on MetaModelInvalidException")
+// .withTag("started-by", "onException")
+// .start();
+
+// final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("redirect to error page on MetaModelInvalidException")
+// .tag("started-by", "onException")
+// .start();
+
// if(tracerIfAny != null) {
// final Span span = tracerIfAny.currentSpan();
// tracerIfAny.nextSpan().name("redirect to error page on MetaModelInvalidException").start();
@@ -298,9 +317,15 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
addMessage(null);
}
- final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully after ListenerInvocationNotAllowedException")
- .tag("started-by", "onException")
- .start();
+
+// GlobalTracer.get().buildSpan("respond gracefully after ListenerInvocationNotAllowedException")
+// .withTag("started-by", "onException")
+// .start();
+
+// final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully after ListenerInvocationNotAllowedException")
+// .tag("started-by", "onException")
+// .start();
+
// if(tracerIfAny != null) {
// tracerIfAny.nextSpan().name("respond gracefully after ListenerInvocationNotAllowedException").start();
// }
@@ -314,9 +339,14 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
getServicesInjector().lookupServices(ExceptionRecognizer2.class);
String recognizedMessageIfAny = new ExceptionRecognizerComposite(exceptionRecognizers).recognize(ex);
if(recognizedMessageIfAny != null) {
- final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully after recognised exception")
- .tag("started-by", "onException")
- .start();
+// GlobalTracer.get().buildSpan("respond gracefully after recognised exception")
+// .withTag("started-by", "onException")
+// .start();
+
+// final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully after recognised exception")
+// .tag("started-by", "onException")
+// .start();
+
// if(tracerIfAny != null) {
// tracerIfAny.nextSpan().name("respond gracefully after recognised exception").start();
// }
@@ -328,9 +358,15 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
ObjectMember.HiddenException.isInstanceOf()).first();
if(hiddenIfAny.isPresent()) {
addMessage("hidden");
- final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully if hidden")
- .tag("started-by", "onException")
- .start();
+
+// GlobalTracer.get().buildSpan("respond gracefully if hidden")
+// .withTag("started-by", "onException")
+// .start();
+
+// final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully if hidden")
+// .tag("started-by", "onException")
+// .start();
+
// if(tracerIfAny != null) {
// tracerIfAny.nextSpan().name("respond gracefully if hidden").start();
// }
@@ -340,9 +376,15 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
ObjectMember.DisabledException.isInstanceOf()).first();
if(disabledIfAny.isPresent()) {
addTranslatedMessage(disabledIfAny.get().getMessage());
- final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully if disabled")
- .tag("started-by", "onException")
- .start();
+
+// GlobalTracer.get().buildSpan("respond gracefully if disabled")
+// .withTag("started-by", "onException")
+// .start();
+
+// final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("respond gracefully if disabled")
+// .tag("started-by", "onException")
+// .start();
+
// if(tracerIfAny != null) {
// tracerIfAny.nextSpan().name("respond gracefully if disabled").start();
// }
@@ -359,9 +401,14 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
? RedirectPolicy.NEVER_REDIRECT
: RedirectPolicy.ALWAYS_REDIRECT;
- final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("redirect to error page on " + ex.getClass().getSimpleName())
- .tag("started-by", "onException")
- .start();
+// GlobalTracer.get().buildSpan("redirect to error page on " + ex.getClass().getSimpleName())
+// .withTag("started-by", "onException")
+// .start();
+
+// final Span nextSpan = ThreadLocalSpan.CURRENT_TRACER.next().name("redirect to error page on " + ex.getClass().getSimpleName())
+// .tag("started-by", "onException")
+// .start();
+
// if(tracerIfAny != null) {
// tracerIfAny.nextSpan().name("redirect to error page on " + ex.getClass().getSimpleName()).start();
// }
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/ComponentFactoryAbstract.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/ComponentFactoryAbstract.java
index 048ea4f..9e6754a 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/ComponentFactoryAbstract.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/ComponentFactoryAbstract.java
@@ -25,8 +25,6 @@ import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.isis.viewer.wicket.ui.panels.PanelUtil;
-import brave.propagation.CurrentTraceContext;
-import brave.propagation.ThreadLocalCurrentTraceContext;
/**
* Adapter implementation for {@link ComponentFactory}.
@@ -99,17 +97,7 @@ public abstract class ComponentFactoryAbstract implements ComponentFactory {
@Override
public final Component createComponent(final IModel<?> model) {
final String id = getComponentType().toString();
- final CurrentTraceContext ctc = ThreadLocalCurrentTraceContext.Default.inheritable();
- final CurrentTraceContext.Scope scope = ctc.newScope(ctc.get());
-
- //final Span start = ThreadLocalSpan.CURRENT_TRACER.next().tag("createComponent.id", id).start();
- try {
- return createComponent(id, model);
- } finally {
- scope.close();
-// final Span remove = ThreadLocalSpan.CURRENT_TRACER.remove();
-// remove.finish();
- }
+ return createComponent(id, model);
}
@Override
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
index c3e96b8..487505b 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
@@ -57,7 +57,7 @@ import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.
import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.columns.ObjectAdapterToggleboxColumn;
import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
-import brave.propagation.ThreadLocalSpan;
+//import brave.propagation.ThreadLocalSpan;
/**
* {@link PanelAbstract Panel} that represents a {@link EntityCollectionModel
diff --git a/example/application/helloworld/pom.xml b/example/application/helloworld/pom.xml
index 5cb2bb5..c628ba2 100644
--- a/example/application/helloworld/pom.xml
+++ b/example/application/helloworld/pom.xml
@@ -200,43 +200,6 @@
</dependency>
</dependencies>
</profile>
- <profile>
- <id>zipkin</id>
- <activation>
- <property>
- <name>!skip.zipkin</name>
- </property>
- </activation>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>io.zipkin.brave</groupId>
- <artifactId>brave-bom</artifactId>
- <version>5.8.0</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <dependencies>
- <!-- <dependency>
- <groupId>io.zipkin.brave</groupId>
- <artifactId>brave-http</artifactId>
- <version>5.8.0</version>
- </dependency>
- <dependency>
- <groupId>io.zipkin.brave</groupId>
- <artifactId>brave-core</artifactId>
- <version>5.8.0</version>
- </dependency>
- -->
- <dependency>
- <groupId>io.zipkin.brave</groupId>
- <artifactId>brave-instrumentation-servlet</artifactId>
- <version>5.8.0</version>
- </dependency>
- </dependencies>
- </profile>
<profile>
<id>skinny-war</id>
diff --git a/example/application/helloworld/src/main/java/Dummy.java b/example/application/helloworld/src/main/java/Dummy.java
new file mode 100644
index 0000000..1321d90
--- /dev/null
+++ b/example/application/helloworld/src/main/java/Dummy.java
@@ -0,0 +1,152 @@
+import io.jaegertracing.Configuration;
+import io.jaegertracing.internal.samplers.ConstSampler;
+import io.jaegertracing.micrometer.MicrometerMetricsFactory;
+import io.opentracing.Scope;
+import io.opentracing.Span;
+import io.opentracing.SpanContext;
+import io.opentracing.Tracer;
+import io.opentracing.util.GlobalTracer;
+import tracing.ThreadLocalScope2;
+import tracing.ThreadLocalScopeManager2;
+
+public class Dummy {
+
+ public static void main(String[] args) throws InterruptedException {
+
+ GlobalTracer.registerIfAbsent(() -> {
+
+ final Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv()
+ .withType(ConstSampler.TYPE)
+ .withParam(1);
+
+ final Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
+ .withLogSpans(true)
+ .withSender(Configuration.SenderConfiguration.fromEnv());
+
+ final Configuration config = new Configuration("dummy")
+ .withSampler(samplerConfig)
+ .withReporter(reporterConfig);
+
+ final MicrometerMetricsFactory metricsReporter = new MicrometerMetricsFactory();
+
+ return config
+ .getTracerBuilder()
+ .withScopeManager(new ThreadLocalScopeManager2())
+ .withMetricsFactory(metricsReporter)
+ .build();
+ });
+
+ //explicit();
+ decoupled();
+
+ // allow agent to complete...
+ Thread.sleep(1000);
+ }
+
+ private static void decoupled() throws InterruptedException {
+
+ // creates a child (but top-level if no existing parent)
+ // we don't need to hold onto the scope created; we can look it up later (see end of this method)
+ final ThreadLocalScope2 unused =
+ ThreadLocalScopeManager2.get().childSpan("outer-Z");
+
+ Thread.sleep(300);
+
+
+ // for nested scope, option (1) is handle scope and close
+ ThreadLocalScope2 tracingScope = ThreadLocalScopeManager2.get().childSpan("inner-1");
+ try {
+ Thread.sleep(500);
+
+
+ // for nested scope, option (2) is to use a callable or runnable
+ ThreadLocalScopeManager2.get().callInSpanEx("inner-2", () -> {
+ Thread.sleep(500);
+ return null;
+ });
+
+
+ } finally {
+ tracingScope.closeAndFinish();
+ }
+
+ Thread.sleep(200);
+
+ // can look up the existing scope, don't need to pass through
+ final ThreadLocalScope2 scope = ThreadLocalScopeManager2.get().activeScope();
+ if(scope != null) {
+ scope.closeAndFinish();
+ }
+
+ }
+
+ private static void innerSpan() throws InterruptedException {
+ ThreadLocalScope2 tracingScope = ThreadLocalScopeManager2.get().childSpan("inner-1");
+ try {
+ Thread.sleep(500);
+ innerSpan2();
+ } finally {
+ tracingScope.closeAndFinish();
+ }
+ }
+
+ private static void innerSpan2() {
+ ThreadLocalScopeManager2.get().callInSpanEx("inner-2", () -> {
+ Thread.sleep(500);
+ return null;
+ });
+ }
+
+
+
+ private static void explicit() throws InterruptedException {
+ final Tracer tracer = GlobalTracer.get();
+
+ final Tracer.SpanBuilder spanBuilder = tracer.buildSpan("outer-1");
+
+ final Span outer = spanBuilder.start();
+ final Scope outerScope = tracer.activateSpan(outer);
+
+ Thread.sleep(300);
+
+ final Span inner = tracer.buildSpan("inner-1").asChildOf(outer).start();
+ final Scope innerScope = tracer.activateSpan(inner);
+
+ Thread.sleep(500);
+ inner.finish();
+ innerScope.close();
+
+ Thread.sleep(200);
+ outer.finish();
+ outerScope.close();
+ }
+
+ private static void explicitWithLogging() throws InterruptedException {
+ final Tracer tracer = GlobalTracer.get();
+
+ final Tracer.SpanBuilder spanBuilder = tracer.buildSpan("outer-1");
+ final Span outer = spanBuilder.start();
+ final Scope outerScope = tracer.activateSpan(outer);
+
+ Thread.sleep(300);
+
+ final Span span = tracer.activeSpan();
+ final SpanContext context = span.context();
+ final Span inner = tracer.buildSpan("inner-1").asChildOf(outer).start();
+ final Scope innerScope = tracer.activateSpan(inner);
+ Thread.sleep(500);
+ final Span span1 = tracer.scopeManager().activeSpan();
+ inner.finish();
+ innerScope.close();
+ final Span span3 = tracer.activeSpan();
+ final Span spanAfterInnerFinish = tracer.scopeManager().activeSpan();
+
+ final Span span2 = tracer.activeSpan();
+ Thread.sleep(200);
+ outer.finish();
+ final Span span4 = tracer.activeSpan();
+ outerScope.close();
+ final Span span5 = tracer.activeSpan();
+ }
+
+}
diff --git a/example/application/helloworld/src/main/java/domainapp/dom/impl/HelloWorldObjects.java b/example/application/helloworld/src/main/java/domainapp/dom/impl/HelloWorldObjects.java
index 4e5824a..a8b981b 100644
--- a/example/application/helloworld/src/main/java/domainapp/dom/impl/HelloWorldObjects.java
+++ b/example/application/helloworld/src/main/java/domainapp/dom/impl/HelloWorldObjects.java
@@ -34,6 +34,11 @@ import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.services.jdosupport.IsisJdoSupport;
import org.apache.isis.applib.services.repository.RepositoryService;
+import io.opentracing.Scope;
+import io.opentracing.Span;
+import io.opentracing.Tracer;
+import io.opentracing.util.GlobalTracer;
+
@DomainService(
nature = NatureOfService.VIEW_MENU_ONLY,
objectType = "helloworld.HelloWorldObjects"
@@ -66,7 +71,18 @@ public class HelloWorldObjects {
@Action(semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING)
public List<HelloWorldObject> listAll() {
- return repositoryService.allInstances(HelloWorldObject.class);
+ final Tracer tracer = GlobalTracer.get();
+ final Span parentSpan = tracer.activeSpan();
+ final Span childSpan = tracer.buildSpan("listAll").asChildOf(parentSpan).start();
+ final Scope scope = tracer.scopeManager().activate(childSpan);
+ try {
+ return repositoryService.allInstances(HelloWorldObject.class);
+ } finally {
+ childSpan.finish();
+ scope.close();
+ final Span parentSpan2 = tracer.activeSpan();
+ final Span parentSpan21 = parentSpan2;
+ }
}
@javax.inject.Inject
diff --git a/example/application/helloworld/src/main/java/tracing/ThreadLocalScope2.java b/example/application/helloworld/src/main/java/tracing/ThreadLocalScope2.java
new file mode 100644
index 0000000..5072617
--- /dev/null
+++ b/example/application/helloworld/src/main/java/tracing/ThreadLocalScope2.java
@@ -0,0 +1,37 @@
+package tracing;
+
+import io.opentracing.Scope;
+import io.opentracing.Span;
+
+public class ThreadLocalScope2 implements Scope {
+ private final ThreadLocalScopeManager2 scopeManager;
+ private final Span wrapped;
+ private final ThreadLocalScope2 toRestore;
+
+ ThreadLocalScope2(ThreadLocalScopeManager2 scopeManager, Span wrapped) {
+ this.scopeManager = scopeManager;
+ this.wrapped = wrapped;
+ this.toRestore = scopeManager.tlsScope.get();
+ scopeManager.tlsScope.set(this);
+ }
+
+
+ @Override
+ public void close() {
+ if (scopeManager.tlsScope.get() != this) {
+ // This shouldn't happen if users call methods in the expected order. Bail out.
+ return;
+ }
+
+ scopeManager.tlsScope.set(toRestore);
+ }
+
+ public Span span() {
+ return wrapped;
+ }
+
+ public void closeAndFinish() {
+ close();
+ wrapped.finish();
+ }
+}
diff --git a/example/application/helloworld/src/main/java/tracing/ThreadLocalScopeManager2.java b/example/application/helloworld/src/main/java/tracing/ThreadLocalScopeManager2.java
new file mode 100644
index 0000000..2e52f78
--- /dev/null
+++ b/example/application/helloworld/src/main/java/tracing/ThreadLocalScopeManager2.java
@@ -0,0 +1,90 @@
+package tracing;
+
+import java.util.concurrent.Callable;
+
+import com.google.common.base.Throwables;
+
+import io.opentracing.Scope;
+import io.opentracing.ScopeManager;
+import io.opentracing.Span;
+import io.opentracing.Tracer;
+import io.opentracing.util.GlobalTracer;
+
+/**
+ * This allows the closing of the scope to be in a different method to the one that activated it
+ * (though it must of course be in the same thread).
+ */
+public class ThreadLocalScopeManager2 implements ScopeManager {
+
+ final ThreadLocal<ThreadLocalScope2> tlsScope = new ThreadLocal<ThreadLocalScope2>();
+
+ @Override
+ public Scope activate(Span span) {
+ return new ThreadLocalScope2(this, span);
+ }
+
+ @Override
+ public Span activeSpan() {
+ ThreadLocalScope2 scope = activeScope();
+ return scope == null ? null : scope.span();
+ }
+
+ public ThreadLocalScope2 activeScope() {
+ return tlsScope.get();
+ }
+
+ public static ThreadLocalScopeManager2 get() {
+ return (ThreadLocalScopeManager2) GlobalTracer.get().scopeManager();
+ }
+
+ public ThreadLocalScope2 childSpan(final String name) {
+
+ final Span outer = this.activeSpan();
+ final Tracer tracer = GlobalTracer.get();
+ final Span innerSpan = tracer.buildSpan(name).asChildOf(outer).start();
+
+ return (ThreadLocalScope2) tracer.activateSpan(innerSpan);
+ }
+
+ private static ThreadLocalScope2 closeSpanIfAny() {
+
+ final ThreadLocalScopeManager2 scopeManager = (ThreadLocalScopeManager2) GlobalTracer.get().scopeManager();
+ final ThreadLocalScope2 scope = scopeManager.activeScope();
+
+ if(scope != null) {
+ scope.closeAndFinish();
+ }
+
+ return scope;
+ }
+
+ public void runInSpan(final String name, final Runnable runnable) {
+ ThreadLocalScope2 tracingScope = ThreadLocalScopeManager2.get().childSpan(name);
+ try {
+ runnable.run();
+ } finally {
+ tracingScope.closeAndFinish();
+ }
+ }
+
+ public <T> T callInSpan(final String name, final Callable<T> callable) throws Exception {
+ ThreadLocalScope2 tracingScope = ThreadLocalScopeManager2.get().childSpan(name);
+ try {
+ return callable.call();
+ } finally {
+ tracingScope.closeAndFinish();
+ }
+ }
+
+ public <T> T callInSpanEx(final String name, final Callable<T> callable) {
+ ThreadLocalScope2 tracingScope = ThreadLocalScopeManager2.get().childSpan(name);
+ try {
+ return callable.call();
+ } catch (Exception e) {
+ tracingScope.span().setTag("exception", Throwables.getStackTraceAsString(e));
+ return null;
+ } finally {
+ tracingScope.closeAndFinish();
+ }
+ }
+}
diff --git a/example/application/helloworld/src/main/webapp/WEB-INF/logging.properties b/example/application/helloworld/src/main/webapp/WEB-INF/logging.properties
index 1b3dfc2..3aba91d 100644
--- a/example/application/helloworld/src/main/webapp/WEB-INF/logging.properties
+++ b/example/application/helloworld/src/main/webapp/WEB-INF/logging.properties
@@ -244,5 +244,5 @@ log4j.logger.org.apache.wicket.page.XmlPartialPageUpdate=ERROR,Console
log4j.additivity.org.apache.wicket.page.XmlPartialPageUpdate=false
-log4j.logger.org.apache.isis.viewer.wicket.viewer.integration.wicket.WebRequestCycleForIsis=DEBUG,Console
-log4j.additivity.org.apache.isis.viewer.wicket.viewer.integration.wicket.WebRequestCycleForIsis=false
+#log4j.logger.org.apache.isis.viewer.wicket.viewer.integration.wicket.WebRequestCycleForIsis=DEBUG,Console
+#log4j.additivity.org.apache.isis.viewer.wicket.viewer.integration.wicket.WebRequestCycleForIsis=false
diff --git a/example/application/helloworld/src/main/webapp/WEB-INF/web.xml b/example/application/helloworld/src/main/webapp/WEB-INF/web.xml
index 6496ba3..f012b11 100644
--- a/example/application/helloworld/src/main/webapp/WEB-INF/web.xml
+++ b/example/application/helloworld/src/main/webapp/WEB-INF/web.xml
@@ -32,24 +32,25 @@
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
+ <listener>
+ <listener-class>org.apache.isis.core.webapp.OpenTracingBootstrapper</listener-class>
+ </listener>
+
<filter>
- <filter-name>TracingZipkinFilter</filter-name>
- <filter-class>org.apache.isis.core.webapp.TracingZipkinFilter</filter-class>
- <init-param>
- <param-name>tracingEndpoint</param-name>
- <param-value>http://localhost:9411/api/v2/spans</param-value>
- </init-param>
- <init-param>
- <param-name>tracingLocalServiceName</param-name>
- <param-value>helloworld-app</param-value>
- </init-param>
+ <filter-name>OpenTracingFilter</filter-name>
+ <filter-class>io.opentracing.contrib.web.servlet.filter.TracingFilter</filter-class>
</filter>
<filter-mapping>
- <filter-name>TracingZipkinFilter</filter-name>
+ <filter-name>OpenTracingFilter</filter-name>
<url-pattern>/wicket/*</url-pattern>
</filter-mapping>
+ <context-param>
+ <param-name>openTracingServiceName</param-name>
+ <param-value>hello-world</param-value>
+ </context-param>
+
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>