Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Release Notes.
* Enhance Apache ShenYu (incubating) plugin: support trace `grpc`,`sofarpc`,`motan`,`tars` rpc proxy.
* Add primary endpoint name to log events.
* Fix Span not finished in gateway plugin when the gateway request timeout.
* Support `-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector` in gRPC log report.

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Optional;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.async.RingBufferLogEvent;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
Expand All @@ -37,6 +38,7 @@
import org.apache.skywalking.apm.network.logging.v3.LogTags;
import org.apache.skywalking.apm.network.logging.v3.TextLog;
import org.apache.skywalking.apm.network.logging.v3.TraceContext;
import org.apache.skywalking.apm.toolkit.logging.common.log.SkyWalkingContext;
import org.apache.skywalking.apm.toolkit.logging.common.log.ToolkitConfig;

public class GRPCLogAppenderInterceptor implements InstanceMethodsAroundInterceptor {
Expand Down Expand Up @@ -114,12 +116,22 @@ private LogData transform(final AbstractAppender appender, LogEvent event) {
builder.setEndpoint(primaryEndpointName);
}

return -1 == ContextManager.getSpanId() ? builder.build()
: builder.setTraceContext(TraceContext.newBuilder()
.setTraceId(ContextManager.getGlobalTraceId())
.setSpanId(ContextManager.getSpanId())
.setTraceSegmentId(ContextManager.getSegmentId())
.build()).build();
if (event instanceof RingBufferLogEvent) {
EnhancedInstance instance = (EnhancedInstance) event;
SkyWalkingContext context = (SkyWalkingContext) instance.getSkyWalkingDynamicField();
return builder.setTraceContext(TraceContext.newBuilder()
.setTraceId(context.getTraceId())
.setSpanId(context.getSpanId())
.setTraceSegmentId(context.getTraceSegmentId())
.build()).build();
} else {
return -1 == ContextManager.getSpanId() ? builder.build()
: builder.setTraceContext(TraceContext.newBuilder()
.setTraceId(ContextManager.getGlobalTraceId())
.setSpanId(ContextManager.getSpanId())
.setTraceSegmentId(ContextManager.getSegmentId())
.build()).build();
}
}

private String transformLogText(final AbstractAppender appender, final LogEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public String getTraceId() {
return traceId;
}

public String getTraceSegmentId() {
return traceSegmentId;
}

public int getSpanId() {
return spanId;
}

@Override
public String toString() {
if (-1 == spanId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The gRPC report could forward the collected logs to SkyWalking OAP server, or [S
log.max_message_size=${SW_GRPC_LOG_MAX_MESSAGE_SIZE:10485760}
```

* Support `-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector` in gRPC log report.

## Transmitting un-formatted messages

Expand Down