elastic / elastic/apm-agent-nodejs

Expose `Transaction.prototype.setParentSpan` as public API

Open
#2,935 0 comments 0 reactions 1 assignee Claimed by @david-luna View on GitHub
agent-nodejs community triage
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**

The application we are trying to instrument is sending a command through AWS SQS when an HTTP endpoint is hit. The command will then got picked up by a lambda handler.

We are following [Message queue guide](https://www.elastic.co/guide/en/apm/agent/nodejs/current/message-queues.html) for sending the traceparent over to the SQS handler. The handler will attach the trace parent to the handler lifecycle and report to APM with the transaction created from the HTTP endpoint.

However, we also got auto instrumentation enabled. So when our lambda handler runs, there is already a transaction created by apm agent with a generated transaction ID.

I want a way to set my trace parent for a given transaction.

**Describe the solution you'd like**

The `GenericSpan` type (inherited by `Transaction` and `Span`) already got `setParentSpan`function in it. If this API is exposed, I can then solve the problem and correlate transactions correctly.

**Describe alternatives you've considered**

I tried to create a new transaction and attaching the trace parent I want to use. But that breaks kibana and report no child span inside the transaction. Kibana seems picking up the transaction generated by auto instrumentation.

I could disable auto instrumentation but that would be too much work from our end.

**Additional context**

I am opening this issue from the comment of https://github.com/elastic/apm-agent-nodejs/issues/2885#issuecomment-1222628181.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.