Commit 0e10e892 authored by Kelly Domico's avatar Kelly Domico Committed by Kishore Battula
Browse files

Add to customDimensions from MDC for logged requests

parent 959134f6
......@@ -389,6 +389,7 @@ The following software have components provided under the terms of this license:
- Microsoft Azure SDK annotations (from https://github.com/Microsoft/java-api-annotations)
- Microsoft Azure SDK for SQL API of Azure Cosmos DB Service (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure SDK for Service Bus (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure SDK for eventgrid (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure client library for Blob Storage (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure client library for Identity (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure client library for KeyVault Secrets (from https://github.com/Azure/azure-sdk-for-java)
......
package org.opengroup.osdu.azure.di;
import com.microsoft.applicationinsights.extensibility.TelemetryInitializer;
import lombok.Getter;
import org.opengroup.osdu.azure.logging.CustomDimensionsTelemetryInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
/**
* A configuration bean class to set up Application Insights custom configurations.
*/
@Configuration
@Getter
@Lazy
public class ApplicationInsightsCustomConfiguration {
/**
* Bean for CustomDimensionsTelemetryInitializer.
*
* @return instance of {@link CustomDimensionsTelemetryInitializer}
*/
@Bean
public TelemetryInitializer customDimensionsTelemetryInitializer() {
return new CustomDimensionsTelemetryInitializer();
}
}
......@@ -35,22 +35,24 @@ public class Slf4jMDCFilter implements Filter {
/**
* Filter logic.
* @param servletRequest Request object.
*
* @param servletRequest Request object.
* @param servletResponse Response object.
* @param filterChain Filter Chain object.
* @param filterChain Filter Chain object.
* @throws IOException
* @throws ServletException
*/
@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
final FilterChain filterChain) throws IOException, ServletException {
MDC.clear();
MDC.setContextMap(getContextMap());
filterChain.doFilter(servletRequest, servletResponse);
MDC.clear();
}
/**
* Method to create context map for mdc.
*
* @return Context map.
*/
private Map<String, String> getContextMap() {
......
package org.opengroup.osdu.azure.logging;
import com.microsoft.applicationinsights.internal.util.MapUtil;
import com.microsoft.applicationinsights.telemetry.ExceptionTelemetry;
import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
import com.microsoft.applicationinsights.telemetry.Telemetry;
import com.microsoft.applicationinsights.web.extensibility.initializers.WebTelemetryInitializerBase;
import org.slf4j.MDC;
/**
* Enrich telemetry with custom properties that will appear in customDimensions.
*/
public class CustomDimensionsTelemetryInitializer extends WebTelemetryInitializerBase {
/**
* Add MDC custom properties to request or exception telemetry.
*
* @param telemetry the Telemetry object
*/
@Override
protected void onInitializeTelemetry(final Telemetry telemetry) {
if (telemetry instanceof RequestTelemetry || telemetry instanceof ExceptionTelemetry) {
MapUtil.copy(MDC.getCopyOfContextMap(), telemetry.getContext().getProperties());
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment