Skip to content

Commit

Permalink
Add distro name and version to the SDK name (#43737)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti authored Jan 13, 2025
1 parent d4e3b3d commit 2aa2130
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@
public final class VersionGenerator {
private static final String UNKNOWN_VERSION_VALUE = "unknown";

private static final String artifactName;
private static final String artifactVersion;

private static final String sdkVersionString;

static {
Map<String, String> properties
= CoreUtils.getProperties("azure-monitor-opentelemetry-autoconfigure.properties");
String componentName = null;
String componentVersion = null;

Map<String, String> springDistroProperties
= CoreUtils.getProperties("azure-spring-cloud-azure-starter-monitor.properties");
String springDistroVersion = springDistroProperties.get("version");
if (springDistroVersion != null) {
componentName = "dss";
componentVersion = springDistroVersion;
}

Map<String, String> quarkusProperties = CoreUtils.getProperties("quarkus-exporter.properties");
String quarkusVersion = quarkusProperties.get("version");
if (quarkusVersion != null) {
componentName = "dsq";
componentVersion = quarkusVersion;
}

artifactName = properties.get("name");
artifactVersion = properties.get("version");
if (componentName == null) {
componentName = "ext";
Map<String, String> otelAutoconfigureProperties
= CoreUtils.getProperties("azure-monitor-opentelemetry-autoconfigure.properties");
componentVersion = otelAutoconfigureProperties.get("version");
}

sdkVersionString = getPrefix() + "java" + getJavaVersion() + getJavaRuntime() + ":" + "otel"
+ getOpenTelemetryApiVersion() + ":" + "ext" + artifactVersion;
+ getOpenTelemetryApiVersion() + ":" + componentName + componentVersion;
}

private static String getPrefix() {
Expand Down Expand Up @@ -56,24 +72,6 @@ private static String getOs() {
return "u";
}

/**
* This method returns artifact name.
*
* @return artifactName.
*/
public static String getArtifactName() {
return artifactName;
}

/**
* This method returns artifact version.
*
* @return artifactVersion.
*/
public static String getArtifactVersion() {
return artifactVersion;
}

/**
* This method returns sdk version string as per the below format javaX:otelY:extZ X = Java
* version, Y = opentelemetry version, Z = exporter version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class VersionTest {
@Test
public void testArtifactName() {
assertThat(VersionGenerator.getArtifactName()).isEqualTo("azure-monitor-opentelemetry-autoconfigure");
}

@Test
public void testArtifactVersion() {
assertTrue(VersionGenerator.getArtifactVersion().matches("[0-9].[0-9].[0-9].*"));
}

@Test
public void testSdkVersion() {
// OpenTelemetry added version.properties files in 1.3.0
Expand Down

0 comments on commit 2aa2130

Please sign in to comment.