-
Notifications
You must be signed in to change notification settings - Fork 159
Description
The Java agent supports creating SpanEvent and SpanLink events via the OpenTelemetry APIs. The following two PRs can provide a reference as to how it's all wired together:
The goal of this issue is to implement our own native Java agent APIs for creating SpanEvent and SpanLink events. This would allow for us to integrate these concepts into our own weave instrumentation modules and it would also provide customers with a way to create these events without any dependency on OpenTelemetry.
Most of the plumbing is already in place from the OTel API support. The OTel Span Events and Span Links are incorporated into New Relic transactions via these methods on the bridge version of the TraceMethod interface, which are implemented on various Tracers (e.g. DefaultTracer):
newrelic-java-agent/agent-bridge/src/main/java/com/newrelic/agent/bridge/TracedMethod.java
Lines 31 to 63 in e21f3e0
| /** | |
| * Add a SpanLink to a collection stored on the traced method. | |
| * <p> | |
| * This is used to support the OpenTelemetry concept of a SpanLink, | |
| * which allows a Span from one trace to link to a Span from | |
| * a different trace, defining a relationship between the traces. | |
| * | |
| * @param link a SpanLink | |
| */ | |
| void addSpanLink(SpanLink link); | |
| /** | |
| * Get a list of SpanLinks associated with this traced method. | |
| * | |
| * @return list of SpanLinks | |
| */ | |
| List<SpanLink> getSpanLinks(); | |
| /** | |
| * Add a SpanEvent to a collection stored on the traced method. | |
| * <p> | |
| * This is used to support the OpenTelemetry concept of a SpanEvent. | |
| * | |
| * @param event a SpanEvent | |
| */ | |
| void addSpanEvent(SpanEvent event); | |
| /** | |
| * Get a list of SpanEvents associated with this traced method. | |
| * | |
| * @return list of SpanEvents | |
| */ | |
| List<SpanEvent> getSpanEvents(); |
The easiest approach, which would allow reuse of the existing code, would be to have our native APIs create events based on our representations of the OTel SpanLink and SpanEvent data models, which then could be directly added to the TraceMethod via the existing interface methods shown above.
At that point, all Span Events and Span Links would be marshaled along on the traced method that eventually gets turned into a Span and there would be no differentiation regardless if they originated from OTel APIs or our native APIs (other than perhaps a few attributes). Eventually they would all be transformed into the New Relic SpanEvent and SpanLink data models before being harvested.
Ultimately, it may prove more desirable to take a different approach that allows our native APIs to directly create the events in the NR data model, rather than converting from one model to another. So that should be explored as part of this work.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status