Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Instrument SLF4J's addKeyValue(key, value) method from fluent API

Abierto
#4,085 0 comentarios 5 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
38/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
azure, java

Línea de trabajo

Comienza localizando la instrumentación existente de fwi_java para SLF4J MDC.put y compárala con la API fluent addKeyValue(key, value) de SLF4J. Rastrea cómo llegan los metadatos de los logs a customDimensions de Application Insights y, después, verifica que una llamada de log fluent produzca la entrada de clave-valor en la tabla traces.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

APPLICATIONINSIGHTS_CONNECTION_STRING=...
APPLICATIONINSIGHTS_ENABLE_AGENT=true

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

MDC.put("key1", "val1");
log.info("my log message");
MDC.remove("key1");

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:

log.atInfo()
    .addKeyValue("key1", "val1")
    .log("my log message");

Looks much cleaner, doesn't it?

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.

Lenguaje dominante
Java
Estrellas
327
Forks
222
Merge medio
22 h 34 min
PR fusionados (30 d)
14

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/ApplicationInsights-Java

Todos los issues de microsoft/ApplicationInsights-Java

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.