Add log endpoint name (#171)
This commit is contained in:
parent
bd7912106a
commit
4b24b7d795
|
|
@ -15,6 +15,7 @@ Release Notes.
|
|||
* Fix NPE in elasticsearch plugin.
|
||||
* Grpc plugin support trace client async generic call(without grpc stubs), support Method type: `UNARY`、`SERVER_STREAMING`.
|
||||
* Enhance Apache ShenYu (incubating) plugin: support trace `grpc`,`sofarpc`,`motan`,`tars` rpc proxy.
|
||||
* Add primary endpoint name to log events.
|
||||
|
||||
#### Documentation
|
||||
|
||||
|
|
|
|||
|
|
@ -133,4 +133,9 @@ public interface AbstractTracerContext {
|
|||
* Get current correlation context
|
||||
*/
|
||||
CorrelationContext getCorrelationContext();
|
||||
|
||||
/**
|
||||
* Get current primary endpoint name
|
||||
*/
|
||||
String getPrimaryEndpointName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,14 @@ public class ContextManager implements BootService {
|
|||
return Objects.nonNull(context) ? context.getSpanId() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current primary endpoint name. Otherwise, the value is null.
|
||||
*/
|
||||
public static String getPrimaryEndpointName() {
|
||||
AbstractTracerContext context = CONTEXT.get();
|
||||
return Objects.nonNull(context) ? context.getPrimaryEndpointName() : null;
|
||||
}
|
||||
|
||||
public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier) {
|
||||
AbstractSpan span;
|
||||
AbstractTracerContext context;
|
||||
|
|
|
|||
|
|
@ -126,6 +126,11 @@ public class IgnoredTracerContext implements AbstractTracerContext {
|
|||
return this.correlationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryEndpointName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class ListenerManager {
|
||||
private static List<IgnoreTracerContextListener> LISTENERS = new LinkedList<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -410,6 +410,11 @@ public class TracingContext implements AbstractTracerContext {
|
|||
return this.correlationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryEndpointName() {
|
||||
return primaryEndpoint.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-check current trace need profiling, encase third part plugin change the operation name.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -96,6 +96,12 @@ public class GRPCLogAppenderInterceptor implements InstanceMethodsAroundIntercep
|
|||
.build())
|
||||
.setBody(LogDataBody.newBuilder().setType(LogDataBody.ContentCase.TEXT.name())
|
||||
.setText(TextLog.newBuilder().setText(transformLogText(appender, event)).build()).build());
|
||||
|
||||
String primaryEndpointName = ContextManager.getPrimaryEndpointName();
|
||||
if (primaryEndpointName != null) {
|
||||
builder.setEndpoint(primaryEndpointName);
|
||||
}
|
||||
|
||||
return -1 == ContextManager.getSpanId() ? builder.build()
|
||||
: builder.setTraceContext(TraceContext.newBuilder()
|
||||
.setTraceId(ContextManager.getGlobalTraceId())
|
||||
|
|
|
|||
|
|
@ -108,6 +108,12 @@ public class GRPCLogAppenderInterceptor implements InstanceMethodsAroundIntercep
|
|||
.setTags(logTags.build())
|
||||
.setBody(LogDataBody.newBuilder().setType(LogDataBody.ContentCase.TEXT.name())
|
||||
.setText(TextLog.newBuilder().setText(transformLogText(appender, event)).build()).build());
|
||||
|
||||
String primaryEndpointName = ContextManager.getPrimaryEndpointName();
|
||||
if (primaryEndpointName != null) {
|
||||
builder.setEndpoint(primaryEndpointName);
|
||||
}
|
||||
|
||||
return -1 == ContextManager.getSpanId() ? builder.build()
|
||||
: builder.setTraceContext(TraceContext.newBuilder()
|
||||
.setTraceId(ContextManager.getGlobalTraceId())
|
||||
|
|
|
|||
|
|
@ -112,6 +112,12 @@ public class GRPCLogAppenderInterceptor implements InstanceMethodsAroundIntercep
|
|||
.setTags(logTags.build())
|
||||
.setBody(LogDataBody.newBuilder().setType(LogDataBody.ContentCase.TEXT.name())
|
||||
.setText(TextLog.newBuilder().setText(transformLogText(appender, event)).build()).build());
|
||||
|
||||
String primaryEndpointName = ContextManager.getPrimaryEndpointName();
|
||||
if (primaryEndpointName != null) {
|
||||
builder.setEndpoint(primaryEndpointName);
|
||||
}
|
||||
|
||||
return -1 == ContextManager.getSpanId() ? builder.build()
|
||||
: builder.setTraceContext(TraceContext.newBuilder()
|
||||
.setTraceId(ContextManager.getGlobalTraceId())
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ logs:
|
|||
serviceid: {{ b64enc "e2e-service-provider" }}.1
|
||||
serviceinstancename: provider1
|
||||
serviceinstanceid: {{ b64enc "e2e-service-provider" }}.1_{{ b64enc "provider1" }}
|
||||
endpointname: null
|
||||
endpointid: null
|
||||
endpointname: POST:/info
|
||||
endpointid: {{ b64enc "e2e-service-provider" }}.1_{{ b64enc "POST:/info" }}
|
||||
traceid: {{ notEmpty .traceid }}
|
||||
timestamp: {{ gt .timestamp 0 }}
|
||||
contenttype: TEXT
|
||||
|
|
@ -36,4 +36,4 @@ logs:
|
|||
value: {{ notEmpty .value }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
total: {{ gt .total 0 }}
|
||||
total: {{ gt .total 0 }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue