Clean up version and include git sha in reported number
Exclude lombok from being included in the shadow jar.
MODIFY
dd-java-agent/dd-java-agent.gradle
dd-java-agent/dd-java-agent.gradle
@@ -14,7 +14,8 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
'com.datadoghq.trace.agent.AnnotationsTracingAgent',
'com.datadoghq.trace.agent.AgentTracerConfig',
'com.datadoghq.trace.agent.TraceAnnotationsManager',
- 'com.datadoghq.trace.agent.InstrumentationChecker'
+ 'com.datadoghq.trace.agent.InstrumentationChecker',
+ 'com.datadoghq.trace.agent.DDJavaAgentInfo',
]
dependencies {
@@ -113,4 +114,8 @@ shadowJar {
exclude 'org/jboss/byteman/layer/LayerModuleFinder.class'
exclude 'org/jboss/byteman/layer/LayerModuleReader.class'
exclude 'org/jboss/byteman/layer/LayerModuleReference.class'
+
+ dependencies {
+ exclude(dependency('org.projectlombok:lombok:1.16.18'))
+ }
}

ADD
dd-java-agent/src/main/java/com/datadoghq/trace/agent/DDJavaAgentInfo.java
+package com.datadoghq.trace.agent;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+public class DDJavaAgentInfo {
+ public static final String VERSION;
+
+ static {
+ String v;
+ try {
+ final StringBuffer sb = new StringBuffer();
+
+ final BufferedReader br =
+ new BufferedReader(
+ new InputStreamReader(
+ 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) {
+ v = "unknown";
+ }
+ VERSION = v;
+ }
+}

ADD
dd-trace-annotations/src/main/java/com/datadoghq/trace/DDTraceAnnotationsInfo.java
+package com.datadoghq.trace;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+public class DDTraceAnnotationsInfo {
+ public static final String VERSION;
+
+ static {
+ String v;
+ try {
+ final StringBuffer sb = new StringBuffer();
+
+ final BufferedReader br =
+ new BufferedReader(
+ new InputStreamReader(
+ DDTraceAnnotationsInfo.class.getResourceAsStream("dd-trace-annotations.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) {
+ v = "unknown";
+ }
+ VERSION = v;
+ }
+}

MODIFY
dd-trace/dd-trace.gradle
dd-trace/dd-trace.gradle
@@ -14,7 +14,8 @@ minimumInstructionCoverage = 0.5
whitelistedInstructionClasses += whitelistedBranchClasses += [
"com.datadoghq.trace.integration.*",
'com.datadoghq.trace.writer.ListWriter',
- 'com.datadoghq.trace.DDTags'
+ 'com.datadoghq.trace.DDTags',
+ 'com.datadoghq.trace.DDTraceInfo',
]
dependencies {
@@ -52,6 +53,10 @@ shadowJar {
relocate 'org.jboss.byteman', 'dd.deps.org.jboss.byteman'
relocate 'org.reflections', 'dd.deps.org.reflections'
relocate 'org.yaml', 'dd.deps.org.yaml'
+
+ dependencies {
+ exclude(dependency('org.projectlombok:lombok:1.16.18'))
+ }
}
jmh {

ADD
dd-trace/src/main/java/com/datadoghq/trace/DDTraceInfo.java
+package com.datadoghq.trace;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+public class DDTraceInfo {
+
+ public static final String JAVA_VERSION = System.getProperty("java.version", "unknown");
+ public static final String JAVA_VM_NAME = System.getProperty("java.vm.name", "unknown");
+
+ public static final String VERSION;
+
+ static {
+ String v;
+ try {
+ final StringBuffer sb = new StringBuffer();
+
+ final BufferedReader br =
+ new BufferedReader(
+ new InputStreamReader(
+ 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();
+ } catch (final Exception e) {
+ v = "unknown";
+ }
+ VERSION = v;
+ }
+}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
@@ -25,15 +25,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class DDTracer extends ThreadLocalActiveSpanSource implements io.opentracing.Tracer {
- public static final String JAVA_VERSION = System.getProperty("java.version", "unknown");
- public static final String JAVA_VM_NAME = System.getProperty("java.vm.name", "unknown");
- public static final String CURRENT_VERSION;
-
- static {
- final String version = DDTracer.class.getPackage().getImplementationVersion();
- CURRENT_VERSION = version != null ? version : "unknown";
- }
-
public static final String UNASSIGNED_DEFAULT_SERVICE_NAME = "unnamed-java-app";
public static final Writer UNASSIGNED_WRITER = new LoggingWriter();
public static final Sampler UNASSIGNED_SAMPLER = new AllSampler();

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/writer/DDApi.java
dd-trace/src/main/java/com/datadoghq/trace/writer/DDApi.java
package com.datadoghq.trace.writer;
import com.datadoghq.trace.DDBaseSpan;
-import com.datadoghq.trace.DDTracer;
+import com.datadoghq.trace.DDTraceInfo;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -90,9 +90,9 @@ public class DDApi {
httpCon.setRequestMethod("PUT");
httpCon.setRequestProperty("Content-Type", "application/json");
httpCon.setRequestProperty("Datadog-Meta-Lang", "java");
- httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTracer.JAVA_VERSION);
- httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTracer.JAVA_VM_NAME);
- httpCon.setRequestProperty("Datadog-Meta-Tracer-Version", DDTracer.CURRENT_VERSION);
+ httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTraceInfo.JAVA_VERSION);
+ httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTraceInfo.JAVA_VM_NAME);
+ httpCon.setRequestProperty("Datadog-Meta-Tracer-Version", DDTraceInfo.VERSION);
return httpCon;
}
}

MODIFY
gradle/publish.gradle
gradle/publish.gradle
apply plugin: 'maven'
apply plugin: "com.jfrog.artifactory"
apply plugin: "signing"
+
+apply from: "$rootDir/gradle/version.gradle"
apply from: "${rootDir}/gradle/pom.gradle"
afterEvaluate {

ADD
gradle/version.gradle
+def getGitHash = { ->
+ def stdout = new ByteArrayOutputStream()
+ exec {
+ commandLine 'git', 'rev-parse', '--short', 'HEAD'
+ standardOutput = stdout
+ }
+ return stdout.toString().trim()
+}
+
+task writeVersionNumberFile {
+
+ def versionFile = file("${sourceSets.main.output.resourcesDir}/${project.name}.version")
+ inputs.property "version", project.version
+ outputs.file versionFile
+
+ doFirst {
+ assert versionFile.parentFile.mkdirs() || versionFile.parentFile.directory
+ versionFile.text = "${project.version}~${getGitHash()}"
+ }
+}
+
+processResources.dependsOn writeVersionNumberFile

Clean up version and include git sha in reported number

Exclude lombok from being included in the shadow jar.