You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[gcp_vertexai] Map logs and metrics to ECS gen_ai fields. - #22746
Map GCP Vertex AI prompt response logs, audit logs, and metrics onto the
ECS gen_ai field set so detections can query the provider, model,
operation, token usage, and chat content without reading gcp.vertexai.*
fields. The existing gcp.vertexai.* fields are kept.
The ECS reference moves from git@v8.11.0 to git@v9.5.0 because earlier
versions have no gen_ai field set, and every pipeline now sets
ecs.version 9.5.0.
Prompt response logs and audit logs call a new genai sub-pipeline.
gen_ai.provider.name is gcp.vertex_ai, and gen_ai.operation.name is
generate_content for content-generation methods. Prompt response logs
also populate the request and response model, response id, request
parameters, token usage, finish reasons, system instructions, tool
definitions and calls, and the input and output messages in the
OpenTelemetry message shape. Metrics copy the provider, request model,
token type, and the token count for that row.
Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.
Queue this pull request once it meets the queue conditions
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved pipeline issues corrupt tool payloads and schemas during normalization and cleanup, while unguarded nesting in retained flattened fields can reject entire documents.
This PR adds ECS gen_ai fields to the GCP Vertex AI integration so detections can query logs and metrics through a common schema, addressing #20740 while retaining provider-specific fields.
Changes:
Add GenAI enrichment for prompt-response logs, audit logs, and token metrics.
Map models, operations, token usage, messages, reasoning, and tool data.
Update the ECS reference to 9.5.0 and package version to 1.6.0, with fixtures, samples, and documentation.
File
Description
packages/gcp_vertexai/manifest.yml
Bump package version to 1.6.0.
packages/gcp_vertexai/docs/README.md
Document GenAI mappings and update generated examples.
Request contents without a role are silently dropped from gen_ai.input.messages; default a missing or empty role to user.
Details
Gemini/Vertex Content.role is optional and is commonly omitted for single-turn requests (the API treats it as user). Line 244 passes a null role through unchanged, and line 263 only adds the message when role != null, so a request such as contents: [{parts: [{text: "Hi"}]}] produces no gen_ai.input.messages at all. The prompt text is lost from the ECS field that detections are meant to query. The output side (line 274) already defaults a missing role to assistant, so the two sides are inconsistent.
Recommendation:
Default a missing or empty request role to user, matching the API semantics, so the message is kept.
Suggested change
String role = c.role == 'model' ? 'assistant' : c.role;
gen_ai.response.finish_reasons stores raw Vertex values (STOP) while gen_ai.output.messages uses the normalized ones (stop); store the normalized value in both.
Details
Line 290 maps cand.finish_reason through params.finish_reasons (STOP -> stop, MAX_TOKENS -> length, SAFETY -> content_filter) for gen_ai.output.messages[].finish_reason, but line 291 appends the unmapped value to gen_ai.response.finish_reasons. The same document therefore carries stop in one field and STOP in the other. ECS/OTel define gen_ai.response.finish_reasons with values such as stop and length, so a provider-agnostic query like gen_ai.response.finish_reasons: content_filter misses every Vertex safety block, which defeats the PR's stated goal of letting detections avoid gcp.vertexai.*.
Recommendation:
Append the normalized value (which already falls back to the raw value for unmapped reasons).
gen_ai.request.model has three different shapes across the package's data streams; strip it to the bare model ID after the last /models/.
Details
Audit logs copy the full resource_name (for example projects/<project>/locations/us-central1/publishers/google/models/gemini-2.0-flash-exp, as in the audit fixtures). Prompt response logs copy model (publishers/google/models/gemini-2.5-pro in the new fixture). Metrics copy model_user_id (gemini-1.5-flash-002). ECS defines gen_ai.request.model as the model name (example gpt-4), and gen_ai.response.model in the same prompt document is already the bare gemini-2.5-pro. As a result, a term query or aggregation on gen_ai.request.model cannot correlate audit, prompt, and metric records for the same model, and request and response model never match in a prompt document.
Recommendation:
Keep only the segment after the last /models/ in both log pipelines, which matches the metrics stream. Audit logs (auditlogs/.../genai.yml):
- script:
tag: script_set_gen_ai_request_model_from_resourcelang: painlessif: ctx.gcp?.vertexai?.audit?.resource_name instanceof String && ctx.gcp.vertexai.audit.resource_name.contains('/models/')source: | def r = ctx.gcp.vertexai.audit.resource_name; def m = r.substring(r.lastIndexOf('/models/') + 8); if (!m.isEmpty()) { ctx.gen_ai = ctx.gen_ai ?: new HashMap(); ctx.gen_ai.request = ctx.gen_ai.request ?: new HashMap(); ctx.gen_ai.request.model = m; }
Apply the same script to gcp.vertexai.prompt_response_logs.model in prompt_response_logs/.../genai.yml, falling back to the raw value when it has no /models/ segment.
Also in:packages/gcp_vertexai/data_stream/prompt_response_logs/elasticsearch/ingest_pipeline/genai.yml:28
The genai sub-pipeline runs before the default empty-value drop, so gen_ai.tool.definitions is still pruned; call genai after painless_remove_null.
Details
genai.yml deliberately removes gen_ai.tool.definitions before its own recursive drop (script_drop_empty_values_keep_tool_definitions) and restores it afterward, because empty values in a tool's parameter schema are part of the tool interface. However, default.yml calls the genai pipeline at line 75 and then runs painless_remove_null at line 79, which runs drop(ctx) over the whole document, including gen_ai.tool.definitions. A declaration such as parameters: {type: object, properties: {}} or required: [] therefore still loses those keys. The protection in genai.yml has no effect, and its drop script just repeats the default one.
Recommendation:
Move the sub-pipeline call after the default drop script. genai.yml already drops empty values in the fields it writes:
Tool-call arguments, tool results, and tool parameter schemas inherit the snake_case/lowercase key rewrite; build these gen_ai payloads from unrewritten keys.
Details
The genai sub-pipeline runs after the existing keysToSnakeCase script in default.yml. That script recurses into every map under full_request and full_response and lowercases every key (/_?([a-z])([A-Z]+)/ -> $1_$2, then toLowerCase()). This includes user-defined payloads: function_call.args, function_response.response, and function_declarations[].parameters. A model call with args: {cityName: "Paris"} is stored as arguments: {city_name: "Paris"} in gen_ai.output.messages. JSON-schema keywords in gen_ai.tool.definitions change too (additionalProperties becomes additional_properties, maxItems becomes max_items). The ECS fields therefore do not reflect what the model actually emitted or what the tool declared, which matters for detections that inspect tool-call arguments.
Recommendation:
Stop keysToSnakeCase from rewriting keys inside opaque user payloads, so these maps pass through unchanged:
for (entry in m.entrySet()) {
def k = entry.getKey();
def v = entry.getValue();
boolean opaque = k == 'args' || k == 'response' || k == 'parameters' || k == 'parametersJsonSchema' || k == 'responseJsonSchema';
if (!opaque && v instanceof Map) {
v = keysToSnakeCase(v);
} else if (!opaque && v instanceof List) {
...
}
...
}
Also in:packages/gcp_vertexai/data_stream/prompt_response_logs/elasticsearch/ingest_pipeline/genai.yml:233, packages/gcp_vertexai/data_stream/prompt_response_logs/elasticsearch/ingest_pipeline/genai.yml:253
The flattened depth cap protects only the gen_ai copies; the new raw flattened fields can still reject the same document. Cap the raw fields too.
Details
script_cap_flattened_depth stringifies objects deeper than 20 levels, but only in gen_ai.input.messages, gen_ai.output.messages, gen_ai.system_instructions, and gen_ai.tool.definitions. This PR also declares full_request.tools, contents.parts.function_call, contents.parts.function_response, and candidates.content.parts.function_call as flattened, which have the same default depth_limit of 20. The raw tools value is one object level deeper than gen_ai.tool.definitions (tool -> function_declarations[] -> parameters versus definition -> parameters), so a deep tool schema exceeds the limit on the raw field first and the whole document is rejected even after the cap runs. For definitions the cap can never prevent a rejection.
Recommendation:
Add the raw flattened paths to the cap list, or iterate the list-valued paths. For example, extend params.fields and handle the tools list:
🟢 Reviewed the latest commits 7ea09ab — nothing new beyond already posted comments.
⚠️ 6 comments still unresolved from earlier commits — 5 medium, 1 low
🟡 Request contents without a role are silently dropped from gen_ai.input.messages (link)
🟡 gen_ai.response.finish_reasons stores raw Vertex values (STOP) while gen_ai.output.messages uses the normalized ones (stop) (link)
🟡 gen_ai.request.model has three different shapes across the package's data streams (link)
🟡 The genai sub-pipeline runs before the default empty-value drop, so gen_ai.tool.definitions is still pruned (link)
🟡 Tool-call arguments, tool results, and tool parameter schemas inherit the snake_case/lowercase key rewrite (link)
🔵 The flattened depth cap protects only the gen_ai copies (link)
Review summary
Issues found across earlier commits 9b42539 — 5 medium, 2 low
🟡 Request contents without a role are silently dropped from gen_ai.input.messages (link) (Outdated)
🟡 gen_ai.response.finish_reasons stores raw Vertex values (STOP) while gen_ai.output.messages uses the normalized ones (stop) (link) (Outdated)
🟡 gen_ai.request.model has three different shapes across the package's data streams (link) (Outdated)
🟡 The genai sub-pipeline runs before the default empty-value drop, so gen_ai.tool.definitions is still pruned (link) (Outdated)
🟡 Tool-call arguments, tool results, and tool parameter schemas inherit the snake_case/lowercase key rewrite (link)
🔵 The flattened depth cap protects only the gen_ai copies (link)
Package-level:
🔵 Proposed commit message
gcp_vertexai: map logs and metrics to ECS gen_ai fields
Map GCP Vertex AI prompt response logs, audit logs, and metrics onto the
ECS gen_ai field set so detections can query the provider, model,
operation, token usage, and chat content without reading gcp.vertexai.*
fields. The existing gcp.vertexai.* fields are kept.
The ECS reference moves from git@v8.11.0 to git@v9.5.0 because earlier
versions have no gen_ai field set, and every pipeline now sets
ecs.version 9.5.0.
Prompt response logs and audit logs call a new genai sub-pipeline.
gen_ai.provider.name is gcp.vertex_ai, and gen_ai.operation.name is
generate_content for content-generation methods. Prompt response logs
also populate the request and response model, response id, request
parameters, token usage, finish reasons, system instructions, tool
definitions and calls, and the input and output messages in the
OpenTelemetry message shape. Metrics copy the provider, request model,
token type, and the token count for that row.
Closes #20740
A new commit triggers another review — at most once every 15 minutes. I skip the PR while it's approved or has merge conflicts.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved ingest-pipeline issues discard tool schemas and available call IDs, emit nonstandard tool-result fields, and leave cleanup exceptions and failure diagnostics insufficiently scoped or informative.
When the new genai sub-pipeline fails, the enclosing handler appends only the failure message, making the failing processor harder to identify. Include _ingest.on_failure_processor_type, _ingest.on_failure_processor_tag, and _ingest.on_failure_pipeline alongside the message. Apply the same change to auditlogs/elasticsearch/ingest_pipeline/default.yml:370.
Function declarations using parametersJsonSchema lose their parameter schema in gen_ai.tool.definitions. The preceding pipeline preserves that payload and renames its key to parameters_json_schema, but this projection only copies parameters, leaving detections with a name-only definition. Copy the alternate schema when parameters is absent, and add a fixture for that representation.
Tool response parts use response, but the ECS/OTel message shape uses result (see the ECS example on the default branch: https://github.com/elastic/ecs/blob/153ecde1932d6df36fad68ca18befc6c1756c1f6/schemas/gen_ai.yml#L349-L355). Consumers querying standardized tool results will therefore miss these values. Emit rp.result, exempt result from the subsequent recursive cleanup so null/empty result members are preserved, and update the expected fixture.
If a response mixes named function calls with and without IDs, this check discards every available ID from gen_ai.tool.call.id, hiding identifiers from detections. Retain the available IDs and use the per-part objects in gen_ai.output.messages for name/ID pairing. Update _dev/build/docs/README.md:157 and regenerate docs/README.md to explain that MV_COUNT(gen_ai.tool.call.id) cannot count calls without IDs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Proposed commit message
Map GCP Vertex AI prompt response logs, audit logs, and metrics onto the
ECS gen_ai field set so detections can query the provider, model,
operation, token usage, and chat content without reading gcp.vertexai.*
fields. The existing gcp.vertexai.* fields are kept.
The ECS reference moves from git@v8.11.0 to git@v9.5.0 because earlier
versions have no gen_ai field set, and every pipeline now sets
ecs.version 9.5.0.
Prompt response logs and audit logs call a new genai sub-pipeline.
gen_ai.provider.name is gcp.vertex_ai, and gen_ai.operation.name is
generate_content for content-generation methods. Prompt response logs
also populate the request and response model, response id, request
parameters, token usage, finish reasons, system instructions, tool
definitions and calls, and the input and output messages in the
OpenTelemetry message shape. Metrics copy the provider, request model,
token type, and the token count for that row.
Checklist
changelog.ymlfile.How to test this PR locally
Relates