Skip to content

Commit

Permalink
update functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
restrry committed Nov 12, 2021
1 parent 0827a61 commit 641b622
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions x-pack/test/functional_execution_context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
'--logging.loggers[1].name=execution_context',
'--logging.loggers[1].level=debug',
`--logging.loggers[1].appenders=${JSON.stringify(['file'])}`,

'--logging.loggers[2].name=http.server.response',
'--logging.loggers[2].level=all',
`--logging.loggers[2].appenders=${JSON.stringify(['file'])}`,
],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ export class FixturePlugin implements Plugin<void, void, FixtureSetupDeps, Fixtu
},
},
async (ctx, req, res) => {
const transaction = apmAgent.startTransaction();
const subscription = req.events.completed$.subscribe(() => {
transaction?.end();
subscription.unsubscribe();
});

await ctx.core.elasticsearch.client.asInternalUser.ping();

return res.ok({
Expand Down
24 changes: 21 additions & 3 deletions x-pack/test/functional_execution_context/tests/log_correlation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@ export default function ({ getService }: FtrProviderContext) {

expect(response2.body.traceId).not.to.be(response1.body.traceId);

let responseTraceId: string | undefined;
await assertLogContains({
description: 'traceId included in the Kibana logs',
predicate: (record) =>
description: 'traceId included in the http logs',
predicate: (record) => {
// we don't check trace.id value since trace.id in the test plugin and Kibana are different on CI.
// because different 'elastic-apm-node' instaces are imported
Boolean(record.http?.request?.id?.includes('myheader1') && record.trace?.id),
if (
record.log?.logger === 'http.server.response' &&
record.url?.path === '/emit_log_with_trace_id'
) {
responseTraceId = record.trace?.id;
return true;
}
return false;
},
retry,
});

expect(responseTraceId).to.be.a('string');

await assertLogContains({
description: 'elasticsearch logs have the same traceId',
predicate: (record) =>
record.log?.logger === 'elasticsearch.query.data' && record.trace?.id === responseTraceId,
retry,
});
});
Expand Down

0 comments on commit 641b622

Please sign in to comment.