@@ -8,16 +8,12 @@ import java.io.FileOutputStream
88import java.net.URL
99import java.nio.file.Files
1010import java.nio.file.StandardCopyOption
11- import java.util.Properties
1211import java.util.concurrent.locks.ReentrantLock
1312import kotlin.io.path.deleteIfExists
1413
1514private const val JARS_DIR_PREFIX = " digma-otel-jars"
1615private const val RESOURCE_LOCATION = " otelJars"
1716
18- private const val OTEL_AGENT_JAR_PROP_NAME = " otel-agent"
19- private const val DIGMA_EXTENSION_JAR_PROP_NAME = " digma-extension"
20- private const val DIGMA_AGENT_JAR_PROP_NAME = " digma-agent"
2117private const val OTEL_AGENT_JAR_NAME = " opentelemetry-javaagent.jar"
2218private const val DIGMA_AGENT_EXTENSION_JAR_NAME = " digma-otel-agent-extension.jar"
2319private const val DIGMA_AGENT_JAR_NAME = " digma-agent.jar"
@@ -49,19 +45,16 @@ class OTELJarProvider {
4945
5046 private val downloadDir: File = File (System .getProperty(" java.io.tmpdir" ), JARS_DIR_PREFIX )
5147
52- private val jarsUrls = Properties ()
53-
5448 private val lock = ReentrantLock (true )
5549
5650
5751 init {
5852
59- jarsUrls.load(this ::class .java.getResourceAsStream(" /jars-urls.properties" ))
60-
6153 // unpack and download on service initialization.
6254 // will happen per IDE session
6355 Thread {
64- unpackFilesAndDownloadLatest()
56+ unpackFiles()
57+ downloadCustomJars()
6558 }.start()
6659 }
6760
@@ -114,8 +107,8 @@ class OTELJarProvider {
114107
115108 Log .log(logger::info, " otel jars do not exists, unpacking.." )
116109
117- unpackFilesAndDownloadLatest ()
118-
110+ unpackFiles ()
111+ downloadCustomJars()
119112 }
120113
121114 private fun filesExist (): Boolean {
@@ -126,7 +119,7 @@ class OTELJarProvider {
126119 }
127120
128121
129- private fun unpackFilesAndDownloadLatest () {
122+ private fun unpackFiles () {
130123
131124 Log .log(logger::info, " unpacking otel agent jars" )
132125
@@ -148,8 +141,6 @@ class OTELJarProvider {
148141 Log .warnWithException(logger, e, " could not unpack otel jars, hopefully download will succeed." )
149142 }
150143 }
151-
152- tryDownloadLatest()
153144 }
154145
155146
@@ -167,22 +158,28 @@ class OTELJarProvider {
167158 }
168159
169160
170- private fun tryDownloadLatest () {
161+ private fun downloadCustomJars () {
171162
172- Log .log(logger::info, " trying to download latest otel jars" )
163+ Log .log(logger::info, " trying to download custom otel jars" )
173164
174165 val runnable = Runnable {
175166
176167 try {
177- val otelUrl = System .getProperty(" org.digma.otel.agentUrl" , jarsUrls.getProperty(OTEL_AGENT_JAR_PROP_NAME ))
178- val extensionUrl = System .getProperty(" org.digma.otel.extensionUrl" , jarsUrls.getProperty(DIGMA_EXTENSION_JAR_PROP_NAME ))
179- val digmaAgentUrl = System .getProperty(" org.digma.otel.digmaAgentUrl" , jarsUrls.getProperty(DIGMA_AGENT_JAR_PROP_NAME ))
180168
181- downloadAndCopyJar(URL (otelUrl), getOtelAgentJar())
182- downloadAndCopyJar(URL (extensionUrl), getDigmaAgentExtensionJar())
183- downloadAndCopyJar(URL (digmaAgentUrl), getDigmaAgentJar())
169+ System .getProperty(" org.digma.otel.agentUrl" )?.let {
170+ downloadAndCopyJar(URL (it), getOtelAgentJar())
171+ }
172+
173+ System .getProperty(" org.digma.otel.extensionUrl" )?.let {
174+ downloadAndCopyJar(URL (it), getDigmaAgentExtensionJar())
175+ }
176+
177+ System .getProperty(" org.digma.otel.digmaAgentUrl" )?.let {
178+ downloadAndCopyJar(URL (it), getDigmaAgentJar())
179+ }
180+
184181 } catch (e: Exception ) {
185- Log .warnWithException(logger, e, " could not download latest otel jars" )
182+ Log .warnWithException(logger, e, " could not download custom otel jars" )
186183 }
187184 }
188185
0 commit comments