com.aliyuncs.v5.utils.TraceUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aliyun-java-sdk-core-v5 Show documentation
Show all versions of aliyun-java-sdk-core-v5 Show documentation
Aliyun Open API SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
The newest version!
package com.aliyuncs.v5.utils;
import io.opentracing.Span;
import io.opentracing.tag.Tags;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
public class TraceUtils {
public static void onError(Throwable throwable, Span span) {
Tags.ERROR.set(span, Boolean.TRUE);
if (throwable != null) {
span.log(errorLogs(throwable));
}
}
private static Map errorLogs(Throwable throwable) {
Map errorLogs = new HashMap(10);
errorLogs.put("event", Tags.ERROR.getKey());
errorLogs.put("error.object", throwable);
errorLogs.put("error.kind", throwable.getClass().getName());
String message = throwable.getCause() != null ? throwable.getCause().getMessage() : throwable.getMessage();
if (message != null) {
errorLogs.put("message", message);
}
StringWriter sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw));
errorLogs.put("stack", sw.toString());
return errorLogs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy