forked from elastic/apm-agent-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrace-handlebars.js
More file actions
executable file
·28 lines (21 loc) · 1004 Bytes
/
trace-handlebars.js
File metadata and controls
executable file
·28 lines (21 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env node
/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/
// A small example showing Elastic APM tracing the 'handlebars' package.
const apm = require('../').start({ // elastic-apm-node
serviceName: 'example-trace-handlebars'
})
const handlebars = require('handlebars')
// For tracing spans to be created, there must be an active transaction.
// Typically, a transaction is automatically started for incoming HTTP
// requests to a Node.js server. However, because this script is not running
// an HTTP server, we manually start a transaction. More details at:
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
const t1 = apm.startTransaction('t1')
const template = handlebars.compile('Hello, {{name}}!')
console.log(template({ name: 'world' }))
console.log(template({ name: 'Bob' }))
t1.end()