Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#4,085 0 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
azure, java
Ambito
observability

Direzione di ricerca

Inizia individuando l’instrumentazione fwi_java esistente per SLF4J MDC.put e confrontala con l’API fluent addKeyValue(key, value) di SLF4J. Traccia il percorso dei metadati dei log fino a customDimensions di Application Insights, quindi verifica che una chiamata di log fluent produca la voce chiave-valore nella tabella traces.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
327
Fork
222
Merge medio
22h 34m
PR unite (30g)
14

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/ApplicationInsights-Java

Tutte le issue di microsoft/ApplicationInsights-Java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.