Skip to content

Commit

Permalink
WX-1122 Enable Azure ApplicationInsights (#7143)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgainerdewar authored May 26, 2023
1 parent c5d6151 commit 0119ac6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ tesk_application.conf
**/venv/
exome_germline_single_sample_v1.3/
**/*.pyc
applicationinsights.log
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

### HTTPFilesystem Improvements

* WDL `size` engine function now works for HTTP files.
WDL `size` engine function now works for HTTP files.

### Azure Instrumentation Support
Cromwell can now send logs and process information to Azure Application Insights. To enable, set environment
variable `APPLICATIONINSIGHTS_CONNECTION_STRING` to your connection string. [See here for information.](https://learn.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string)


## 85 Release Notes

Expand Down
4 changes: 3 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Dependencies {
// https://github.com/sbt/sbt/issues/4531
private val azureStorageBlobNioV = "12.0.0-beta.19"
private val azureIdentitySdkV = "1.9.0-beta.2"
private val azureAppInsightsV = "3.4.12"
private val betterFilesV = "3.9.1"
private val jsonSmartV = "2.4.10"
/*
Expand Down Expand Up @@ -210,7 +211,8 @@ object Dependencies {
"com.azure" % "azure-core-management" % "1.7.1",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-xml" % jacksonV,
"com.azure.resourcemanager" % "azure-resourcemanager" % "2.18.0",
"net.minidev" % "json-smart" % jsonSmartV
"net.minidev" % "json-smart" % jsonSmartV,
"com.microsoft.azure" % "applicationinsights-runtime-attach" % azureAppInsightsV,
)

val wsmDependencies: List[ModuleID] = List(
Expand Down
7 changes: 7 additions & 0 deletions server/src/main/resources/applicationinsights.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"instrumentation": {
"jdbc": {
"enabled": false
}
}
}
15 changes: 15 additions & 0 deletions server/src/main/scala/cromwell/CromwellEntryPoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cats.data.Validated._
import cats.effect.{ContextShift, IO}
import cats.syntax.apply._
import cats.syntax.validated._
import com.microsoft.applicationinsights.attach.ApplicationInsights
import com.typesafe.config.{Config, ConfigFactory}
import common.exception.MessageAggregation
import common.validation.ErrorOr._
Expand Down Expand Up @@ -45,6 +46,11 @@ object CromwellEntryPoint extends GracefulStopSupport {
private val dnsCacheTtl = config.getOrElse("system.dns-cache-ttl", 3 minutes)
java.security.Security.setProperty("networkaddress.cache.ttl", dnsCacheTtl.toSeconds.toString)

// The presence of this env var tells us that the user is trying to send instrumentation data and
// logs to Azure Application Insights. If it's present, we'll attach the ApplicationInsights agent.
// To configure the behavior of this agent, see server/src/main/resources/applicationinsights.json
private lazy val useAzureInstrumentation = sys.env.contains("APPLICATIONINSIGHTS_CONNECTION_STRING")

/**
* Run Cromwell in server mode.
*/
Expand Down Expand Up @@ -140,8 +146,17 @@ object CromwellEntryPoint extends GracefulStopSupport {
*
* Also copies variables from config/system/environment/defaults over to the system properties.
* Fixes issue where users are trying to specify Java properties as environment variables.
*
* Also also enables Azure log handling when appropriate
*/
private def initLogging(command: Command): Unit = {

// Enable Azure instrumentation and log-slurping if desired. Running ApplicationInsights.attach()
// without checking for the presence of the relevant env var doesn't cause any failures, but does
// print an error that would be confusing for non-Azure users.
if (useAzureInstrumentation)
ApplicationInsights.attach()

val logbackSetting = command match {
case Server => "STANDARD"
case Submit => "PRETTY"
Expand Down

0 comments on commit 0119ac6

Please sign in to comment.