-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add APIs for manual inter process context propagation
closes #334
- Loading branch information
1 parent
934ae1b
commit 59a45a5
Showing
15 changed files
with
684 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
apm-agent-api/src/main/java/co/elastic/apm/api/ElasticApmJava7.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/*- | ||
* #%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.api; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Map; | ||
|
||
|
||
public class ElasticApmJava7 { | ||
|
||
ElasticApmJava7() { | ||
// do not instantiate | ||
} | ||
|
||
/** | ||
* Use this method to create a custom transaction. | ||
* <p> | ||
* Note that the agent will do this for you automatically when ever your application receives an incoming HTTP request. | ||
* You only need to use this method to create custom transactions. | ||
* </p> | ||
* <p> | ||
* It is important to call {@link Transaction#end()} when the transaction has ended. | ||
* A best practice is to use the transaction in a try-catch-finally block. | ||
* Example: | ||
* </p> | ||
* <pre> | ||
* Transaction transaction = ElasticApm.startTransaction(); | ||
* try { | ||
* transaction.setName("MyController#myAction"); | ||
* transaction.setType(Transaction.TYPE_REQUEST); | ||
* // do your thing... | ||
* } catch (Exception e) { | ||
* transaction.captureException(e); | ||
* throw e; | ||
* } finally { | ||
* transaction.end(); | ||
* } | ||
* </pre> | ||
* <p> | ||
* Note: Transactions created via this method can not be retrieved by calling {@link #currentSpan()} or {@link #currentTransaction()}. | ||
* See {@link Transaction#activate()} on how to achieve that. | ||
* </p> | ||
* | ||
* @return the started transaction. | ||
*/ | ||
@Nonnull | ||
public static Transaction startTransaction() { | ||
Object transaction = doStartTransaction(); | ||
return transaction != null ? new TransactionImpl(transaction) : NoopTransaction.INSTANCE; | ||
} | ||
|
||
private static Object doStartTransaction() { | ||
// co.elastic.apm.api.ElasticApmInstrumentation.StartTransactionInstrumentation.doStartTransaction | ||
return null; | ||
} | ||
|
||
/** | ||
* Similar to {@link #startTransaction()} but creates this transaction as the child of a remote parent. | ||
* | ||
* <p> | ||
* Note: If you are using Java 8 or newer, it is recommended to use {@link ElasticApm#startTransactionWithRemoteParent(java.util.function.Function)} | ||
* </p> | ||
* | ||
* @param headers a map, representing the headers of the incoming request | ||
* @return the started transaction | ||
* @since 1.3.0 | ||
*/ | ||
@Nonnull | ||
public static Transaction startTransactionWithRemoteParent(Map<String, ? extends Iterable<String>> headers) { | ||
Object transaction = doStartTransactionWithRemoteParentMap(headers); | ||
return transaction != null ? new TransactionImpl(transaction) : NoopTransaction.INSTANCE; | ||
} | ||
|
||
private static Object doStartTransactionWithRemoteParentMap(Map<String, ? extends Iterable<String>> headers) { | ||
// co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation.StartTransactionWithRemoteParentInstrumentationMap | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the currently running transaction. | ||
* <p> | ||
* If there is no current transaction, this method will return a noop transaction, | ||
* which means that you never have to check for {@code null} values. | ||
* </p> | ||
* <p> | ||
* NOTE: Transactions created via {@link #startTransaction()} can not be retrieved by calling this method. | ||
* See {@link Transaction#activate()} on how to achieve that. | ||
* </p> | ||
* | ||
* @return The currently running transaction, or a noop transaction (never {@code null}). | ||
*/ | ||
@Nonnull | ||
public static Transaction currentTransaction() { | ||
Object transaction = doGetCurrentTransaction(); | ||
return transaction != null ? new TransactionImpl(transaction) : NoopTransaction.INSTANCE; | ||
} | ||
|
||
private static Object doGetCurrentTransaction() { | ||
// co.elastic.apm.api.ElasticApmInstrumentation.CurrentTransactionInstrumentation.doGetCurrentTransaction | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the currently active span or transaction. | ||
* <p> | ||
* If there is no current span, this method will return a noop span, | ||
* which means that you never have to check for {@code null} values. | ||
* </p> | ||
* <p> | ||
* Note that even if this method is returning a noop span, | ||
* you can still {@link Span#captureException(Throwable) capture exceptions} on it. | ||
* These exceptions will not have a link to a Span or a Transaction. | ||
* </p> | ||
* <p> | ||
* NOTE: Transactions created via {@link Span#createSpan()} can not be retrieved by calling this method. | ||
* See {@link Span#activate()} on how to achieve that. | ||
* </p> | ||
* | ||
* @return The currently active span, or transaction, or a noop span (never {@code null}). | ||
*/ | ||
@Nonnull | ||
public static Span currentSpan() { | ||
Object span = doGetCurrentSpan(); | ||
return span != null ? new SpanImpl(span) : NoopSpan.INSTANCE; | ||
} | ||
|
||
private static Object doGetCurrentSpan() { | ||
// co.elastic.apm.api.ElasticApmInstrumentation.CurrentSpanInstrumentation.doGetCurrentSpan | ||
return null; | ||
} | ||
|
||
/** | ||
* Captures an exception and reports it to the APM server. | ||
* | ||
* @param e the exception to record | ||
* @deprecated use {@link #currentSpan()}.{@link Span#captureException(Throwable) captureException(Throwable)} instead | ||
*/ | ||
@Deprecated | ||
public static void captureException(@Nullable Throwable e) { | ||
// co.elastic.apm.api.ElasticApmInstrumentation.CaptureExceptionInstrumentation.captureException | ||
} | ||
|
||
} |
Oops, something went wrong.