1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.monitoring 21 22 import kamon.Kamon 23 import kamon.tag.TagSet 24 import org.make.core.RequestContext 25 26 object MonitoringUtils { 27 28 private val DefaultAttributeValue = "unknown" 29 30 private val formatAttribute: Option[String] => String = 31 _.fold(DefaultAttributeValue)(MonitoringMessageHelper.format) 32 33 def logRequest(operationName: String, context: RequestContext, origin: Option[String]): Unit = 34 Kamon 35 .counter("api-requests") 36 .withTags( 37 TagSet.from( 38 Map( 39 "source" -> formatAttribute(context.source), 40 "operation" -> operationName, 41 "origin" -> formatAttribute(origin), 42 "application" -> formatAttribute(context.applicationName.map(_.value)), 43 "location" -> formatAttribute(context.location), 44 "question" -> formatAttribute(context.questionContext.questionId.map(_.value)) 45 ) 46 ) 47 ) 48 .increment() 49 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 28 | 45858 | 932 - 941 | Literal | <nosymbol> | org.make.api.user.adminuserapitest | "unknown" |
| 31 | 51046 | 1035 - 1065 | Apply | org.make.api.technical.monitoring.MonitoringMessageHelper.format | org.make.api.technical.makedirectivestest | MonitoringMessageHelper.format(value) |
| 31 | 37734 | 1012 - 1033 | Select | org.make.api.technical.monitoring.MonitoringUtils.DefaultAttributeValue | org.make.api.user.adminuserapitest | MonitoringUtils.this.DefaultAttributeValue |
| 31 | 46929 | 1005 - 1066 | Apply | scala.Option.fold | org.make.api.user.adminuserapitest | x$1.fold[String](MonitoringUtils.this.DefaultAttributeValue)(((value: String) => MonitoringMessageHelper.format(value))) |
| 48 | 31218 | 1689 - 1689 | Literal | <nosymbol> | org.make.api.user.adminuserapitest | () |
| 48 | 39363 | 1169 - 1691 | Apply | kamon.metric.Counter.increment | org.make.api.user.adminuserapitest | kamon.Kamon.counter("api-requests").withTags(kamon.tag.TagSet.from(scala.Predef.Map.apply[String, String](scala.Predef.ArrowAssoc[String]("source").->[String](MonitoringUtils.this.formatAttribute.apply(context.source)), scala.Predef.ArrowAssoc[String]("operation").->[String](operationName), scala.Predef.ArrowAssoc[String]("origin").->[String](MonitoringUtils.this.formatAttribute.apply(origin)), scala.Predef.ArrowAssoc[String]("application").->[String](MonitoringUtils.this.formatAttribute.apply(context.applicationName.map[String](((x$2: org.make.core.ApplicationName) => x$2.value)))), scala.Predef.ArrowAssoc[String]("location").->[String](MonitoringUtils.this.formatAttribute.apply(context.location)), scala.Predef.ArrowAssoc[String]("question").->[String](MonitoringUtils.this.formatAttribute.apply(context.questionContext.questionId.map[String](((x$3: org.make.core.question.QuestionId) => x$3.value))))))).increment() |