Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.opentelemetry.instrumentation.docs.internal.TelemetryAttribute;
import java.io.BufferedWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -133,7 +134,9 @@ private static Map<String, Object> baseProperties(InstrumentationModule module)
}

if (module.getAgentTargetVersions() != null && !module.getAgentTargetVersions().isEmpty()) {
moduleMap.put("javaagent_target_versions", new ArrayList<>(module.getAgentTargetVersions()));
List<String> agentTargetVersions = new ArrayList<>(module.getAgentTargetVersions());
Collections.sort(agentTargetVersions);
moduleMap.put("javaagent_target_versions", agentTargetVersions);
}

addConfigurations(module, moduleMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,56 @@ void testGenerateInstrumentationYamlSeparatesClassifications() throws Exception
assertThat(expectedYaml).isEqualTo(stringWriter.toString());
}

@Test
void testTargetVersionsAreOrdered() throws Exception {
List<InstrumentationModule> modules = new ArrayList<>();

modules.add(
new InstrumentationModule.Builder("test-instrumentation")
.srcPath("instrumentation/test-instrumentation")
.targetVersions(
Set.of(
"org.springframework.data:spring-data-commons:[1.8.0.RELEASE,)",
"org.springframework:spring-aop:[1.2,)"))
.build());

modules.add(
new InstrumentationModule.Builder("test-instrumentation2")
.srcPath("instrumentation/test-instrumentation2")
.targetVersions(
Set.of(
"org.springframework:spring-aop:[1.2,)",
"org.springframework.data:spring-data-commons:[1.8.0.RELEASE,)"))
.build());

StringWriter stringWriter = new StringWriter();
BufferedWriter writer = new BufferedWriter(stringWriter);

YamlHelper.generateInstrumentationYaml(modules, writer);
writer.flush();

String expectedYaml =
"""
libraries:
- name: test-instrumentation
source_path: instrumentation/test-instrumentation
scope:
name: io.opentelemetry.test-instrumentation
javaagent_target_versions:
- org.springframework.data:spring-data-commons:[1.8.0.RELEASE,)
- org.springframework:spring-aop:[1.2,)
- name: test-instrumentation2
source_path: instrumentation/test-instrumentation2
scope:
name: io.opentelemetry.test-instrumentation2
javaagent_target_versions:
- org.springframework.data:spring-data-commons:[1.8.0.RELEASE,)
- org.springframework:spring-aop:[1.2,)
""";

assertThat(expectedYaml).isEqualTo(stringWriter.toString());
}

@Test
void testMetadataParser() throws JsonProcessingException {
String input =
Expand Down
Loading