Skip to content

Commit 6ec35a4

Browse files
added ai insight logger
1 parent a3d535f commit 6ec35a4

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

  • x-pack/solutions/observability/plugins/observability_agent_builder/server

x-pack/solutions/observability/plugins/observability_agent_builder/server/plugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ export class ObservabilityAgentBuilderPlugin
3838
>
3939
{
4040
private readonly logger: Logger;
41+
private readonly aiInsightsLogger: Logger;
4142
private readonly dataRegistry: ObservabilityAgentBuilderDataRegistry;
4243

4344
constructor(initContext: PluginInitializerContext) {
4445
this.logger = initContext.logger.get();
46+
this.aiInsightsLogger = this.logger.get('aiInsights');
4547
this.dataRegistry = new ObservabilityAgentBuilderDataRegistry(this.logger);
4648
}
4749

@@ -72,7 +74,12 @@ export class ObservabilityAgentBuilderPlugin
7274
this.logger.error(`Error registering observability attachments: ${error}`);
7375
});
7476

75-
registerServerRoutes({ core, plugins, logger: this.logger, dataRegistry: this.dataRegistry });
77+
registerServerRoutes({
78+
core,
79+
plugins,
80+
logger: this.aiInsightsLogger,
81+
dataRegistry: this.dataRegistry,
82+
});
7683

7784
if (plugins.searchInferenceEndpoints) {
7885
plugins.searchInferenceEndpoints.features.register(observabilityParentFeature);

x-pack/solutions/observability/plugins/observability_agent_builder/server/routes/ai_insights/route.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ function getRawErrorMessage(error: unknown): string {
4444
}
4545
}
4646

47+
function logAiInsightRouteError({
48+
logger,
49+
routeType,
50+
error,
51+
}: {
52+
logger: Pick<Logger, 'debug' | 'error'>;
53+
routeType: 'alert' | 'error' | 'log';
54+
error: unknown;
55+
}) {
56+
const message = getRawErrorMessage(error);
57+
logger.error(`Failed to generate AI insight for ${routeType} route: ${message}`);
58+
59+
if (error instanceof Error) {
60+
logger.debug(error.stack ?? error.message);
61+
}
62+
}
63+
4764
function aiInsightSseErrorResponse({
4865
response,
4966
message,
@@ -176,7 +193,7 @@ export function getObservabilityAgentBuilderAiInsightsRouteRepository(): ServerR
176193
}),
177194
});
178195
} catch (error) {
179-
logger.error(error);
196+
logAiInsightRouteError({ logger, routeType: 'alert', error });
180197
return routeAiInsightError({
181198
error,
182199
response,
@@ -247,7 +264,7 @@ export function getObservabilityAgentBuilderAiInsightsRouteRepository(): ServerR
247264
}),
248265
});
249266
} catch (error) {
250-
logger.error(error);
267+
logAiInsightRouteError({ logger, routeType: 'error', error });
251268
return routeAiInsightError({
252269
error,
253270
response,
@@ -326,7 +343,7 @@ export function getObservabilityAgentBuilderAiInsightsRouteRepository(): ServerR
326343
}),
327344
});
328345
} catch (error) {
329-
logger.error(error);
346+
logAiInsightRouteError({ logger, routeType: 'log', error });
330347
return routeAiInsightError({
331348
error,
332349
response,

0 commit comments

Comments
 (0)