Skip to content

Commit

Permalink
[doc] Align agents logs documentation (elastic#3399)
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge authored and PeterEinberger committed Aug 20, 2024
1 parent 77617f5 commit 33e154b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
8 changes: 1 addition & 7 deletions docs/agent-api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,9 @@ apm.clearPatches(['timers'])

[small]#Added in: v2.17.0#

// This content is reused in log-correlation.asciidoc
// Ensure any updates here also make sense there
// tag::currentTraceIds[]

`apm.currentTraceIds` produces an object containing `trace.id` and either `transaction.id` or `span.id` when a current transaction or span is available.
When no transaction or span is available it will return an empty object.
This enables <<log-correlation,log correlation>> to APM traces with structured loggers.
This enables <<log-correlation-ids,log correlation>> to APM traces with structured loggers.

[source,js]
----
Expand All @@ -884,8 +880,6 @@ This enables <<log-correlation,log correlation>> to APM traces with structured l
}
----

// end::currentTraceIds[]

[[apm-register-custom-metrics]]
==== `apm.registerMetric(name[, labels], callback)`

Expand Down
4 changes: 2 additions & 2 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ include::./api.asciidoc[]

include::./metrics.asciidoc[]

include::./logs.asciidoc[]

include::./api-opentelemetry.asciidoc[]

include::./opentracing.asciidoc[]

include::./log-correlation.asciidoc[]

include::./source-maps.asciidoc[]

include::./distributed-tracing.asciidoc[]
Expand Down
22 changes: 0 additions & 22 deletions docs/log-correlation.asciidoc

This file was deleted.

34 changes: 34 additions & 0 deletions docs/logs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[[logs]]
## Logs

The Elastic APM Node.js Agent provides support for <<log-correlation-ids>>. When
used together with the {ecs-logging-nodejs-ref}/intro.html[`ecs-logging-nodejs`
packages], correlation IDs will be automatically injected into log records to
allow navigation between logs, traces, and services.

This feature is part of {observability-guide}/application-logs.html[Application log ingestion strategies].

[float]
[[log-correlation-ids]]
== Log correlation

{apm-guide-ref}/log-correlation.html[Log correlation] allows you to navigate to all logs belonging to a particular trace
and vice-versa: for a specific log, see in which context it has been logged and which parameters the user provided.

In order to correlate logs from your application with traces captured by the
Elastic APM Node.js Agent, your logs must contain the following identifiers:

* {ecs-ref}/ecs-tracing.html[`trace.id`]
* {ecs-ref}/ecs-tracing.html[`transaction.id`] or {ecs-ref}/ecs-tracing.html[`span.id`]

The APM Node.js Agent provides the <<apm-current-trace-ids>> API for this.
If your application is also using one of the {ecs-logging-nodejs-ref}/intro.html[ECS formatting plugin packages]
(available for Pino, Winston, and Morgan), then this APM Agent API will
automatically be used to inject the appropriate tracing fields into your log
records. Otherwise, configure your logger to add these fields when emitting a
log record.

When your logs contain the appropriate identifiers, the final step is to ingest them into the same
Elasticsearch instance that contains your APM data. See
{apm-guide-ref}/log-correlation.html#ingest-logs-in-es[Ingest your logs into Elasticsearch]
for more information.
5 changes: 5 additions & 0 deletions docs/redirects.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ This page has moved.

- For details on ES Modules (ESM) support, see <<compatibility-esm>>.
- For information on using the APM agent with TypeScript, see <<typescript>>.

[role="exclude",id="log-correlation"]
=== Log correlation

This section has moved. See <<logs>>.

0 comments on commit 33e154b

Please sign in to comment.