Skip to content

Commit

Permalink
rename log field fastlyRequestId to requestId
Browse files Browse the repository at this point in the history
this is because there is no fastly id for preview requests
  • Loading branch information
marjisound committed Feb 3, 2025
1 parent 975cc57 commit 5ba6ee2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common/app/common/RequestLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ case class RequestLoggerFields(request: RequestHeader, response: Option[Result],

(allowListedHeaders ++ guardianSpecificHeaders).toList.map { case (headerName, headerValue) =>
if (headerName == "x-gu-xid") {
LogFieldString(s"fastlyRequestId", headerValue)
LogFieldString(s"requestId", headerValue)
} else {
LogFieldString(s"req.header.$headerName", headerValue)
}
Expand Down
4 changes: 2 additions & 2 deletions common/app/common/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ object `package`
context: ApplicationContext,
log: Logger,
): PartialFunction[Throwable, Result] = {
val fastlyRequestId = request.headers.get("x-gu-xid").getOrElse("fastly-id-not-provided")
val requestId = request.headers.get("x-gu-xid").getOrElse("request-id-not-provided")
val customFieldMarker: LogstashMarker = {
append("fastlyRequestId", fastlyRequestId)
append("requestId", requestId)
}
{
case _: CircuitBreakerOpenException =>
Expand Down
18 changes: 9 additions & 9 deletions common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
ws: WSClient,
payload: JsValue,
endpoint: String,
fastlyRequestId: Option[String],
requestId: Option[String],
timeout: Duration = Configuration.rendering.timeout,
)(implicit request: RequestHeader): Future[WSResponse] = {

Expand All @@ -70,7 +70,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
.withRequestTimeout(timeout)
.addHttpHeaders("Content-Type" -> "application/json")

val resp = fastlyRequestId match {
val resp = requestId match {
case Some(id) => request.addHttpHeaders("x-gu-xid" -> id).post(payload)
case None => request.post(payload)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
cacheTime: CacheTime,
timeout: Duration = Configuration.rendering.timeout,
)(implicit request: RequestHeader): Future[Result] = {
val fastlyRequestId = request.headers.get("x-gu-xid")
val requestId = request.headers.get("x-gu-xid")
def handler(response: WSResponse): Result = {
response.status match {
case 200 =>
Expand Down Expand Up @@ -140,10 +140,10 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload

if (CircuitBreakerDcrSwitch.isSwitchedOn) {
circuitBreaker
.withCircuitBreaker(postWithoutHandler(ws, payload, endpoint, fastlyRequestId, timeout))
.withCircuitBreaker(postWithoutHandler(ws, payload, endpoint, requestId, timeout))
.map(handler)
} else {
postWithoutHandler(ws, payload, endpoint, fastlyRequestId, timeout).map(handler)
postWithoutHandler(ws, payload, endpoint, requestId, timeout).map(handler)
}
}

Expand Down Expand Up @@ -232,9 +232,9 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
)(implicit request: RequestHeader): Future[String] = {
val dataModel = DotcomBlocksRenderingDataModel(page, request, blocks)
val json = DotcomBlocksRenderingDataModel.toJson(dataModel)
val fastlyRequestId = request.headers.get("x-gu-xid")
val requestId = request.headers.get("x-gu-xid")

postWithoutHandler(ws, json, Configuration.rendering.articleBaseURL + "/Blocks", fastlyRequestId)
postWithoutHandler(ws, json, Configuration.rendering.articleBaseURL + "/Blocks", requestId)
.flatMap(response => {
if (response.status == 200)
Future.successful(response.body)
Expand All @@ -254,9 +254,9 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
)(implicit request: RequestHeader): Future[String] = {
val dataModel = DotcomBlocksRenderingDataModel(page, request, blocks)
val json = DotcomBlocksRenderingDataModel.toJson(dataModel)
val fastlyRequestId = request.headers.get("x-gu-xid")
val requestId = request.headers.get("x-gu-xid")

postWithoutHandler(ws, json, Configuration.rendering.articleBaseURL + "/AppsBlocks", fastlyRequestId)
postWithoutHandler(ws, json, Configuration.rendering.articleBaseURL + "/AppsBlocks", requestId)
.flatMap(response => {
if (response.status == 200)
Future.successful(response.body)
Expand Down
2 changes: 1 addition & 1 deletion common/app/utils/DotcomponentsLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case class DotcomponentsLoggerFields(request: Option[RequestHeader]) {
"req.method" -> r.method,
"req.url" -> r.uri,
"req.id" -> Random.nextInt(Integer.MAX_VALUE).toString,
"fastlyRequestId" -> r.headers.get("x-gu-xid").getOrElse("fastly-id-not-provided"),
"requestId" -> r.headers.get("x-gu-xid").getOrElse("request-id-not-provided"),
)
}
.getOrElse(Nil)
Expand Down

0 comments on commit 5ba6ee2

Please sign in to comment.