-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathlog_plugin.spec.js
More file actions
68 lines (53 loc) · 1.6 KB
/
log_plugin.spec.js
File metadata and controls
68 lines (53 loc) · 1.6 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
require('../setup/tap')
const LogPlugin = require('../../src/plugins/log_plugin')
const Tracer = require('../../src/tracer')
const Config = require('../../src/config')
const { channel } = require('../../../diagnostics_channel')
const { expect } = require('chai')
const testLogChannel = channel('apm:test:log')
class TestLog extends LogPlugin {
static get id () {
return 'test'
}
}
const config = {
env: 'my-env',
service: 'my-service',
version: '1.2.3'
}
const tracer = new Tracer(new Config({
logInjection: true,
enabled: true,
...config
}))
const plugin = new TestLog({
_tracer: tracer
})
plugin.configure({
logInjection: true,
enabled: true
})
describe('LogPlugin', () => {
it('always adds service, version, and env', () => {
const data = { message: {} }
testLogChannel.publish(data)
const { message } = data
expect(message.dd).to.deep.equal(config)
// Should not have trace/span data when none is active
expect(message.dd).to.not.have.property('trace_id')
expect(message.dd).to.not.have.property('span_id')
})
it('should include trace_id and span_id when a span is active', () => {
const span = tracer.startSpan('test')
tracer.scope().activate(span, () => {
const data = { message: {} }
testLogChannel.publish(data)
const { message } = data
expect(message.dd).to.contain(config)
// Should have trace/span data when none is active
expect(message.dd).to.have.property('trace_id', span.context().toTraceId())
expect(message.dd).to.have.property('span_id', span.context().toSpanId())
})
})
})