-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library instrumentation should read its version from a file
- Loading branch information
Mateusz Rzeszutek
committed
Mar 25, 2022
1 parent
f2587ba
commit 4972634
Showing
19 changed files
with
283 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...s/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelInstrumentationExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.opentelemetry.instrumentation.gradle | ||
|
||
import org.gradle.api.provider.Property | ||
|
||
abstract class OtelInstrumentationExtension { | ||
|
||
abstract val name : Property<String> | ||
|
||
abstract val version : Property<String> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...n/java/io/opentelemetry/instrumentation/api/internal/EmbeddedInstrumentationVersions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.internal; | ||
|
||
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.list; | ||
import static java.util.Collections.unmodifiableMap; | ||
import static java.util.logging.Level.FINE; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class EmbeddedInstrumentationVersions { | ||
|
||
private static final Map<String, String> versions = loadVersions(); | ||
|
||
private static Map<String, String> loadVersions() { | ||
Map<String, String> versions = new HashMap<>(); | ||
|
||
// preload this once | ||
try { | ||
List<URL> urls = | ||
list( | ||
new ResourceLoaderProxy() | ||
.getResources("META-INF/io/opentelemetry/instrumentation.version")); | ||
Properties parsed = new Properties(); | ||
|
||
for (URL url : urls) { | ||
try (InputStream in = url.openStream()) { | ||
parsed.clear(); | ||
parsed.load(in); | ||
|
||
for (String name : parsed.stringPropertyNames()) { | ||
versions.put(name, parsed.getProperty(name)); | ||
} | ||
} | ||
} | ||
|
||
} catch (IOException e) { | ||
Logger.getLogger(EmbeddedInstrumentationVersions.class.getName()) | ||
.log(FINE, "Failed to load embedded instrumentation version file(s)", e); | ||
return emptyMap(); | ||
} | ||
|
||
return unmodifiableMap(versions); | ||
} | ||
|
||
@Nullable | ||
public static String findVersion(String instrumentationName) { | ||
return versions.get(instrumentationName); | ||
} | ||
|
||
// works as a proxy for the bootstrap classloader (if agent) | ||
private static final class ResourceLoaderProxy extends ClassLoader { | ||
ResourceLoaderProxy() { | ||
super(ResourceLoaderProxy.class.getClassLoader()); | ||
} | ||
} | ||
|
||
private EmbeddedInstrumentationVersions() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.