You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At our project we have a bunch of azure function written in java. Those functions are connected to the application insight through the following env variables
In java code we use SLF4J and Logback libraries for logging. We often need to attach some metadata to our logs so it appears in customDimensions field in the traces table in application insights.
So far we have been doing this by using MDC from SLF4J, so the code is something alone these lines
The code above makes "my log message" having "key1" field in customDimensions field in traces table in application insights. Fine. That means that MDC.put() has been properly instrumented.
But recently we discovered more convenient way to attach those additional fields to the log message.
SLF4J provides fluent api https://www.slf4j.org/manual.html#fluent which exposes addKeyValue(key, val) method for doing that (instead of putting those key+val in MDC)
So the code above can be rewritten as following:
Unfortunately, in this case key1="val1" entry does not appear in the customDimensions of this log message in traces table in the application insights. That means fwi_java SDK does not instrument this addKeyValue() as it does for MDC.put().
From my point of view making .addKeyValue(key, val) instrumented similarly to MDC.put(key, val) would be the right move. They both have very similar semantics, but .addKeyValue(key, val) makes the code much cleaner.
The text was updated successfully, but these errors were encountered:
At our project we have a bunch of azure function written in java. Those functions are connected to the application insight through the following env variables
In java code we use SLF4J and Logback libraries for logging. We often need to attach some metadata to our logs so it appears in
customDimensions
field in thetraces
table in application insights.So far we have been doing this by using MDC from SLF4J, so the code is something alone these lines
The code above makes "my log message" having "key1" field in
customDimensions
field intraces
table in application insights. Fine. That means thatMDC.put()
has been properly instrumented.But recently we discovered more convenient way to attach those additional fields to the log message.
SLF4J provides fluent api https://www.slf4j.org/manual.html#fluent which exposes
addKeyValue(key, val)
method for doing that (instead of putting those key+val in MDC)So the code above can be rewritten as following:
Looks much cleaner, doesn't it?
Unfortunately, in this case
key1="val1"
entry does not appear in thecustomDimensions
of this log message intraces
table in the application insights. That meansfwi_java
SDK does not instrument thisaddKeyValue()
as it does forMDC.put()
.From my point of view making
.addKeyValue(key, val)
instrumented similarly toMDC.put(key, val)
would be the right move. They both have very similar semantics, but.addKeyValue(key, val)
makes the code much cleaner.The text was updated successfully, but these errors were encountered: