From aa61790d6acc3b9ae6714039364615e89b3af5af Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Wed, 31 Oct 2018 18:50:13 +0100 Subject: [PATCH 1/5] Add API methods to enable RUM trace correlation --- .../java/co/elastic/apm/api/NoopSpan.java | 6 ++++++ .../co/elastic/apm/api/NoopTransaction.java | 12 +++++++++++ .../main/java/co/elastic/apm/api/Span.java | 12 +++++++++++ .../java/co/elastic/apm/api/SpanImpl.java | 7 +++++++ .../java/co/elastic/apm/api/Transaction.java | 8 ++++++++ .../co/elastic/apm/api/TransactionImpl.java | 7 +++++++ .../plugin/api/ApiScopeInstrumentation.java | 19 ++++++++++++++++++ .../apm/plugin/api/SpanInstrumentation.java | 15 ++++++++++++++ .../api/TransactionInstrumentation.java | 20 +++++++++++++++++++ ....elastic.apm.bci.ElasticApmInstrumentation | 2 ++ .../api/ElasticApmApiInstrumentationTest.java | 14 +++++++++++++ 11 files changed, 122 insertions(+) diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/NoopSpan.java b/apm-agent-api/src/main/java/co/elastic/apm/api/NoopSpan.java index bfd6c9aaa4..137d21c6c5 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/NoopSpan.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/NoopSpan.java @@ -55,6 +55,12 @@ public String getId() { return ""; } + @Nonnull + @Override + public String getTraceId() { + return ""; + } + @Override public Scope activate() { return NoopScope.INSTANCE; diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java b/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java index 11e9e4fa6b..65a0b49326 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java @@ -61,6 +61,18 @@ public String getId() { return ""; } + @Nonnull + @Override + public String makeChildOfRumTransaction() { + return ""; + } + + @Nonnull + @Override + public String getTraceId() { + return ""; + } + @Override public Scope activate() { return NoopScope.INSTANCE; diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java b/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java index fd7ffb916c..3c38e229ef 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java @@ -132,6 +132,18 @@ public interface Span { @Nonnull String getId(); + /** + * Returns the id of this trace (never {@code null}) + *

+ * If this span represents a noop, + * this method returns an empty string. + *

+ * + * @return the id of this span (never {@code null}) + */ + @Nonnull + String getTraceId(); + /** * Makes this span the active span on the current thread until {@link Scope#close()} has been called. *

diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/SpanImpl.java b/apm-agent-api/src/main/java/co/elastic/apm/api/SpanImpl.java index 7368042b78..b4061a3ded 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/SpanImpl.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/SpanImpl.java @@ -82,6 +82,13 @@ public String getId() { return ""; } + @Nonnull + @Override + public String getTraceId() { + // co.elastic.apm.plugin.api.SpanInstrumentation.GetTraceIdInstrumentation + return ""; + } + @Override public Scope activate() { // co.elastic.apm.plugin.api.SpanInstrumentation.ActivateInstrumentation diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java b/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java index cf6fe8248a..3d78a7d501 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java @@ -117,6 +117,14 @@ public interface Transaction extends Span { @Nonnull String getId(); + /** + * TODO documentation + * + * @return + */ + @Nonnull + String makeChildOfRumTransaction(); + /** * Makes this transaction the active transaction on the current thread until {@link Scope#close()} has been called. *

diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java b/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java index a3f4d70280..e0ecb8ba4c 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java @@ -40,4 +40,11 @@ public void setUser(String id, String email, String username) { // co.elastic.apm.plugin.api.TransactionInstrumentation$SetUserInstrumentation.setUser } + @Nonnull + @Override + public String makeChildOfRumTransaction() { + // co.elastic.apm.plugin.api.TransactionInstrumentation.MakeChildOfRumTransactionInstrumentation + return ""; + } + } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ApiScopeInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ApiScopeInstrumentation.java index 8f059c7a4d..957bc4786a 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ApiScopeInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ApiScopeInstrumentation.java @@ -1,3 +1,22 @@ +/*- + * #%L + * Elastic APM Java agent + * %% + * Copyright (C) 2018 Elastic and contributors + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ package co.elastic.apm.plugin.api; import co.elastic.apm.bci.ElasticApmInstrumentation; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java index 1ce0884d2f..178e901d1b 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java @@ -146,6 +146,21 @@ public static void getId(@Advice.FieldValue(value = "span", typing = Assigner.Ty } } + public static class GetTraceIdInstrumentation extends SpanInstrumentation { + public GetTraceIdInstrumentation() { + super(named("getTraceId").and(takesArguments(0))); + } + + @VisibleForAdvice + @Advice.OnMethodExit + public static void getTraceId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan span, + @Advice.Return(readOnly = false) String traceId) { + if (tracer != null) { + traceId = span.getTraceContext().getTraceId().toString(); + } + } + } + public static class AddTagInstrumentation extends SpanInstrumentation { public AddTagInstrumentation() { super(named("addTag")); diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java index 878629c9a4..0844682a3d 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java @@ -21,6 +21,7 @@ import co.elastic.apm.bci.ElasticApmInstrumentation; import co.elastic.apm.bci.VisibleForAdvice; +import co.elastic.apm.impl.transaction.TraceContext; import co.elastic.apm.impl.transaction.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -77,4 +78,23 @@ public static void setUser(@Advice.FieldValue(value = "span", typing = Assigner. transaction.setUser(id, email, username); } } + + public static class MakeChildOfRumTransactionInstrumentation extends TransactionInstrumentation { + public MakeChildOfRumTransactionInstrumentation() { + super(named("makeChildOfRumTransaction")); + } + + @VisibleForAdvice + @Advice.OnMethodExit + public static void makeChildOfRumTransaction(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Transaction transaction, + @Advice.Return(readOnly = false) String spanId) { + if (tracer != null) { + final TraceContext traceContext = transaction.getTraceContext(); + if (traceContext.getParentId().isEmpty()) { + traceContext.getParentId().setToRandomValue(); + } + spanId = traceContext.getParentId().toString(); + } + } + } } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation index 1762fd996c..2d7d96fef9 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation +++ b/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation @@ -3,12 +3,14 @@ co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CurrentTransactionInstrum co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CurrentSpanInstrumentation co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CaptureExceptionInstrumentation co.elastic.apm.plugin.api.TransactionInstrumentation$SetUserInstrumentation +co.elastic.apm.plugin.api.TransactionInstrumentation$MakeChildOfRumTransactionInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$SetNameInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$SetTypeInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$DoCreateSpanInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$EndInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$CaptureExceptionInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$GetIdInstrumentation +co.elastic.apm.plugin.api.SpanInstrumentation$GetTraceIdInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$AddTagInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$ActivateInstrumentation co.elastic.apm.plugin.api.CaptureExceptionInstrumentation diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java index 482e52f457..61fc52aa78 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java @@ -108,10 +108,13 @@ void testGetId_distributedTracingEnabled() { co.elastic.apm.impl.transaction.Transaction transaction = tracer.startTransaction().withType(Transaction.TYPE_REQUEST); try (Scope scope = transaction.activateInScope()) { assertThat(ElasticApm.currentTransaction().getId()).isEqualTo(transaction.getTraceContext().getId().toString()); + assertThat(ElasticApm.currentTransaction().getTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); assertThat(ElasticApm.currentSpan().getId()).isEqualTo(transaction.getTraceContext().getId().toString()); + assertThat(ElasticApm.currentSpan().getTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); co.elastic.apm.impl.transaction.Span span = transaction.createSpan().withType("db").withName("SELECT"); try (Scope spanScope = span.activateInScope()) { assertThat(ElasticApm.currentSpan().getId()).isEqualTo(span.getTraceContext().getId().toString()); + assertThat(ElasticApm.currentSpan().getTraceId()).isEqualTo(span.getTraceContext().getTraceId().toString()); } finally { span.end(); } @@ -162,4 +165,15 @@ void testScopes() { assertThat(ElasticApm.currentTransaction()).isSameAs(NoopTransaction.INSTANCE); } + + @Test + void testMakeChildOfRumTransaction() { + final Transaction transaction = ElasticApm.startTransaction(); + try (co.elastic.apm.api.Scope scope = transaction.activate()) { + assertThat(tracer.currentTransaction()).isNotNull(); + assertThat(tracer.currentTransaction().getTraceContext().getParentId().isEmpty()).isTrue(); + String rumTransactionId = transaction.makeChildOfRumTransaction(); + assertThat(tracer.currentTransaction().getTraceContext().getParentId().toString()).isEqualTo(rumTransactionId); + } + } } From d88e7ea7a6cf883aa194348b97a2ac66dd441879 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Wed, 31 Oct 2018 18:58:10 +0100 Subject: [PATCH 2/5] Assert idempotency of makeChildOfRumTransaction() --- .../co/elastic/apm/api/ElasticApmApiInstrumentationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java index 61fc52aa78..87005d1cb8 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java @@ -174,6 +174,7 @@ void testMakeChildOfRumTransaction() { assertThat(tracer.currentTransaction().getTraceContext().getParentId().isEmpty()).isTrue(); String rumTransactionId = transaction.makeChildOfRumTransaction(); assertThat(tracer.currentTransaction().getTraceContext().getParentId().toString()).isEqualTo(rumTransactionId); + assertThat(transaction.makeChildOfRumTransaction()).isEqualTo(rumTransactionId); } } } From ea19eafa4d3e68608d119b08004335c5b8111480 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Fri, 2 Nov 2018 14:01:50 +0100 Subject: [PATCH 3/5] Rename makeChildOfRumTransaction to ensureParentId, docs --- .../co/elastic/apm/api/NoopTransaction.java | 2 +- .../main/java/co/elastic/apm/api/Span.java | 4 ++ .../java/co/elastic/apm/api/Transaction.java | 42 +++++++++++++- .../co/elastic/apm/api/TransactionImpl.java | 2 +- .../api/TransactionInstrumentation.java | 2 +- .../api/ElasticApmApiInstrumentationTest.java | 4 +- docs/public-api.asciidoc | 57 +++++++++++++++++++ 7 files changed, 105 insertions(+), 8 deletions(-) diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java b/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java index 65a0b49326..a00eaf9765 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java @@ -63,7 +63,7 @@ public String getId() { @Nonnull @Override - public String makeChildOfRumTransaction() { + public String ensureParentId() { return ""; } diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java b/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java index 3c38e229ef..6a7310507d 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/Span.java @@ -135,6 +135,10 @@ public interface Span { /** * Returns the id of this trace (never {@code null}) *

+ * The trace-ID is consistent across all transactions and spans which belong to the same logical trace, + * even for spans which happened in another service (given this service is also monitored by Elastic APM). + *

+ *

* If this span represents a noop, * this method returns an empty string. *

diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java b/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java index 3d78a7d501..95b8110bb2 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java @@ -118,12 +118,48 @@ public interface Transaction extends Span { String getId(); /** - * TODO documentation + *

+ * If the transaction does not have a parent-ID yet, + * calling this method generates a new ID, + * sets it as the parent-ID of this transaction, + * and returns it as a `String`. + *

+ *

+ * This enables the correlation of the spans the JavaScript Real User Monitoring (RUM) agent creates for the initial page load + * with the transaction of the backend service. + * If your backend service generates the HTML page dynamically, + * initializing the JavaScript RUM agent with the value of this method allows analyzing the time spent in the browser vs in the backend services. + *

+ *

+ * To enable the JavaScript RUM agent when using an HTML templating language like Freemarker, + * add {@code ElasticApm.currentTransaction()} with the key {@code "transaction"} to the model. + *

+ *

+ * Also, add a snippet similar to this to the body of your HTML pages, + * preferably before other JS libraries: + *

+ * + *
{@code
+     * 
+     * 
+     * }
+ * + *

+ * See the JavaScript RUM agent documentation for more information. + *

* - * @return + * @return the parent-ID for this transaction. Updates the transaction to use a new parent-ID if it has previously been unset. */ @Nonnull - String makeChildOfRumTransaction(); + String ensureParentId(); /** * Makes this transaction the active transaction on the current thread until {@link Scope#close()} has been called. diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java b/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java index e0ecb8ba4c..80c38cda6e 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java @@ -42,7 +42,7 @@ public void setUser(String id, String email, String username) { @Nonnull @Override - public String makeChildOfRumTransaction() { + public String ensureParentId() { // co.elastic.apm.plugin.api.TransactionInstrumentation.MakeChildOfRumTransactionInstrumentation return ""; } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java index 0844682a3d..8ba671572c 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java @@ -81,7 +81,7 @@ public static void setUser(@Advice.FieldValue(value = "span", typing = Assigner. public static class MakeChildOfRumTransactionInstrumentation extends TransactionInstrumentation { public MakeChildOfRumTransactionInstrumentation() { - super(named("makeChildOfRumTransaction")); + super(named("ensureParentId")); } @VisibleForAdvice diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java index 87005d1cb8..c7d8ca2795 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java @@ -172,9 +172,9 @@ void testMakeChildOfRumTransaction() { try (co.elastic.apm.api.Scope scope = transaction.activate()) { assertThat(tracer.currentTransaction()).isNotNull(); assertThat(tracer.currentTransaction().getTraceContext().getParentId().isEmpty()).isTrue(); - String rumTransactionId = transaction.makeChildOfRumTransaction(); + String rumTransactionId = transaction.ensureParentId(); assertThat(tracer.currentTransaction().getTraceContext().getParentId().toString()).isEqualTo(rumTransactionId); - assertThat(transaction.makeChildOfRumTransaction()).isEqualTo(rumTransactionId); + assertThat(transaction.ensureParentId()).isEqualTo(rumTransactionId); } } } diff --git a/docs/public-api.asciidoc b/docs/public-api.asciidoc index 3e33c711fc..1efca6ade6 100644 --- a/docs/public-api.asciidoc +++ b/docs/public-api.asciidoc @@ -224,6 +224,52 @@ Returns the id of this transaction (never `null`) If this transaction represents a noop, this method returns an empty string. +[float] +[[api-transaction-get-trace-id]] +==== `String getTraceId()` +Returns the trace-id of this transaction. + +The trace-id is consistent across all transactions and spans which belong to the same logical trace, +even for transactions and spans which happened in another service (given this service is also monitored by Elastic APM). + +If this span represents a noop, +this method returns an empty string. + +[float] +[[api-ensure-parent-id]] +==== `String ensureParentId()` +If the transaction does not have a parent-ID yet, +calling this method generates a new ID, +sets it as the parent-ID of this transaction, +and returns it as a `String`. + +This enables the correlation of the spans the JavaScript Real User Monitoring (RUM) agent creates for the initial page load +with the transaction of the backend service. +If your backend service generates the HTML page dynamically, +initializing the JavaScript RUM agent with the value of this method allows analyzing the time spent in the browser vs in the backend services. + +To enable the JavaScript RUM agent when using an HTML templating language like Freemarker, +add `ElasticApm.currentTransaction()` with the key `"transaction"` to the model. + +Also, add a snippet similar to this to the body of your HTML page, +preferably before other JS libraries: + +[source,html] +---- + + +---- + +See the {apm-rum-ref}[JavaScript RUM agent documentation] for more information. + [float] [[api-transaction-start-span]] ==== `Span createSpan()` @@ -364,6 +410,17 @@ Returns the id of this span (never `null`) If this span represents a noop, this method returns an empty string. +[float] +[[api-span-get-trace-id]] +==== `String getTraceId()` +Returns the trace-ID of this span. + +The trace-ID is consistent across all transactions and spans which belong to the same logical trace, +even for transactions and spans which happened in another service (given this service is also monitored by Elastic APM). + +If this span represents a noop, +this method returns an empty string. + [float] [[api-span-end]] ==== `void end()` From eb417896edb3870d801b6dc83cabfe0bc0af4124 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Mon, 5 Nov 2018 08:06:10 +0100 Subject: [PATCH 4/5] Update based on @eyalkoren's feedback --- .../apm/plugin/api/TransactionInstrumentation.java | 8 ++++---- .../services/co.elastic.apm.bci.ElasticApmInstrumentation | 2 +- .../elastic/apm/api/ElasticApmApiInstrumentationTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java index 8ba671572c..dfe0bb822c 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java @@ -79,15 +79,15 @@ public static void setUser(@Advice.FieldValue(value = "span", typing = Assigner. } } - public static class MakeChildOfRumTransactionInstrumentation extends TransactionInstrumentation { - public MakeChildOfRumTransactionInstrumentation() { + public static class EnsureParentIdInstrumentation extends TransactionInstrumentation { + public EnsureParentIdInstrumentation() { super(named("ensureParentId")); } @VisibleForAdvice @Advice.OnMethodExit - public static void makeChildOfRumTransaction(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Transaction transaction, - @Advice.Return(readOnly = false) String spanId) { + public static void ensureParentId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Transaction transaction, + @Advice.Return(readOnly = false) String spanId) { if (tracer != null) { final TraceContext traceContext = transaction.getTraceContext(); if (traceContext.getParentId().isEmpty()) { diff --git a/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation index 2d7d96fef9..3dd2fec598 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation +++ b/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation @@ -3,7 +3,7 @@ co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CurrentTransactionInstrum co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CurrentSpanInstrumentation co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CaptureExceptionInstrumentation co.elastic.apm.plugin.api.TransactionInstrumentation$SetUserInstrumentation -co.elastic.apm.plugin.api.TransactionInstrumentation$MakeChildOfRumTransactionInstrumentation +co.elastic.apm.plugin.api.TransactionInstrumentation$EnsureParentIdInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$SetNameInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$SetTypeInstrumentation co.elastic.apm.plugin.api.SpanInstrumentation$DoCreateSpanInstrumentation diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java index c7d8ca2795..a5675cdf57 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java @@ -167,7 +167,7 @@ void testScopes() { } @Test - void testMakeChildOfRumTransaction() { + void testEnsureParentId() { final Transaction transaction = ElasticApm.startTransaction(); try (co.elastic.apm.api.Scope scope = transaction.activate()) { assertThat(tracer.currentTransaction()).isNotNull(); From 284f57c91f8aef0bad525995d37b3b64c89bfae6 Mon Sep 17 00:00:00 2001 From: eyalkoren <41850454+eyalkoren@users.noreply.github.com> Date: Mon, 5 Nov 2018 08:51:01 +0100 Subject: [PATCH 5/5] Apply @eyalkoren's suggestion Co-Authored-By: felixbarny --- .../src/main/java/co/elastic/apm/api/TransactionImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java b/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java index 80c38cda6e..cea6c2569e 100644 --- a/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java +++ b/apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java @@ -43,7 +43,7 @@ public void setUser(String id, String email, String username) { @Nonnull @Override public String ensureParentId() { - // co.elastic.apm.plugin.api.TransactionInstrumentation.MakeChildOfRumTransactionInstrumentation + // co.elastic.apm.plugin.api.TransactionInstrumentation.EnsureParentIdInstrumentation return ""; }