You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/agent-api.asciidoc
+6-1
Original file line number
Diff line number
Diff line change
@@ -789,7 +789,11 @@ apm.clearPatches(['timers'])
789
789
790
790
[small]#Added in: v2.17.0#
791
791
792
-
Produces an object containing `trace.id` and either `transaction.id` or `span.id` when a current transaction or span is available.
792
+
// This content is reused in log-correlation.asciidoc
793
+
// Ensure any updates here also make sense there
794
+
// tag::currentTraceIds[]
795
+
796
+
`apm.currentTraceIds` produces an object containing `trace.id` and either `transaction.id` or `span.id` when a current transaction or span is available.
793
797
When no transaction or span is available it will return an empty object.
794
798
This enables log correlation to APM traces with structured loggers.
795
799
@@ -817,3 +821,4 @@ This enables log correlation to APM traces with text-only loggers.
It's important that the agent is started before you require *any* other modules in your Node.js application - i.e. before `http` and before your router etc.
42
35
@@ -64,59 +57,26 @@ The agent will now monitor the performance of your application and record any un
64
57
65
58
[float]
66
59
[[custom-stack-advanced-configuration]]
67
-
==== Advanced configuration
68
-
69
-
In the above example we initialize the agent by calling the <<apm-start,`start()`>> function.
70
-
This function takes an optional options object used to configure the agent.
71
-
Any option not supplied via the options object can instead be configured using environment variables.
72
-
So if you prefer, you can set the same configuration options using environment variables:
73
-
74
-
[source,bash]
75
-
----
76
-
ELASTIC_APM_SERVICE_NAME=<service name>
77
-
ELASTIC_APM_SECRET_TOKEN=<token>
78
-
ELASTIC_APM_SERVER_URL=<server url>
79
-
----
80
-
81
-
And then just start the agent like so:
82
-
83
-
[source,js]
84
-
----
85
-
// Start the agent before any thing else in your app
86
-
var apm = require('elastic-apm-node').start()
87
-
----
60
+
===== Advanced configuration
88
61
89
-
See all possible ways to configure the agent <<configuring-the-agent,in the API documentation>>.
If you use the https://www.npmjs.com/package/connect[connect] module and an error is either thrown synchronously inside one of the middleware functions or is passed as the first argument to the middleware `next()` function,
214
147
it will be passed to the https://www.npmjs.com/package/connect#error-middleware[Connect error handler].
The Node.js agent will keep track of the active HTTP request and will link it to errors and recorded transaction metrics when they are sent to the Elastic APM server.
263
-
This allows you to see details about which request resulted in a particular error or which requests cause a certain HTTP endpoint to be slow.
264
-
265
-
But in many cases,
266
-
information about the HTTP request itself isn't enough.
267
-
To add even more metadata to errors and transactions,
268
-
use one of the functions below:
182
+
==== Add your own data
269
183
270
-
* <<apm-set-user-context,`apm.setUserContext()`>> - Call this to enrich collected performance data and errors with information about the user/client
271
-
* <<apm-set-custom-context,`apm.setCustomContext()`>> - Call this to enrich collected performance data and errors with any information that you think will help you debug performance issues and errors (this data is only stored, but not indexed in Elasticsearch)
272
-
* <<apm-set-label,`apm.setLabel()`>> - Call this to enrich collected performance data and errors with simple key/value strings that you think will help you debug performance issues and errors (labels are indexed in Elasticsearch)
0 commit comments