BooleanTagReader.java 899 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package org.skywalking.apm.trace.tag;

import java.lang.reflect.Field;
import java.util.List;
import org.skywalking.apm.trace.Span;

/**
 * @author wusheng
 */
public class BooleanTagReader {
    public static Boolean get(Span span, BooleanTag tag) {
        List<BooleanTagItem> tagsWithBoolList = null;
        try {
            Field tagsWithBool = Span.class.getDeclaredField("tagsWithBool");
            tagsWithBool.setAccessible(true);
            tagsWithBoolList = (List<BooleanTagItem>)tagsWithBool.get(span);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        for (BooleanTagItem item : tagsWithBoolList) {
            if (tag.key().equals(item.getKey())) {
                return item.getValue();
            }
        }
        return tag.defaultValue();
    }

}