You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/05/18 13:21:23 UTC

[GitHub] [skywalking] yaojingguo opened a new issue #6970: Make %traceId configurable for application toolkit for logging

yaojingguo opened a new issue #6970:
URL: https://github.com/apache/skywalking/issues/6970


   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [ ] Question or discussion
   - [ ] Bug
   - [X] Requirement
   - [ ] Feature or performance improvement
   
   ___
   ### Requirement or improvement
   For [Application-toolkit-log4j-2.x][1], [Application-toolkit-log4j-1.x][2] and [Application-toolkit-logback-1.x][3], `%traceId` means  `TID: real_trace_id`. For example, a `%traceId` placeholdder is replaced with `TID: df16a9001ca34cafbe23cbc5751c0d66.96.16206346254060001` in [log4j-2.x][1]. It is hard to extract `df16a9001ca34cafbe23cbc5751c0d66.96.16206346254060001` from `TID: df16a9001ca34cafbe23cbc5751c0d66.96.16206346254060001` when such log  messages are injected into ELK or Aliyun SLS.  But if `%traceId` means `real_trace_id`, the extraction is trival. And if we want something like `TID: real_trace_id`, we can write `TID: %traceId` in log4j-2.x's PatternLayout.
   
   Is it possible to make `%traceId` pattern configurable?
   
   [1]: https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/Application-toolkit-log4j-2.x.md
   [2]: https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/Application-toolkit-log4j-1.x.md
   [3]: https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/Application-toolkit-logback-1.x.md
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-843247070


   What do you mean hard to extract? We could easily do by using LAL by SkyWalking OAP.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-843247624


   And we recommend injecting trace context rather than trace id already in the 8.6.0-dev.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-843286324


   Notice, once you have entered the commercial product/service field, you are on your own, or we should say, it is AliCloud's responsibility, rather than the community's.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] yaojingguo commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
yaojingguo commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-843276767


   > What do you mean hard to extract? We could easily do by using LAL by SkyWalking OAP.
   
   For example, we use `%d{ISO8601}|%-5p|[%t]|%traceId|%c{2}|%m%n` log4j2 pattern. When log messages are loaded into Aliyun SLS,  `|` is used to split the log message. After the split, we get `TID: real_trace_id`.  We don't want the prefix `TID: `. We just want `real_trace_id`.
   
   > And we recommend injecting trace context rather than trace id already in the 8.6.0-dev.
   
   Where can I find the related information? I have just skimmed the source code. But I don't find it.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng closed issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
wu-sheng closed issue #6970:
URL: https://github.com/apache/skywalking/issues/6970


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-843271545


   Read this if you want to know how SkyWalking does log collection. https://github.com/apache/skywalking/pull/6952


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] yaojingguo commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
yaojingguo commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-913392697


   I have another use case with Skywalking trace ID which has nothing to do with AliCloud's products. I want to format Log4j2 logs as JSON with the pattern layout. In order to make the log message a valid JSON, I need to double-quote `%traceId` in the following way:
   
   ```
   {
     "TID" : "%traceId"
   }
   ```
   
   An example log message is:
   ```
   {
     "TID" : "TID: df16a9001ca34cafbe23cbc5751c0d66.96.16206346254060001"
   }
   ```
   
   But what I really want is:
   ```
   {
     "TID" : "df16a9001ca34cafbe23cbc5751c0d66.96.16206346254060001"
   }
   ```
   
   For now, I need to use the following `TraceIdConverter` wrapper to remove the prefix:
   ```java
   @Plugin(name = "TraceIdConverter", category = "Converter")
   @ConverterKeys({"sw_tid"})
   public class SwTraceIdConverter extends LogEventPatternConverter {
   
     private TraceIdConverter converter;
   
     protected SwTraceIdConverter(String name, String style) {
       super(name, style);
       converter = TraceIdConverter.newInstance(null);
     }
   
     public static SwTraceIdConverter newInstance(String[] options) {
       return new SwTraceIdConverter("sw_tid", "sw_tid");
     }
   
     @Override
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
       StringBuilder sb = new StringBuilder();
       converter.format(event, sb);
       String traceId = sb.toString().substring(5);
       toAppendTo.append(traceId);
     }
   }
   ```
   
   If the `TID: ` prefix can be removed, I don't need to do any coding to have the above valid JSON. And if the user really wants something like `TID: df16a9001ca34cafbe23cbc5751c0d66.96.16206346254060001`, he can use `TID: %traceId`. Here is another issue requesting the removal of the prefix: #6142. @ecyuan
   
   https://github.com/apache/skywalking-java/blob/main/docs/en/setup/service-agent/java-agent/Application-toolkit-log4j-2.x.md now supports both `%traceId` and `%sw_ctx`. `%sw_ctx` has all the context information beside Skywalking trace ID. If the prefix can't be removed, `%traceId` can be more easily used in Log4j2 pattern layout. And if the user wants to more tracing context information, he can use `%sw_ctx`.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on issue #6970: Make %traceId configurable for application toolkit for logging

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #6970:
URL: https://github.com/apache/skywalking/issues/6970#issuecomment-843285601


   Sorry, SLS should not be used as a primary consideration in this case. To match `TID:` is a very easy regex capability, I can't see why you want to use `|`, which doesn't make sense to a community-level feature.
   
   This doc should help, https://skywalking.apache.org/docs/main/latest/en/setup/service-agent/java-agent/application-toolkit-log4j-2.x/#print-skywalking-context-in-your-logs. But still, don't try to use `|` to do log analysis.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org