-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bugfix/675-replaceSpecialCharacters
- Loading branch information
Showing
10 changed files
with
398 additions
and
14 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
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
93 changes: 93 additions & 0 deletions
93
.../rocks/inspectit/ocelot/core/instrumentation/hook/tags/CommonTagsToAttributesManager.java
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package rocks.inspectit.ocelot.core.instrumentation.hook.tags; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import io.opencensus.trace.AttributeValue; | ||
import io.opencensus.trace.Span; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import rocks.inspectit.ocelot.config.model.InspectitConfig; | ||
import rocks.inspectit.ocelot.config.model.tracing.TracingSettings; | ||
import rocks.inspectit.ocelot.core.config.InspectitConfigChangedEvent; | ||
import rocks.inspectit.ocelot.core.config.InspectitEnvironment; | ||
import rocks.inspectit.ocelot.core.tags.CommonTagsManager; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.Objects; | ||
|
||
/** | ||
* This class is used when creating spans to determine if the common tags should be added to the created span or not. | ||
*/ | ||
@Component | ||
public class CommonTagsToAttributesManager { | ||
|
||
/** | ||
* Environment. | ||
*/ | ||
private final InspectitEnvironment env; | ||
|
||
/** | ||
* Common tags manager. | ||
*/ | ||
private final CommonTagsManager commonTagsManager; | ||
|
||
/** | ||
* Currently active setting. | ||
*/ | ||
private TracingSettings.AddCommonTags addCommonTags; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
@Autowired | ||
public CommonTagsToAttributesManager(InspectitEnvironment env, CommonTagsManager commonTagsManager) { | ||
this.env = env; | ||
this.commonTagsManager = commonTagsManager; | ||
this.addCommonTags = TracingSettings.AddCommonTags.NEVER; | ||
} | ||
|
||
/** | ||
* Creates the new #action based on the current config. | ||
*/ | ||
@EventListener(InspectitConfigChangedEvent.class) | ||
@PostConstruct | ||
@VisibleForTesting | ||
void update() { | ||
InspectitConfig configuration = env.getCurrentConfig(); | ||
TracingSettings tracing = configuration.getTracing(); | ||
if (!Objects.equals(tracing.getAddCommonTags(), addCommonTags)) { | ||
this.addCommonTags = tracing.getAddCommonTags(); | ||
} | ||
} | ||
|
||
/** | ||
* Writes common tags to span depending on the current {@link #addCommonTags} setting and the provided information about the span. | ||
* | ||
* @param span Span | ||
* @param hasRemoteParent If span has remote parent | ||
* @param hasLocalParent If span has local parent | ||
*/ | ||
public void writeCommonTags(Span span, boolean hasRemoteParent, boolean hasLocalParent) { | ||
if (shouldAdd(hasRemoteParent, hasLocalParent)) { | ||
commonTagsManager.getCommonTagValueMap() | ||
.forEach((k, v) -> span.putAttribute(k, AttributeValue.stringAttributeValue(v))); | ||
} | ||
} | ||
|
||
/** | ||
* If tags should be added. | ||
*/ | ||
private boolean shouldAdd(boolean hasRemoteParent, boolean hasLocalParent) { | ||
switch (addCommonTags) { | ||
case ALWAYS: | ||
return true; | ||
case ON_LOCAL_ROOT: | ||
return !hasLocalParent; | ||
case ON_GLOBAL_ROOT: | ||
return !hasRemoteParent && !hasLocalParent; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.