Skip to content

add withSpan and withTransaction API #2983

@trentm

Description

@trentm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions