-
Notifications
You must be signed in to change notification settings - Fork 229
Description
This issue is to add a apm.withSpan(options, fn)
API (and similar for withTransaction
) that critically takes a function to which the new RunContext is bound. This would avoid the #2611 footgun that startSpan
and startTransaction
apply. A possible result of that footgun is shown and discussed at #2929.
Adding this API has been considered since the RunContext work.
A good test of this functionality would be whether it could fully or significantly replace the withApmSpan
helper in Kibana (see https://github.com/elastic/kibana/blob/main/x-pack/plugins/apm/server/utils/with_apm_span.ts and https://github.com/elastic/kibana/blob/main/packages/kbn-apm-utils/index.ts).
This apm.withSpan()
would be the equivalent of OTel JS's tracer.startActiveSpan()
. The OTel tracer.startSpan()
is already roughly equivalent to our internal createSpan()
-- which was added in the RunContext work to cope with the apm.startSpan()
footgun.
Eventually I think these APIs should be preferred and startSpan()
and startTransaction()
APIs should be deprecated.