File tree Expand file tree Collapse file tree 5 files changed +57
-3
lines changed Expand file tree Collapse file tree 5 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -410,3 +410,33 @@ This is useful on scenarios where the APM server is behind a reverse proxy that
410
410
411
411
NOTE: If APM Server is deployed in an origin different than the page’s origin, you will need to
412
412
<<configuring-cors, configure Cross-Origin Resource Sharing (CORS)>>.
413
+
414
+
415
+ [function]
416
+ [[transaction-context-callback]]
417
+ ==== `transactionContextCallback`
418
+
419
+ * *Type:* Function
420
+ * *Default:* `null`
421
+
422
+ `transactionContextCallback` allows the agent to specify a function to be called when starting automatically instrumented transactions and spans and return
423
+ context to be set as tags. This enables the agent to capture the context when instrumented events are fired from files which do not import the RUM agent library.
424
+
425
+ The following example illustrates an example which captures the stack trace:
426
+
427
+ [source,js]
428
+ ----
429
+ var options = {
430
+ transactionContextCallback: () => {
431
+ let stack
432
+ try {
433
+ throw new Error('')
434
+ }
435
+ catch (error) {
436
+ stack = (error as Error).stack || ''
437
+ }
438
+ stack = stack.split('\n').map(function (line) { return line.trim(); })
439
+ return { stack };
440
+ }
441
+ }
442
+ ----
Original file line number Diff line number Diff line change @@ -94,7 +94,8 @@ class Config {
94
94
context : { } ,
95
95
session : false ,
96
96
apmRequest : null ,
97
- sendCredentials : false
97
+ sendCredentials : false ,
98
+ transactionContextCallback : null
98
99
}
99
100
100
101
this . events = new EventHandler ( )
Original file line number Diff line number Diff line change @@ -101,7 +101,15 @@ class TransactionService {
101
101
102
102
createOptions ( options ) {
103
103
const config = this . _config . config
104
- let presetOptions = { transactionSampleRate : config . transactionSampleRate }
104
+ let presetOptions = {
105
+ transactionSampleRate : config . transactionSampleRate
106
+ }
107
+ if ( config . transactionContextCallback ) {
108
+ presetOptions = {
109
+ ...presetOptions ,
110
+ transactionContextCallback : config . transactionContextCallback
111
+ }
112
+ }
105
113
let perfOptions = extend ( presetOptions , options )
106
114
if ( perfOptions . managed ) {
107
115
perfOptions = extend (
@@ -483,6 +491,13 @@ class TransactionService {
483
491
)
484
492
}
485
493
494
+ if ( this . _config . config . transactionContextCallback ) {
495
+ options = {
496
+ ...options ,
497
+ tags : this . _config . config . transactionContextCallback ( )
498
+ }
499
+ }
500
+
486
501
const span = tr . startSpan ( name , type , options )
487
502
if ( __DEV__ ) {
488
503
this . _logger . debug (
Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ class Transaction extends SpanBase {
54
54
55
55
this . sampleRate = this . options . transactionSampleRate
56
56
this . sampled = Math . random ( ) <= this . sampleRate
57
+
58
+ if ( this . options . transactionContextCallback ) {
59
+ this . options = {
60
+ ...this . options ,
61
+ tags : this . options . transactionContextCallback ( )
62
+ }
63
+ }
57
64
}
58
65
59
66
addMarks ( obj ) {
Original file line number Diff line number Diff line change @@ -107,7 +107,8 @@ declare module '@elastic/apm-rum' {
107
107
method : string
108
108
payload ?: string
109
109
headers ?: Record < string , string >
110
- } ) => boolean
110
+ } ) => boolean ,
111
+ transactionContextCallback ?: ( ...args : any [ ] ) => any
111
112
}
112
113
113
114
type Init = ( options ?: AgentConfigOptions ) => ApmBase
You can’t perform that action at this time.
0 commit comments