Skip to content

Commit 67d8419

Browse files
committed
fix(spans): report in case of missing spans too
1 parent 32d6d64 commit 67d8419

4 files changed

Lines changed: 93 additions & 6 deletions

File tree

lib/agent/api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ CollectorApi.prototype.sendSamples = function (samples, sync) {
146146
version: '2',
147147
instance: this._withInstanceInfo({}),
148148
service: {
149-
key: this.serviceKey,
149+
key: this.serviceKey ? this.serviceKey : undefined,
150150
name: this.serviceName
151151
}
152152
}

lib/agent/api/index.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ describe('The Trace CollectorApi module', function () {
9999
pid: defaultConfig.system.processId
100100
},
101101
service: {
102-
name: defaultConfig.serviceName,
103-
key: null
102+
name: defaultConfig.serviceName
104103
}
105104
}, data))
106105
return JSON.stringify(data)

lib/agent/index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,30 @@ Agent.prototype.clientReceive = function (data) {
233233
Agent.prototype.onCrash = function (data) {
234234
var span = this.findSpan(this.getRequestId())
235235
var parentCommId = this.getParentCommId()
236+
var crashWithoutSpan
236237

237238
if (!span) {
238-
return
239+
// we have a crash which does not belong to an open transaction
240+
// creating one
241+
crashWithoutSpan = true
242+
parentCommId = this.generateCommId()
243+
244+
span = this.openSpan(this.generateRequestId())
245+
span.events.push({
246+
type: Agent.SERVER_RECV,
247+
time: this.getMicrotime(),
248+
data: {
249+
method: 'ERROR',
250+
endpoint: 'stacktrace',
251+
rpcId: parentCommId
252+
}
253+
})
239254
}
240255

241256
span.isForceSampled = true
242257

243258
span.events.push({
244-
time: microtime.now(),
259+
time: this.getMicrotime(),
245260
type: Agent.ERROR,
246261
data: {
247262
rpcId: parentCommId,
@@ -253,6 +268,18 @@ Agent.prototype.onCrash = function (data) {
253268
}
254269
})
255270

271+
if (crashWithoutSpan) {
272+
// faking the server send event
273+
span.events.push({
274+
time: microtime.now(),
275+
type: Agent.SERVER_SEND,
276+
data: {
277+
rpcId: parentCommId,
278+
statusCode: 500
279+
}
280+
})
281+
}
282+
256283
this.reservoirSampler.addReturnsSuccess(span)
257284

258285
this._send({

lib/agent/index.spec.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,68 @@ describe('The Trace agent', function () {
9696
})
9797
})
9898

99-
it('does server receive when there is no parentServiceId', function () {
99+
it('reports crashes', function () {
100+
var sendStub = this.sandbox.stub(agent, '_send', function () {})
101+
var error = new Error('error')
102+
error.stack = 'stacktrace'
103+
this.sandbox.stub(agent, 'getMicrotime', function () {
104+
return time
105+
})
106+
this.sandbox.stub(agent, 'generateRequestId', function () {
107+
return requestId
108+
})
109+
this.sandbox.stub(agent, 'generateCommId', function () {
110+
return parentCommId
111+
})
112+
113+
agent.onCrash({
114+
stackTrace: error
115+
})
116+
117+
expect(agent.reservoirSampler.getItems()).to.eql([
118+
{
119+
requestId: requestId,
120+
isSampled: false,
121+
isForceSampled: true,
122+
events: [
123+
{
124+
type: 'sr',
125+
time: time,
126+
data: {
127+
endpoint: 'stacktrace',
128+
method: 'ERROR',
129+
rpcId: parentCommId
130+
}
131+
},
132+
{
133+
type: 'err',
134+
time: time,
135+
data: {
136+
rpcId: parentCommId,
137+
type: 'system-error',
138+
message: error.message,
139+
raw: {
140+
stack: error.stack
141+
}
142+
}
143+
},
144+
{
145+
type: 'ss',
146+
time: time,
147+
data: {
148+
rpcId: parentCommId,
149+
statusCode: 500
150+
}
151+
}
152+
]
153+
}
154+
])
155+
expect(sendStub).to.be.calledWith({
156+
isSync: true
157+
})
158+
})
159+
160+
it('does server receive when there is no parentId', function () {
100161
agent.serverReceive({
101162
requestId: requestId,
102163
parentCommId: parentCommId,

0 commit comments

Comments
 (0)