-
Hi, I'm trying to encode my stacktrace in JSON, but my config does not seem to do the trick, I still have the stack trace in one string with I inspired myself from https://stackoverflow.com/a/49838106/7208947 but used directly the StackTraceJsonProvider class, is that supported (the README does not mention that possibility as far as I can see) ? The relevant parts of my config : <nestedField>
<fieldName>logback</fieldName>
<providers>
<logstashMarkers/>
<context>
<fieldName>context</fieldName>
</context>
<contextName>
<fieldName>contextName</fieldName>
</contextName>
<tags/>
<throwableClassName>
<useSimpleClassName>false</useSimpleClassName>
</throwableClassName>
<provider class="net.logstash.logback.composite.loggingevent.StackTraceJsonProvider">
<fieldName>stacktraceTestingOnly</fieldName>
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>1000</maxDepthPerThrowable>
<maxLength>50000</maxLength>
<rootCauseFirst>true</rootCauseFirst>
</throwableConverter>
</provider>
</providers>
</nestedField> And a log example (redacted) {
"context": {},
"contextName": "default",
"throwable_class": "org.springframework.web.reactive.function.client.WebClientRequestException",
"stacktraceTestingOnly": "<lots of lines...>\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\n\t\tat java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\t\tat java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)\n\t\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)\n\t\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n\t\tat java.lang.Thread.run(Thread.java:831)\n"
} Is that usecase possible, and how could I achieve a result similar to the one in the linked stackoverflow answer (see below) ? {
l_t : "2018-04-14T20:00:25.066-07:00",
l_l : "ERROR",
l_m : "Error while validating field existence",
service : "com.ac.api.client.product.ProductService",
method : "fetchProduct",
value : "p-j0ednf7f6wd8l6rss",
l_th : "http-nio-8080-exec-5",
stack_hash : "26c1547b",
l_c : "com.ac.core.validation.ExistsByStringFieldValidator:isValid:34",
stack_trace : {
1 : "c.i.c.a.c.e.RemoteServiceException: error code: 1002, user msg: remote.service.objectNotFound, parameters: [(identifier: p-j0ednf7f6wd8l6rss)]",
2 : "at c.i.c.a.c.p.ProductServiceImpl.toProduct(ProductServiceImpl.java:69)",
3 : "at c.i.c.a.c.p.ProductServiceImpl.fetchProductInternal(ProductServiceImpl.java:44)",
4 : "at c.i.c.a.c.p.ProductServiceImpl.fetchProduct(ProductServiceImpl.java:33)",
5 : "at c.i.c.a.c.p.ProductServiceImpl$$FastClassBySpringCGLIB$$5ee58445.invoke(<generated>)",
6 : "at o.s.c.p.MethodProxy.invoke(MethodProxy.java:204)",
7 : "at o.s.a.f.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)",
8 : "at o.s.a.f.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)",
9 : "at o.s.c.j.i.JCacheInterceptor$1.invoke(JCacheInterceptor.java:52)",
10 : "at o.s.c.j.i.JCacheAspectSupport.invokeOperation(JCacheAspectSupport.java:153)",
11 : "at o.s.c.j.i.JCacheAspectSupport$CacheOperationInvokerAdapter.invoke(JCacheAspectSupport.java:167)",
12 : "at o.s.c.j.i.CacheResultInterceptor.invoke(CacheResultInterceptor.java:62)",
13 : "at o.s.c.j.i.JCacheAspectSupport.execute(JCacheAspectSupport.java:123)",
14 : "at o.s.c.j.i.JCacheAspectSupport.execute(JCacheAspectSupport.java:102)",
15 : "at o.s.c.j.i.JCacheInterceptor.invoke(JCacheInterceptor.java:61)",
16 : "at o.s.a.f.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)",
17 : "at o.s.a.f.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)",
18 : "at c.i.c.a.c.p.ProductServiceImpl$$EnhancerBySpringCGLIB$$f315262.fetchProduct(<generated>)",
19 : "... 124 common frames omitted\nWrapped by: j.l.r.InvocationTargetException: null",
20 : "at s.r.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java)",
21 : "at s.r.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
22 : "at s.r.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
23 : "at j.l.reflect.Method.invoke(Method.java:498)",
24 : "at c.i.c.c.v.ExistsByStringFieldValidator.isValid(ExistsByStringFieldValidator.java:29)",
25 : "at c.i.c.c.v.ExistsByStringFieldValidator.isValid(ExistsByStringFieldValidator.java:12)",
26 : "at o.h.v.i.e.c.ConstraintTree.validateSingleConstraint(ConstraintTree.java:448)",
27 : "at o.h.v.i.e.c.ConstraintTree.validateConstraints(ConstraintTree.java:127)",
28 : "at o.h.v.i.e.c.ConstraintTree.validateComposingConstraints(ConstraintTree.java:398)",
29 : "at o.h.v.i.e.c.ConstraintTree.validateConstraints(ConstraintTree.java:98)",
30 : "at o.h.v.i.e.c.ConstraintTree.validateConstraints(ConstraintTree.java:87)",
31 : "at o.h.v.i.m.c.MetaConstraint.validateConstraint(MetaConstraint.java:73)",
32 : "at o.h.v.i.e.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:621)",
33 : "at o.h.v.i.e.ValidatorImpl.validateConstraint(ValidatorImpl.java:584)",
34 : "at o.h.v.i.e.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:528)",
35 : "at o.h.v.i.e.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:496)",
36 : "at o.h.v.i.e.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:461)",
37 : "at o.h.v.i.e.ValidatorImpl.validateInContext(ValidatorImpl.java:411)",
38 : "at o.h.v.i.e.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:762)",
39 : "at o.h.v.i.e.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:685)",
40 : "at o.h.v.i.e.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:1126)",
41 : "at o.h.v.i.e.ValidatorImpl.validateParameters(ValidatorImpl.java:302)",
42 : "at o.h.v.i.e.ValidatorImpl.validateParameters(ValidatorImpl.java:256)",
43 : "at s.r.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java)",
44 : "at s.r.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
45 : "... 99 frames truncated\n"
}
} EDIT: Add the json stacktrace example from SO |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The logstash-logback-encoder does not have a To do so, you would need to implement a custom After you write your own custom If you are using a |
Beta Was this translation helpful? Give feedback.
The
net.logstash.logback.composite.loggingevent.StackTraceJsonProvider
provided by logstash-logback-encoder writes the stacktrace as a single string field.logstash-logback-encoder does not have a
JsonProvider
that breaks up the stacktrace into individual frames as separate fields.To do so, you would need to implement a custom
JsonProvider
. The stackoverflow answer you referenced includes an implementation of a custom JsonProvider that breaks up the string produced by the throwable converter. Alternatively, you could write aJsonProvider
that writes output directly from theevent.getThrowableProxy()
(without converting to a string, and then parsing it).After you write your own custom
Js…