Skip to content
Snippets Groups Projects
Commit de9c8fe9 authored by Alexandre TISON's avatar Alexandre TISON
Browse files

Added OpenTelemetry traces for any GetValue

parent 86ac9dd1
No related branches found
No related tags found
1 merge request!2JTango10: DevInfo & Telemetry upgrade
package fr.soleil.tango.parser;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -266,10 +262,11 @@ public abstract class AJepParser {
}
try {
TangoContext ctx = openTelemetry.handleServer();
TangoSpan span = ctx.buildSpan("getValue (Eq)", sourceName, expressions); // static Method ?
TangoSpan span = ctx.buildSpan("getValue", sourceName, variables.values().toArray(new String[0])); // static Method ?
try (TangoScope scope = span.makeCurrent()) {
// get results for tango attributes
for (final String variableName : variables.values()) {
span.startProcessing(variableName);
if(!tangoVariable.containsKey(variableName)) {
final AttributeResult r = dataSource.getResult(sourceName, variableName);
if (r != null) {
......@@ -287,6 +284,7 @@ public abstract class AJepParser {
final Object value = tangoVariable.get(variableName);
jep.addVariable(variableName, fromStandardToJepType(value));
}
span.endProcessing(variableName);
}
// get results for variables
......
......@@ -7,10 +7,12 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import fr.esrf.TangoApi.telemetry.*;
import org.lsmp.djep.vectorJep.values.MVector;
import org.lsmp.djep.vectorJep.values.Matrix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tango.server.ServerManager;
import org.tango.utils.DevFailedUtils;
import fr.esrf.Tango.AttrDataFormat;
......@@ -35,17 +37,34 @@ public class TangoSource {
private final AttributeResults attributeData = new AttributeResults();
private final Map<String, TangoGroupAttribute> writeGroups = new TreeMap<String, TangoGroupAttribute>();
private final boolean isSynchronous;
private final OpenTelemetry openTelemetry;
TangoSource(final String deviceName, final String name, final boolean isSynchronous) {
this.deviceName = deviceName.toLowerCase(Locale.ENGLISH);
this.name = name.toLowerCase(Locale.ENGLISH);
this.isSynchronous = isSynchronous;
this.openTelemetry = new OpenTelemetry(this.deviceName);
this.openTelemetry.setTangoDeviceName(this.deviceName);
this.openTelemetry.setTangoProcessId(ServerManager.getInstance().getPid());
this.openTelemetry.setTangoHostName(ServerManager.getInstance().getHostName());
this.openTelemetry.setTangoServerName(ServerManager.getInstance().getServerName());
this.openTelemetry.setTangoProcessKind(EProcessKind.SERVER);
this.openTelemetry.init();
}
TangoSource() {
this.deviceName = "";
this.name = "";
this.isSynchronous = false;
this.openTelemetry = new OpenTelemetry(deviceName);
this.openTelemetry.setTangoDeviceName(deviceName);
this.openTelemetry.setTangoProcessId(ServerManager.getInstance().getPid());
this.openTelemetry.setTangoHostName(ServerManager.getInstance().getHostName());
this.openTelemetry.setTangoServerName(ServerManager.getInstance().getServerName());
this.openTelemetry.setTangoProcessKind(EProcessKind.SERVER);
this.openTelemetry.init();
}
/**
......@@ -83,10 +102,21 @@ public class TangoSource {
public synchronized void refresh() throws DevFailed {
logger.debug("read attributes for {}", attributeData);
TangoContext ctx = openTelemetry.handleServer();
TangoSpan span = ctx.buildSpan("refresh", deviceName, ""); // static Method ?
try (TangoScope scope = span.makeCurrent()) {
span.startProcessing("");
if (!isEmpty()) {
readGroup.readAync();
getResults();
}
span.endProcessing("");
} catch (Exception e) {
span.recordException(e);
}
finally {
span.end();
}
}
public AttributeResult getResult(final String sourceName, final String variableName) {
......@@ -98,7 +128,11 @@ public class TangoSource {
final DeviceAttribute[] results = readGroup.getReadAsyncReplies();
// final Iterator<AttributeResult> it = attributeData.values().iterator();
final String[] attributeNames = attributeData.getAllAttributes();
TangoContext ctx = openTelemetry.handleServer();
TangoSpan span = ctx.buildSpan("getResults", deviceName, attributeNames); // static Method ?
try (TangoScope scope = span.makeCurrent()) {
for (int i = 0; i < results.length; i++) {
span.startProcessing(attributeNames[i]);
// final AttributeResult result = it.next();
final String attributeName = attributeNames[i];
// final String attributeName = result.getName();
......@@ -158,6 +192,13 @@ public class TangoSource {
attributeData.setAttributeResultError(attributeName,
DevFailedUtils.newDevFailed("Device down for " + attributeName));
}
span.endProcessing(attributeNames[i]);
}
} catch (final Exception e) {
span.recordException(e);
throw DevFailedUtils.newDevFailed(e);
} finally {
span.end();
}
}
......
......@@ -5,10 +5,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fr.esrf.TangoApi.telemetry.*;
import org.apache.commons.lang3.ArrayUtils;
import org.nfunk.jep.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tango.server.ServerManager;
import org.tango.server.StateMachineBehavior;
import org.tango.server.attribute.AttributeConfiguration;
import org.tango.server.attribute.AttributePropertiesImpl;
......@@ -48,6 +50,8 @@ public final class DynamicAttributeParser implements IWriteLockAttributeBehaviou
private boolean writingLock = false;
private Object writeValue;
private final OpenTelemetry openTelemetry;
public DynamicAttributeParser(final String deviceName, final AttributeConfiguration config,
final String expressionsR, final List<String> expressionsW, final BiMap<String, String> variables,
Map<String, ParserConstant> constants, List<TangoParserCustomFunction> functions,
......@@ -69,6 +73,14 @@ public final class DynamicAttributeParser implements IWriteLockAttributeBehaviou
this.config = config;
final AttributePropertiesImpl attributeProperties = new AttributePropertiesImpl();
this.openTelemetry = new OpenTelemetry(deviceName);
this.openTelemetry.setTangoDeviceName(deviceName);
this.openTelemetry.setTangoProcessId(ServerManager.getInstance().getPid());
this.openTelemetry.setTangoHostName(ServerManager.getInstance().getHostName());
this.openTelemetry.setTangoServerName(ServerManager.getInstance().getServerName());
this.openTelemetry.setTangoProcessKind(EProcessKind.SERVER);
this.openTelemetry.init();
// config.setMemorized(true);
this.isSynchronous = sourceGroup.isSynchronous();
final AttrWriteType attrWryteType = config.getWritable();
......@@ -154,10 +166,22 @@ public final class DynamicAttributeParser implements IWriteLockAttributeBehaviou
@Override
public AttributeValue getValue() throws DevFailed {
TangoContext ctx = openTelemetry.handleServer();
TangoSpan span = ctx.buildSpan("getValue", dataSource.getDeviceName(), getConfiguration().getName()); // static Method ?
try (TangoScope scope = span.makeCurrent()) {
span.startProcessing(getConfiguration().getName());
if (isSynchronous) {
launchRefresh(true);
}
refreshValue(true);
span.endProcessing(getConfiguration().getName());
}
catch (final Exception e) {
span.recordException(e);
}
finally {
span.end();
}
return value;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment