-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ChatModelSpanContributor #1260
Conversation
Interesting! I will have a closer look in a few days as I am traveling |
...rc/main/java/io/quarkiverse/langchain4j/runtime/listeners/ExtendedSpanChatModelListener.java
Outdated
Show resolved
Hide resolved
4b3e886
to
d98170f
Compare
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(AiService.class, EchoChatLanguageModelSupplier.class)) | ||
.setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-opentelemetry", "3.15.2"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geoand
"3.15.2"
any idea where this is supposed to come from?
or is there a simpler solution to it adding otel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to externalize the version, but just go ahead and copy it for now if you need to add a new test.
How about using so we can support multiple contributors? That way we also won't need the default bean. |
...untime/src/main/java/io/quarkiverse/langchain4j/runtime/listeners/SpanChatModelListener.java
Outdated
Show resolved
Hide resolved
By principal, we should own the list of attributes to be placed in a span, to make sure we have all the important attributes covered. |
I don't think this is necessary. We can add the proper documentation and Javadoc warning about this. |
4f9203a
to
8d7bc45
Compare
aiService.test(); | ||
|
||
await().untilAsserted(() -> assertThat(exporter.getFinishedSpanItems()).hasSize(1)); | ||
assertThat(exporter.getFinishedSpanItems()).extracting(SpanData::getName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geoand this will get nasty
i have yet to understand how spans are built in test - do you wanna go this road?
or may be a more stable / Mockito approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess for the purposes of this test, we can go with a mock approach (although I'm not a huge fan)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code should be ready, still missing version to be externalized
there is one "bug" i think i fixed that span was not ended in onError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code should be ready, still missing version to be externalized
I'll do that after the PR is merged
@brunobat this solution enables different attribute-sets for every "APM worth having" to be collected. they could be enabled by config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I only added a few very minor comments
@@ -53,6 +58,7 @@ public void onRequest(ChatModelRequestContext requestContext) { | |||
var attributes = requestContext.attributes(); | |||
attributes.put(OTEL_SCOPE_KEY_NAME, scope); | |||
attributes.put(OTEL_SPAN_KEY_NAME, span); | |||
chatModelSpanContributors.forEach(c -> invokeSafeWithRecordException(span, () -> c.onRequest(requestContext, span))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please avoid lambdas in this code. We generally strive for this principle in code that is executed at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np... - but how comes?
...untime/src/main/java/io/quarkiverse/langchain4j/runtime/listeners/SpanChatModelListener.java
Outdated
Show resolved
Hide resolved
...untime/src/main/java/io/quarkiverse/langchain4j/runtime/listeners/SpanChatModelListener.java
Outdated
Show resolved
Hide resolved
...ime/src/main/java/io/quarkiverse/langchain4j/runtime/listeners/ChatModelSpanContributor.java
Outdated
Show resolved
Hide resolved
...ime/src/main/java/io/quarkiverse/langchain4j/runtime/listeners/ChatModelSpanContributor.java
Outdated
Show resolved
Hide resolved
...ime/src/main/java/io/quarkiverse/langchain4j/runtime/listeners/ChatModelSpanContributor.java
Outdated
Show resolved
Hide resolved
|
||
== AI method declaration | ||
=== AI method declaration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geoand current doc broken here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it!
hope i am done!? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
enabling users adding more/custom attributes/data to span enabling us to add pre-built attribute-sets for diffrent APMs Closes quarkiverse#1256
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
This comment has been minimized.
This comment has been minimized.
Status for workflow
|
enabling adding more/custom attributes to span, namely before span is closed
for
onRequest
this would already be possible just using anotherChatModelListener
. not so unfortunately foronResponse
as span is ended inSpanChatModelListener.onResponse()
and so additional attributes land on parent-span overwriting each other with every new request.this change is just missing some
Processor
Magic producing a default-ExtendedSpanChatModelListener
and some docs may-be.