-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #30: Bump OpenTracing to 0.33.0 * Fixed issue where scope is not closed correctly * Reverted changes not related to issue and revert incorrect formating * Updated test as precondition for method is not true, message cannot be null according to javadoc * Factorize closing of scope * Removed changes not related to ticket
- Loading branch information
1 parent
b112cf7
commit e57ad16
Showing
6 changed files
with
56 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Copyright 2017-2018 The OpenTracing Authors | ||
* Copyright 2017-2019 The OpenTracing Authors | ||
* | ||
* Licensed 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 | ||
|
@@ -13,6 +13,8 @@ | |
*/ | ||
package io.opentracing.contrib.spring.integration.messaging; | ||
|
||
import static io.opentracing.contrib.spring.integration.messaging.Headers.SCOPE_HEADER; | ||
|
||
import io.opentracing.References; | ||
import io.opentracing.Scope; | ||
import io.opentracing.Span; | ||
|
@@ -28,14 +30,13 @@ | |
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.MessageChannel; | ||
import org.springframework.messaging.MessageHandler; | ||
import org.springframework.messaging.support.ChannelInterceptorAdapter; | ||
import org.springframework.messaging.support.ExecutorChannelInterceptor; | ||
import org.springframework.util.ClassUtils; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Gytis Trikleris</a> | ||
*/ | ||
public class OpenTracingChannelInterceptor extends ChannelInterceptorAdapter implements ExecutorChannelInterceptor { | ||
public class OpenTracingChannelInterceptor implements ExecutorChannelInterceptor { | ||
private static final Log log = LogFactory.getLog(OpenTracingChannelInterceptor.class); | ||
|
||
static final String COMPONENT_NAME = "spring-messaging"; | ||
|
@@ -66,8 +67,9 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) { | |
spanBuilder.asChildOf(extractedContext); | ||
} | ||
|
||
Span span = spanBuilder.startActive(true).span(); | ||
|
||
Span span = spanBuilder.start(); | ||
Scope scope = tracer.activateSpan(span); | ||
carrier.addHeader(SCOPE_HEADER, scope); | ||
if (isConsumer) { | ||
log.trace("Adding 'messageConsumed' header"); | ||
carrier.put(Headers.MESSAGE_CONSUMED, "true"); | ||
|
@@ -76,23 +78,27 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) { | |
log.trace("Adding 'messageSent' header"); | ||
carrier.put(Headers.MESSAGE_SENT_FROM_CLIENT, "true"); | ||
} | ||
log.trace(String.format("Pre-send: starting a new span %s , carrier extracted context %s", span, extractedContext)); | ||
|
||
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, carrier); | ||
return carrier.getMessage(); | ||
} | ||
|
||
@Override | ||
public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, Exception ex) { | ||
Scope scope = tracer.scopeManager().active(); | ||
if (scope == null) { | ||
return; | ||
Object scopeValue = message.getHeaders().get(SCOPE_HEADER); | ||
if (scopeValue instanceof Scope) { | ||
Span span = tracer.scopeManager().activeSpan(); | ||
closeResources(ex, (Scope) scopeValue, span); | ||
} | ||
} | ||
|
||
log.trace(String.format("Completed sending and current span is %s", scope.span())); | ||
handleException(ex, scope.span()); | ||
log.trace("Closing messaging span scope " + scope); | ||
scope.close(); | ||
log.trace(String.format("Messaging span scope %s successfully closed", scope)); | ||
private void closeResources(Exception ex, Scope scopeValue, Span span) { | ||
handleException(ex, span); | ||
span.finish(); | ||
log.trace(String.format("Completed sending of current span %s", span)); | ||
scopeValue.close(); | ||
log.trace(String.format("Scope %s successfully closed", scopeValue)); | ||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters