Skip to content

Commit 8d1afe7

Browse files
keyokejulianocosta89puckpuck
authored
Ensure we handle the scenario the payment service code expects there to be an active span but finds none (open-telemetry#2129)
* Ensure we handle the scenario where there is currently no active span for e.g. open-telemetry#2124 * Mark this new span as active * incorporate review comments * revert var def change --------- Co-authored-by: Juliano Costa <julianocosta89@outlook.com> Co-authored-by: Pierre Tessier <pierre@pierretessier.com>
1 parent 6676676 commit 8d1afe7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/payment/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function chargeServiceHandler(call, callback) {
1313

1414
try {
1515
const amount = call.request.amount
16-
span.setAttributes({
16+
span?.setAttributes({
1717
'app.payment.amount': parseFloat(`${amount.units}.${amount.nanos}`).toFixed(2)
1818
})
1919
logger.info({ request: call.request }, "Charge request received.")
@@ -24,9 +24,8 @@ async function chargeServiceHandler(call, callback) {
2424
} catch (err) {
2525
logger.warn({ err })
2626

27-
span.recordException(err)
28-
span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR })
29-
27+
span?.recordException(err)
28+
span?.setStatus({ code: opentelemetry.SpanStatusCode.ERROR })
3029
callback(err)
3130
}
3231
}

0 commit comments

Comments
 (0)