Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate trace.id to http response log manually #118466

Merged
merged 17 commits into from
Nov 24, 2021

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Nov 12, 2021

Summary

Closes #114476
http.server.response logs are emitted when an APM transaction was finished, therefore it contains unrelevant trace.id value.
APM agent is going to extend Hapi lifecycle instrumentation (tentatively in v8.1.0) elastic/apm-agent-nodejs#2353
Until it's resolved in the upstream, we can work it around by storing trace.id for every incoming request.
Kibana logs with this change (a short version for brevity) look like:

{"message":"200\nGET /_security/_authenticate","trace":{"id":"6757659c7a30687eb7f31911612e184a"}}
{"message":"404\nGET /_security/role/logstash_read_user", "trace":{"id":"6757659c7a30687eb7f31911612e184a"}}
{"message":"200\nPUT /_security/role/logstash_read_user\n{\"cluster\":[\"manage_logstash_pipelines\"],\"indices\":[],\"run_as\":[],\"applications\":[]}", "trace":{"id":"6757659c7a30687eb7f31911612e184a"}}
{"path":"/api/security/role/logstash_read_user","query":""},"trace":{"id":"6757659c7a30687eb7f31911612e184a"},"message":"PUT /api/security/role/logstash_read_user 204 95ms"}

Note that the current implementation works for automatic instrumentation. If a plugin creates a custom transaction in a route handler manually, it must provide parents' trace.id to support Distributed Tracing.

const transaction = apmAgent.startTransaction('my-transaction', { childOf: apmAgent.currentTransaction });
// or
const span = apmAgent.startSpan('my-span', { childOf: apmAgent.currentTransaction });

@mshustov mshustov added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v8.1.0 labels Nov 12, 2021
@mshustov mshustov marked this pull request as ready for review November 22, 2021 14:36
@mshustov mshustov requested a review from a team as a code owner November 22, 2021 14:36
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

It's a workaround for now and we'll need to keep checking on the apm issue status.
Core review only,
LGTM

@mshustov mshustov added auto-backport Deprecated - use backport:version if exact versions are needed backport:skip This commit does not require backporting and removed auto-backport Deprecated - use backport:version if exact versions are needed labels Nov 24, 2021
@mshustov mshustov merged commit 755950a into elastic:main Nov 24, 2021
@mshustov mshustov deleted the issue-114476-http-trace-id branch November 24, 2021 08:59
dmlemeshko pushed a commit that referenced this pull request Nov 29, 2021
* store traceId manually during hapi lifecycle

* update functional test

* REMOVE ME

* REMOVE ME

* REMOVE ME

* arghhh

* REMOVE ME

* REMOVE ME

* ARGH

* cleanup

* cleanup 2

* fix test

* add ping check
TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
* store traceId manually during hapi lifecycle

* update functional test

* REMOVE ME

* REMOVE ME

* REMOVE ME

* arghhh

* REMOVE ME

* REMOVE ME

* ARGH

* cleanup

* cleanup 2

* fix test

* add ping check
gbamparop pushed a commit to gbamparop/kibana that referenced this pull request Jan 12, 2022
* store traceId manually during hapi lifecycle

* update functional test

* REMOVE ME

* REMOVE ME

* REMOVE ME

* arghhh

* REMOVE ME

* REMOVE ME

* ARGH

* cleanup

* cleanup 2

* fix test

* add ping check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"http.server.response" logging should include tracing information.
5 participants