Skip to content

Added Enhancements to Log Ai Insight#247291

Merged
yuliia-fryshko merged 85 commits into
elastic:mainfrom
yuliia-fryshko:edit-log-insight-system-promt-445
Feb 3, 2026
Merged

Added Enhancements to Log Ai Insight#247291
yuliia-fryshko merged 85 commits into
elastic:mainfrom
yuliia-fryshko:edit-log-insight-system-promt-445

Conversation

@yuliia-fryshko
Copy link
Copy Markdown
Contributor

@yuliia-fryshko yuliia-fryshko commented Dec 22, 2025

Issue #445

This PR enhances the Log AI Insight:

  • We implemented a function to identify the log severity. It takes into account both ECS and OTel fields, since we are working with the raw log entry. We check the severity of the log entry, and we only ask the model to include remediation steps when the log severity is warning or higher.

  • We now always prefetch the ServiceSummary and CorrelatedLogs.

Tested this using the following Cursor prompt prompt_log_ai_insight.md

Here are the results logaiinsightresults.md

It was able to correctly identify errors, and the correlated logs provided enough detail to understand where the error might have occurred.

@yuliia-fryshko yuliia-fryshko self-assigned this Dec 22, 2025
@yuliia-fryshko yuliia-fryshko requested a review from a team as a code owner December 22, 2025 16:26
@yuliia-fryshko yuliia-fryshko added backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ai Observability AI team labels Dec 22, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-ai-team (Team:obs-ai)

You are assisting an SRE who is viewing a log entry in the Kibana Logs UI.
Using the provided data produce a concise, action-oriented response.`);
Using the provided data produce a concise, action-oriented response.
If it's an issue, provide remediation steps suitable for an on-call SRE.`);
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.

The wording here is a bit ambiguous I feel.

If it's an issue doesn't clearly say what an issue is?
Is it referring to an error log or a warning log? What can be considered as an issue in this context?

And do we need to say suitable for an on-call SRE?

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.

If it's an issue - I added it because, in the message, we ask to explain the log and whether "it is an issue". We didn’t specify what qualifies as an issue there. I’m happy to clarify it if you think it’s needed, but the LLM was able to define it nicely on its own.

Regarding suitable for an on-call SRE - I added this because we already mention in the system promt that the audience is an SRE, and I assume that if there is an issue, we want to provide some next steps to investigate. I don’t have a strong opinion on keeping this part or not and am happy to change it.

Copy link
Copy Markdown
Contributor

@viduni94 viduni94 Dec 23, 2025

Choose a reason for hiding this comment

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

I added it because, in the message, we ask to explain the log and whether "it is an issue"

I think that should change as well. We have to avoid ambiguity in system prompt and instructions as much as possible, as different LLMs may interpret it in different ways if it's ambiguous.

@yuliia-fryshko yuliia-fryshko changed the title Added Remediation Steps to Log Ai Insight system promt Added Enhancements to Log Ai Insight Dec 29, 2025
yuliia-fryshko and others added 5 commits December 31, 2025 09:23
…lder/server/routes/ai_insights/get_log_ai_insights.ts

Co-authored-by: Viduni Wickramarachchi <viduni.ushanka@gmail.com>
…lder/server/routes/ai_insights/get_log_ai_insights.ts

Co-authored-by: Viduni Wickramarachchi <viduni.ushanka@gmail.com>
@yuliia-fryshko yuliia-fryshko requested a review from a team as a code owner December 31, 2025 10:52
@botelastic botelastic Bot added the Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation label Dec 31, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-presentation-team (Team:obs-presentation)

@arturoliduena
Copy link
Copy Markdown
Contributor

We are adding more information (ServiceSummary, DownstreamDependencies, TraceDocuments, and TraceServices), which is great. But do we need all of them to explain a log message? also worry about the token count.
Maybe we should add more data depending on the log.level, eg. for info we may not want to query and send to the LLM Trace data.
also there is another that we can use here: get_correlated_logs.

${entityLinkingInstructions}
`)
: dedent(`
You are an expert SRE assistant analyzing an info, debug, or trace log entry. Keep it concise:
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.

Same as above

Comment on lines +185 to +187
<LogContext>
${context}
</LogContext>
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.

Does this cause multiple levels of nesting?

    <LogContext>
    <CorrelatedLogSequence>
        ...
    </CorrelatedLogSequence>
    </LogContext>

If so, remove the LogContext tag

Comment on lines +66 to +92
errorLogsOnly,
errorLogsOnly = DEFAULT_ERROR_LOGS_ONLY,
index,
correlationFields,
correlationFields = DEFAULT_CORRELATION_IDENTIFIER_FIELDS,
logId,
logSourceFields,
maxSequences,
maxLogsPerSequence,
logSourceFields = DEFAULT_LOG_SOURCE_FIELDS,
maxSequences = DEFAULT_MAX_SEQUENCES,
maxLogsPerSequence = DEFAULT_MAX_LOGS_PER_SEQUENCE,
}: {
core: ObservabilityAgentBuilderCoreSetup;
logger: Logger;
esClient: IScopedClusterClient;
start: string;
end: string;
kqlFilter?: string;
errorLogsOnly: boolean;
errorLogsOnly?: boolean;
index?: string;
correlationFields: string[];
correlationFields?: string[];
logId?: string;
logSourceFields: string[];
maxSequences: number;
maxLogsPerSequence: number;
logSourceFields?: string[];
maxSequences?: number;
maxLogsPerSequence?: number;
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 think these should not be optional. Instead of changing this, can you create a function (in this file) that you call, and which just calls getToolHandler?

});

await logsSynthtraceEsClient.index([logs]);
await logsSynthtraceEsClient.refresh();
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.

Is this necessary when we already have refreshAfterIndex?

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.

Thanks, I missed that refreshAfterIndex: true is already configured in the synthtrace client manager.

Comment on lines +81 to +83
errorMessage: ERROR_MESSAGE,
warningMessage: WARNING_MESSAGE,
infoMessage: INFO_MESSAGE,
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.

Where are these used?

logsSynthtraceEsClient,
logData: {
traceId,
serviceName: SERVICE_NAME,
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.

This should be a param to the data generator (decided by the consumer) and thus not returned

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.

... this would also be more consistent with service environment

…lder/server/routes/ai_insights/get_log_ai_insights.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
id,
size: 1,
_source: false,
fields: ['*'],
Copy link
Copy Markdown
Contributor

@sorenlouv sorenlouv Jan 30, 2026

Choose a reason for hiding this comment

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

We shouldn't retrieve all fields - just the fields we need.

`);

const userPrompt = dedent(`
${context}
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.

Did you consider adding context to system prompt instead of user prompt? Pros/cons?

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.

Good question! For me the context is the user's input data to analyze, so userPromt is a right point to add it. Also this part will be available for the chat with agent later as a part of attachments

Copy link
Copy Markdown
Contributor

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

Just a couple of nits

yuliia-fryshko and others added 4 commits February 2, 2026 14:06
…lder/server/routes/ai_insights/get_log_ai_insights.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…lder/server/routes/ai_insights/get_log_ai_insights.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…lder/server/routes/ai_insights/get_log_document_by_id.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Feb 2, 2026

💔 Build Failed

Failed CI Steps

History

cc @yuliia-fryshko

@yuliia-fryshko yuliia-fryshko merged commit 6185ec2 into elastic:main Feb 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ai Observability AI team Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants