Report version from main
This allows running the agent as an executable jar to report the version number.
Also repot version scan errors better.
MODIFY
buildSrc/src/main/groovy/VersionScanPlugin.groovy
buildSrc/src/main/groovy/VersionScanPlugin.groovy
@@ -15,6 +15,7 @@ import org.eclipse.aether.spi.connector.RepositoryConnectorFactory
import org.eclipse.aether.spi.connector.transport.TransporterFactory
import org.eclipse.aether.transport.http.HttpTransporterFactory
import org.eclipse.aether.version.Version
+import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.objectweb.asm.ClassReader
@@ -138,7 +139,8 @@ class VersionScanPlugin implements Plugin<Project> {
if (!verifyPresent.isEmpty() || !verifyMissing.isEmpty()) {
def verifyVersionScan = project.task('verifyVersionScan') {
description = "Validates that the configured classes and methods are only present where expected."
- doLast {
+ }
+ verifyVersionScan.doLast {
// This may already be done by the report task, but repeating for good measure.
keyPresent.get().removeAll(allExclude)
keyMissing.get().removeAll(allInclude)
@@ -164,16 +166,15 @@ class VersionScanPlugin implements Plugin<Project> {
}
}
errors.each {
- System.err.println "Error for $group:$module - $it"
+ logger.error "Error for $group:$module - $it"
}
if (!errors.isEmpty()) {
- throw new AssertionError("Version scan verification failed.\n" +
+ throw new GradleException("Version scan verification failed.\n" +
"Errors listed above are likely the result of a new module " +
"being published to Maven, not a code change in this repo.\n" +
"This does mean a fix should be made though to 'dd-trace-supported-framework.yaml'.")
}
}
- }
if (project.gradle.startParameter.taskNames.contains('scanVersions')) {
scanVersions.finalizedBy(verifyVersionScan)

MODIFY
dd-java-agent/dd-java-agent.gradle
dd-java-agent/dd-java-agent.gradle
@@ -78,6 +78,7 @@ jar {
manifest {
attributes(
+ "Main-Class": "com.datadoghq.trace.agent.DDJavaAgentInfo",
// I don't think we want to define this since we can't really load after startup:
//"Agent-Class": "com.datadoghq.trace.agent.AnnotationsTracingAgent",
"Premain-Class": "com.datadoghq.trace.agent.AnnotationsTracingAgent",

MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/DDJavaAgentInfo.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/DDJavaAgentInfo.java
@@ -16,14 +16,19 @@ public class DDJavaAgentInfo {
final BufferedReader br =
new BufferedReader(
new InputStreamReader(
- DDJavaAgentInfo.class.getResourceAsStream("dd-java-agent.version"), "UTF-8"));
+ DDJavaAgentInfo.class.getResourceAsStream("/dd-java-agent.version"), "UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char) c);
v = sb.toString().trim();
} catch (final Exception e) {
+ e.printStackTrace();
v = "unknown";
}
VERSION = v;
log.info("dd-java-agent - version: {}", v);
}
+
+ public static void main(String... args) {
+ System.out.println(VERSION);
+ }
}

MODIFY
dd-trace-annotations/src/main/java/com/datadoghq/trace/DDTraceAnnotationsInfo.java
dd-trace-annotations/src/main/java/com/datadoghq/trace/DDTraceAnnotationsInfo.java
@@ -16,7 +16,7 @@ public class DDTraceAnnotationsInfo {
final BufferedReader br =
new BufferedReader(
new InputStreamReader(
- DDTraceAnnotationsInfo.class.getResourceAsStream("dd-trace-annotations.version"),
+ DDTraceAnnotationsInfo.class.getResourceAsStream("/dd-trace-annotations.version"),
"UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char) c);
@@ -27,4 +27,8 @@ public class DDTraceAnnotationsInfo {
VERSION = v;
log.info("dd-trace-annotations - version: {}", v);
}
+
+ public static void main(String... args) {
+ System.out.println(VERSION);
+ }
}

MODIFY
dd-trace-examples/rest-spark/rest-spark.gradle
dd-trace-examples/rest-spark/rest-spark.gradle
+plugins {
+ id "com.github.johnrengelman.shadow" version "2.0.1"
+}
+
apply plugin: 'application'
apply from: "${rootDir}/gradle/java.gradle"
apply from: "${rootDir}/gradle/jacoco.gradle"
@@ -23,6 +27,16 @@ dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
}
+jar {
+ manifest {
+ attributes 'Main-Class': 'com.datadoghq.example.restspark.SparkApplication'
+ }
+}
+
+shadowJar {
+ mergeServiceFiles()
+}
+
task wrapper(type: Wrapper) {
gradleVersion = '4.0'
}

MODIFY
dd-trace-java.gradle
dd-trace-java.gradle
@@ -30,25 +30,20 @@ apply from: "${rootDir}/gradle/publish.gradle"
// Source: https://github.com/ratpack/ratpack/blob/master/ratpack.gradle#L101
task bintrayPublish() {
doLast {
- if (!project.hasProperty("bintrayApiKey")) {
- throw new InvalidUserDataException("You must provide bintrayApiKey")
+ if (!project.hasProperty("bintrayApiKey") || bintrayApiKey.length() < 20) {
+ throw new InvalidUserDataException("You must provide a valid bintrayApiKey")
}
- if (!project.hasProperty('buildNumber')) {
- throw new GradleException("Must provide buildNumber of a release from https://oss.jfrog.org/artifactory/webapp/#/builds/dd-trace-java")
+ if (!project.hasProperty('buildNumber') || !"$buildNumber".isInteger()) {
+ throw new TaskExecutionException("Must provide buildNumber of a release from https://oss.jfrog.org/artifactory/webapp/#/builds/dd-trace-java")
}
- def curl = ['curl',
+ def curl = [
+ 'curl',
'-X', 'POST',
- "-u", "${bintrayUser}:${bintrayApiKey}",
- "-H", "Content-Type: application/json",
- "-d", """{
- "dryRun": "true",
- "targetRepo": "datadog-maven",
- "sourceRepos": ["oss-release-local"]
-}
-""",
- "https://oss.jfrog.org/api/build/distribute/dd-trace-java/$project.buildNumber"
+ '-u', "${bintrayUser}:${bintrayApiKey}",
+ '-d', '',
+ "http://oss.jfrog.org/api/plugins/build/promote/snapshotsToBintray/dd-trace-java/$project.buildNumber"
].execute()
logger.info("Received response: ${curl.text}")
}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTraceInfo.java
dd-trace/src/main/java/com/datadoghq/trace/DDTraceInfo.java
@@ -20,7 +20,7 @@ public class DDTraceInfo {
final BufferedReader br =
new BufferedReader(
new InputStreamReader(
- DDTraceInfo.class.getResourceAsStream("dd-trace.version"), "UTF-8"));
+ DDTraceInfo.class.getResourceAsStream("/dd-trace.version"), "UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char) c);
v = sb.toString().trim();
@@ -30,4 +30,8 @@ public class DDTraceInfo {
VERSION = v;
log.info("dd-trace - version: {}", v);
}
+
+ public static void main(String... args) {
+ System.out.println(VERSION);
+ }
}

MODIFY
dd-trace/src/test/groovy/com/datadoghq/trace/writer/DDApiTest.groovy
dd-trace/src/test/groovy/com/datadoghq/trace/writer/DDApiTest.groovy
@@ -76,7 +76,7 @@ class DDApiTest extends Specification {
requestContentType.get().type == "application/msgpack"
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
- requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
+ requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "Stubbed-Test-Version"
convertList(requestBody.get()) == expectedRequestBody
cleanup:
@@ -175,7 +175,7 @@ class DDApiTest extends Specification {
requestContentType.get().type == "application/msgpack"
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
- requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
+ requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "Stubbed-Test-Version"
convertMap(requestBody.get()) == expectedRequestBody
cleanup:

ADD
dd-trace/src/test/resources/dd-trace.version
+Stubbed-Test-Version

Report version from main

This allows running the agent as an executable jar to report the version number.

Also repot version scan errors better.