Fix support for OpenAI developer messages by JonasKunz · Pull Request #539 · elastic/elastic-otel-java · GitHub
Skip to content

Fix support for OpenAI developer messages#539

Merged
codefromthecrypt merged 5 commits into
elastic:mainfrom
JonasKunz:openai-developer-messages
Feb 12, 2025
Merged

Fix support for OpenAI developer messages#539
codefromthecrypt merged 5 commits into
elastic:mainfrom
JonasKunz:openai-developer-messages

Conversation

@JonasKunz

Copy link
Copy Markdown
Contributor

Closes #532 . For now, these messages will simply be reported as gen_ai.system.message events with role set to developer, which seems to be kind of sem conv compliant. We'll have to revisit later anyway for future semconv changes (e.g. open-telemetry/semantic-conventions#1851), but this at least keeps things working for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This would previously cause the instrumentation to fail, which is a bit too strict.

private static Value<?> buildToolCallEventObject(ChatCompletionMessageToolCall call) {
Map<String, Value<?>> result = new HashMap<>();
result.put("id", Value.of(call.id()));
result.put("type", Value.of(call._type().toString()));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was not detected by muzzle: In some versions inbetween _type() was not present in the openAI lib.

return "json_object";
} else if (val.isResponseFormatJsonSchema()) {
return val.asResponseFormatJsonSchema()._type().toString();
return "json_schema";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For some versions _type() returns null here, so I instead hardcoded the strings for these older versions.

@JonasKunz

Copy link
Copy Markdown
Contributor Author

I'm giving up on muzzle, the checks for 8e050f4 should have failed but did not: In that commit muzzle should have checked against the 0.2.0 version and fail, because DeveloperMessages are not present in that version. I tried debugging why it doesn't work, but eventually gave up because I think it's not worth spending more time here.

For now we should not trust muzzle being green, but rather as a additional safety net which might catch additional problems (or not...)

@JonasKunz JonasKunz marked this pull request as ready for review February 11, 2025 14:22
@JonasKunz JonasKunz requested a review from a team February 11, 2025 14:54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. where the SDK isn't explicit in how these map to json, we make a good guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-java enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for OpenAI "Developer Messages" introduced in openAI java client 0.8

3 participants