Skip to content

Micrometer instrumentation for tool calling #3066

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

Conversation

ThomasVitale
Copy link
Contributor

@ThomasVitale ThomasVitale commented May 9, 2025

Introduce instrumentation for tool calling using the Micrometer Observation API.

By default, metadata about tool calling are exported as metrics and traces. Optionally, the actual tool call input and result can be exported as well by enabling the dedicated feature flag.

Fixes gh-1924

@ThomasVitale
Copy link
Contributor Author

FYI @shakuzen @jonatan-ivanov Standard Micrometer-based instrumentation following the patterns we used for rest of the project.

Some of the shared attributes come from naming conventions originally based on the OTel SemConv. If it's gonna be decided to rename them, then this new instrumentation will use those new names automatically since they are based on enums (i.e. not much refactoring needed).


@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = ToolCallingProperties.CONFIG_PREFIX + ".observations", name = "include-content",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi: in otel this I believe would be the same ENV var used for normal content. OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true as there is no difference in toggle whether it is a message or a tool. So, for folks using otel they need to map two properties to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out! Yeah, I guess that will be needed.

@codefromthecrypt
Copy link

@ThomasVitale curious is the schema capture limited to certain inference platforms or for all of them. I like that you have the ability to capture schema because there are some models that act differently depending on how schema are translated.

fyi on the otel genai semconv issue on schema capture open-telemetry/semantic-conventions#1760

Another consumer of this data could be openinference (also otel export) which has a stable schema that includes tool .. schema ;) https://github.com/Arize-ai/openinference/blob/076bb7966d44fccdb2ab94e6f379ef4ae22c39b1/spec/semantic_conventions.md?plain=1#L45 cc @mikeldking @axiomofjoy

Introduce instrumentation for tool calling using the Micrometer Observation API.

By default, metadata about tool calling are exported as metrics and traces.
Optionally, the actual tool call input and result can be exported as well by enabling the dedicated feature flag.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
@ThomasVitale ThomasVitale force-pushed the tool-calling-instrumentation branch from eefb811 to 9a39339 Compare May 9, 2025 14:30
@ThomasVitale
Copy link
Contributor Author

ThomasVitale commented May 9, 2025

@codefromthecrypt thanks for reviewing this! The schema captured is part of the ToolDefinition in Spring AI. It's defined consistently across providers, and most of them use JSON Schema. There are exceptions, though. For example, Vertex uses some OpenAPI variant instead of JSON Schema (which SpringAI supports). Some providers might also support a subset of JSON Schema, so having this info part of the telemetry should be useful to troubleshoot those scenarios.

I'm aware that some platforms have defined their own naming for such attributes (and at some point, also OTel SemConv might have something). They can all be supported by customising the ToolCallingObservationConvention. The naming provided here out-of-the-box will be guaranteed by Spring AI to be stable while still allowing the adoption of different sets of conventions (e.g. to support OpenInference).

@codefromthecrypt
Copy link

@ThomasVitale thanks for the code and the commentary. Looking forward to it!

@tzolov
Copy link
Contributor

tzolov commented May 11, 2025

Rebased and merged at 30eb3ce

@tzolov tzolov closed this May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Observability] Add observability support for function calling.
3 participants