StringTagReader.java 872 字节
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 StringTagReader {
    public static String get(Span span, StringTag tag) {
        List<StringTagItem> tagsWithStrList = null;
        try {
            Field tagsWithStr = Span.class.getDeclaredField("tagsWithStr");
            tagsWithStr.setAccessible(true);
            tagsWithStrList = (List<StringTagItem>)tagsWithStr.get(span);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        for (StringTagItem item : tagsWithStrList) {
            if (tag.key().equals(item.getKey())) {
                return item.getValue();
            }
        }
        return null;
    }

}