Skip to content

Commit

Permalink
app insights correlated telemtry
Browse files Browse the repository at this point in the history
  • Loading branch information
chtrembl committed Feb 8, 2024
1 parent e1f5d80 commit 5ead9ee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -297,6 +298,7 @@ private AzurePetStoreSessionInfo configureSession(TurnContext turnContext, Strin
// single time so you will want to change to
// turnContext.getActivity().getrecipient().getId() when running locally
String id = turnContext.getActivity().getId().trim();

if (id.contains("-")) {
id = id.substring(0, id.indexOf("-"));
}
Expand Down Expand Up @@ -328,6 +330,13 @@ private AzurePetStoreSessionInfo configureSession(TurnContext turnContext, Strin
azurePetStoreSessionInfo.setPrompts(existingPrompts);
}

MDC.put("newText", azurePetStoreSessionInfo!= null ? azurePetStoreSessionInfo.getNewText(): null);
MDC.put("unformattedID", turnContext.getActivity().getId().trim());
MDC.put("id", azurePetStoreSessionInfo!= null ? azurePetStoreSessionInfo.getId() : null);
MDC.put("sessionID", azurePetStoreSessionInfo!= null ? azurePetStoreSessionInfo.getSessionID() : null);
MDC.put("csrfToken", azurePetStoreSessionInfo!= null ? azurePetStoreSessionInfo.getCsrfToken() : null);
MDC.put("arrAffinity", azurePetStoreSessionInfo!= null ? azurePetStoreSessionInfo.getArrAffinity() : null);

return azurePetStoreSessionInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class AzurePetStoreSessionInfo implements Serializable{
private String arrAffinity = null;
@JsonIgnore
private String newText = null;
private String unformattedId = null;
private String id = null;

private List<Prompt> prompts = null;
Expand All @@ -37,6 +38,12 @@ public String getNewText() {
public void setNewText(String newText) {
this.newText = newText;
}
public String getUnformattedId() {
return unformattedId;
}
public void setUnformattedId(String unformattedId) {
this.unformattedId = unformattedId;
}
public String getId() {
return id;
}
Expand Down
20 changes: 20 additions & 0 deletions petstore/petstoreassistant/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>

<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />

<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} application=PetStoreAssistant newText=%X{newText} unformattedID=%X{unformattedID} formattedID=%X{id} sessionID=%X{sessionID} csrfToken=%X{csrfToken} arrAffinity=%X{arrAffinity} | %m%n%wEx
</Pattern>
</layout>
</appender>

<root level="INFO">
<appender-ref ref="consoleAppender" />
</root>
</configuration>

0 comments on commit 5ead9ee

Please sign in to comment.