use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class SessionAndTraceRegistrationPayloadFilter method doFilter.
/**
* Register thread-local session and trace information, executes the given {@link FilterChain}
* and unregisters the session/trace information. If configured, the execution of this filter is
* also logged to the {@link IMonitoringController}. This method returns immediately if
* monitoring is not enabled.
*
* @param request
* The request.
* @param response
* The response.
* @param chain
* The filter chain to be used.
*
* @throws IOException
* on io errors
* @throws ServletException
* on servlet errors
*/
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
if (SessionAndTraceRegistrationPayloadFilter.CTRLINST.isMonitoringEnabled()) {
// if (CTRLINST.isProbeActivated(this.filterOperationSignatureString)) {
final String method;
final String path;
final String sessionId;
if (request instanceof HttpServletRequest) {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
method = httpRequest.getMethod();
final String requestPath = httpRequest.getRequestURI();
// TODO is this a generic thing?
/**
* remove sessionId from request path.
*/
path = requestPath.contains(";") ? requestPath.substring(0, requestPath.indexOf(";")) : requestPath;
sessionId = httpRequest.getSession().getId();
final String operationSignature = path;
final List<String> parameters = new ArrayList<>();
final List<String> parameterValues = new ArrayList<>();
final Enumeration<String> names = httpRequest.getParameterNames();
while (names.hasMoreElements()) {
final String name = names.nextElement();
final String[] values = httpRequest.getParameterValues(name);
for (final String value : values) {
parameters.add(name);
parameterValues.add(value);
}
}
final String componentSignature = request.getServletContext().getContextPath();
TraceMetadata trace = SessionAndTraceRegistrationPayloadFilter.TRACEREGISTRY.getTrace();
final boolean newTrace = trace == null;
if (newTrace) {
SessionRegistry.INSTANCE.storeThreadLocalSessionId(sessionId);
trace = SessionAndTraceRegistrationPayloadFilter.TRACEREGISTRY.registerTrace();
SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(trace);
}
final long traceId = trace.getTraceId();
if ("GET".equals(method)) {
this.logMonitoringAndHandleFilterChain(chain, httpRequest, response, traceId, trace.getNextOrderId(), operationSignature, componentSignature, parameters.toArray(new String[parameters.size()]), parameterValues.toArray(new String[parameterValues.size()]), 1, newTrace);
} else if ("POST".equals(method)) {
this.logMonitoringAndHandleFilterChain(chain, httpRequest, response, traceId, trace.getNextOrderId(), operationSignature, componentSignature, parameters.toArray(new String[parameters.size()]), parameterValues.toArray(new String[parameterValues.size()]), 1, newTrace);
} else {
chain.doFilter(request, response);
return;
}
} else {
/**
* not a http request.
*/
chain.doFilter(request, response);
}
} else {
chain.doFilter(request, response);
}
}
use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class TestSend method main.
/**
* Execute send test.
*
* @param args
* arguments are ignored.
*/
public static void main(final String[] args) {
TestSend.LOGGER.debug("Sender");
final Configuration configuration = ConfigurationFactory.createDefaultConfiguration();
configuration.setProperty(ConfigurationKeys.CONTROLLER_NAME, "Kieker-Test");
configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, TestSend.WRITER_NAME);
configuration.setProperty(SingleSocketTcpWriter.CONFIG_HOSTNAME, "localhost");
configuration.setProperty(SingleSocketTcpWriter.CONFIG_PORT, "9876");
configuration.setProperty(SingleSocketTcpWriter.CONFIG_BUFFERSIZE, "1024");
configuration.setProperty(SingleSocketTcpWriter.CONFIG_FLUSH, "true");
// add ignored values
configuration.setProperty(ConfigurationKeys.PREFIX + "test", "true");
configuration.setProperty(TestSend.WRITER_NAME + ".test", "true");
TestSend.LOGGER.debug("Configuration complete");
final IMonitoringController ctrl = MonitoringController.createInstance(configuration);
TestSend.LOGGER.debug("Controller active");
TestSend.LOGGER.debug("Send first record");
IMonitoringRecord record = new TraceMetadata(1, 2, "demo", "hostname", 0, 0);
ctrl.newMonitoringRecord(record);
TestSend.LOGGER.debug("Send second record");
record = new BeforeOperationEvent(0, 1, 0, "Send", "main");
ctrl.newMonitoringRecord(record);
TestSend.LOGGER.debug("Done");
}
Aggregations