Skip to content

Commit

Permalink
Merge pull request #155 from quarkiverse/#143
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier authored Dec 14, 2023
2 parents ec6d4f8 + 2ee632d commit b6a38ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class AiServicesProcessor {
private static final MethodDescriptor QUARKUS_AI_SERVICES_CONTEXT_REMOVE_CHAT_MEMORY_IDS = MethodDescriptor.ofMethod(
QuarkusAiServiceContext.class, "removeChatMemoryIds", void.class, Object[].class);
public static final DotName CDI_INSTANCE = DotName.createSimple(Instance.class);
private static final String[] EMPTY_STRING_ARRAY = new String[0];

@BuildStep
public void nativeSupport(CombinedIndexBuildItem indexBuildItem,
Expand Down Expand Up @@ -822,7 +823,12 @@ private Optional<AiServiceMethodCreateInfo.MetricsInfo> gatherMetricsInfo(Method
return Optional.empty();
}

String name = defaultAiServiceMetricName(method);
String name = "langchain4j.aiservices";
List<String> tags = new ArrayList<>();
tags.add("aiservice");
tags.add(method.declaringClass().name().withoutPackagePrefix());
tags.add("method");
tags.add(method.name());

AnnotationInstance timedInstance = method.annotation(MICROMETER_TIMED);
if (timedInstance == null) {
Expand All @@ -831,7 +837,8 @@ private Optional<AiServiceMethodCreateInfo.MetricsInfo> gatherMetricsInfo(Method

if (timedInstance == null) {
// we default to having all AiServices being timed
return Optional.of(new AiServiceMethodCreateInfo.MetricsInfo.Builder(name).build());
return Optional.of(new AiServiceMethodCreateInfo.MetricsInfo.Builder(name)
.setExtraTags(tags.toArray(EMPTY_STRING_ARRAY)).build());
}

AnnotationValue nameValue = timedInstance.value();
Expand All @@ -846,8 +853,9 @@ private Optional<AiServiceMethodCreateInfo.MetricsInfo> gatherMetricsInfo(Method

AnnotationValue extraTagsValue = timedInstance.value("extraTags");
if (extraTagsValue != null) {
builder.setExtraTags(extraTagsValue.asStringArray());
tags.addAll(Arrays.asList(extraTagsValue.asStringArray()));
}
builder.setExtraTags(tags.toArray(EMPTY_STRING_ARRAY));

AnnotationValue longTaskValue = timedInstance.value("longTask");
if (longTaskValue != null) {
Expand Down Expand Up @@ -885,10 +893,6 @@ private Optional<AiServiceMethodCreateInfo.SpanInfo> gatherSpanInfo(MethodInfo m
return Optional.of(new AiServiceMethodCreateInfo.SpanInfo(name));
}

private String defaultAiServiceMetricName(MethodInfo method) {
return "langchain4j.aiservices." + method.declaringClass().name().withoutPackagePrefix() + "." + method.name();
}

private String defaultAiServiceSpanName(MethodInfo method) {
return "langchain4j.aiservices." + method.declaringClass().name().withoutPackagePrefix() + "." + method.name();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ public static class MetricsInfo {
private final boolean histogram;
private final String description;

public MetricsInfo(String name) {
this(name, false, null, null, false, null);
}

@RecordableConstructor
public MetricsInfo(String name, boolean longTask, String[] extraTags, double[] percentiles, boolean histogram,
String description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void noTimedAnnotations() throws InterruptedException {
.statusCode(200)
.body(containsString("MockGPT"));

waitForMeters(registry.find("langchain4j.aiservices.AssistantResourceWithMetrics$Assistant1.chat").timers(), 1);
waitForMeters(registry.find("langchain4j.aiservices").tag("aiservice", "AssistantResourceWithMetrics$Assistant1")
.tag("method", "chat").timers(), 1);
}

@Test
Expand All @@ -55,8 +56,8 @@ public void timedAnnotationOnClass() throws InterruptedException {
.statusCode(200)
.body(containsString("MockGPT"));

waitForMeters(registry.find("langchain4j.aiservices.AssistantResourceWithMetrics$Assistant2.chat").tag("key", "value")
.timers(), 1);
waitForMeters(registry.find("langchain4j.aiservices").tag("aiservice", "AssistantResourceWithMetrics$Assistant2")
.tag("method", "chat").tag("key", "value").timers(), 1);
}

@Test
Expand Down

0 comments on commit b6a38ef

Please sign in to comment.