Skip to content
Closed
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.
* Fix discussions #9113, log4j2 grpc report missing traceId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need some update on the docs https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/application-toolkit-log4j-2.x/

Please update application-toolkit-log4j-2.x.md accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fix discussions #9113, log4j2 grpc report missing traceId
* Support `-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector` in gRPC log report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice #9113 is actually not working, because this is not in the same repository.

Copy link
Contributor Author

@andotorg andotorg May 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to recreate an issues?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean the link.#issue/discussion number is only working as a link when PR and issue are in the same repo. And we don't put this in the change log. The changelog is related to a commit/PR already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


#### 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,23 @@ 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();
// fix -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector not traceId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems not current. You should explain about AsyncLoggerContextSelector is working on async mode, so it has to use SkyWalkingContext.

Comments for fix xxx actually is pointless, because git log already includes this information.

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