Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions obp-api/src/main/scala/code/bankconnectors/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ package object bankconnectors extends MdcLoggable {
// Consider refactoring invokeMethod to accept a pre-resolved connectorName to avoid the duplicate lookup.
val (_, connectorName) = getConnectorNameAndMethodRouting(methodName, argNameToValue)

// Extract correlationId from CallContext before entering any Future callback,
// because Lift's S.containerSession is unavailable in async contexts.
val correlationId: String = args.collectFirst {
case Some(cc: CallContext) => cc.correlationId
case Full(cc: CallContext) => cc.correlationId
}.getOrElse(getCorrelationId()) // fallback to Lift session if no CallContext in args

// Record outbound (before call)
ConnectorCountsRedis.incrementOutbound(connectorName, methodName)
val t0 = System.currentTimeMillis()
Expand All @@ -88,11 +95,6 @@ package object bankconnectors extends MdcLoggable {
// Record detailed metric to DB
if (getPropsAsBoolValue("write_connector_metrics", false)) {
val params = extractKeyParams(args)
// TODO: The correlation_id should be passed down from the REST API layer
// so that one REST call with a correlation_id results in multiple connector
// metric records each sharing the same correlation_id. Currently getCorrelationId()
// relies on Lift's S.containerSession which is unavailable inside this Future.
val correlationId = getCorrelationId()
Future {
ConnectorMetricsProvider.metrics.vend.saveConnectorMetric(
connectorName, methodName, correlationId, now, duration, params, isSuccess)
Expand All @@ -108,8 +110,6 @@ package object bankconnectors extends MdcLoggable {

if (getPropsAsBoolValue("write_connector_metrics", false)) {
val params = extractKeyParams(args)
// TODO: Same as above — correlation_id should come from the REST API layer.
val correlationId = getCorrelationId()
Future {
ConnectorMetricsProvider.metrics.vend.saveConnectorMetric(
connectorName, methodName, correlationId, now, duration, params, isSuccess)
Expand Down
Loading