Interface Transaction
-
public interface Transaction
A transaction represents a unit of work in an application. It may be a single web request or a scheduled background task. To indicate that a method is the starting point of a transaction, mark it with aTrace
annotation and setTrace.dispatcher()
to true.- See Also:
Agent.getTransaction()
,Trace.dispatcher()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
acceptDistributedTraceHeaders(TransportType transportType, Headers headers)
Accept the distributed trace headers.void
acceptDistributedTracePayload(DistributedTracePayload payload)
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.void
acceptDistributedTracePayload(java.lang.String payload)
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.void
addOutboundResponseHeaders()
Adds headers to the external response so that the response can be recognized on the receiving end.void
convertToWebTransaction()
Turns the current transaction from a background transaction into a web transaction.DistributedTracePayload
createDistributedTracePayload()
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.TracedMethod
getLastTracer()
Deprecated.usegetTracedMethod()
.java.lang.String
getRequestMetadata()
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.java.lang.String
getResponseMetadata()
Deprecated.Instead, use the Distributed Tracing API.java.lang.Object
getSecurityMetaData()
Returns the associated security related metadata from this Transaction.Token
getToken()
Creates aToken
for linking asynchronous work to the currentTransaction
.TracedMethod
getTracedMethod()
Returns theTracedMethod
enclosing the caller.void
ignore()
Ignore this transaction so that none of its data is reported to the New Relic service.void
ignoreApdex()
Ignore the current transaction for calculating Apdex score.void
ignoreErrors()
Ignore throwable and http status code errors resulting from this transaction.void
insertDistributedTraceHeaders(Headers headers)
Generate distributed trace headers and insert them into theHeaders
.boolean
isTransactionNameSet()
Returns true if the transaction name has been set.boolean
isWebTransaction()
Returns true if in a web transaction.boolean
markResponseSent()
Marks the time when the last byte of the response left the server as the current timestamp.void
processRequestMetadata(java.lang.String requestMetadata)
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.void
processResponseMetadata(java.lang.String responseMetadata)
Deprecated.Instead, use the Distributed Tracing API.void
processResponseMetadata(java.lang.String responseMetadata, java.net.URI uri)
Deprecated.Instead, use the Distributed Tracing API.boolean
setTransactionName(TransactionNamePriority namePriority, boolean override, java.lang.String category, java.lang.String... parts)
Sets the current transaction's name using the given priority.void
setWebRequest(ExtendedRequest request)
Sets the request for the current transaction.void
setWebResponse(Response response)
Sets the response for the current transaction.Segment
startSegment(java.lang.String segmentName)
Starts and returns aSegment
.Segment
startSegment(java.lang.String category, java.lang.String segmentName)
Starts and returns aSegment
.
-
-
-
Method Detail
-
setTransactionName
boolean setTransactionName(TransactionNamePriority namePriority, boolean override, java.lang.String category, java.lang.String... parts)
Sets the current transaction's name using the given priority. Higher priority levels are given precedence, and if the name is set many times with the same priority, the first call wins unless override is true.- Parameters:
namePriority
- The priority of the new transaction name.override
- Overrides the current transaction name if it has the same priority level (or lower).category
- The type of transaction. This is the second segment of the full transaction metric name.parts
- The category and all of the parts are concatenated together with / characters to create the full name.- Returns:
- Returns true if the transaction name was successfully changed, else false.
- Since:
- 3.9.0
-
isTransactionNameSet
boolean isTransactionNameSet()
Returns true if the transaction name has been set. This method is inherently unreliable in the presence of transactions with multiple threads, because another thread may set the transaction name after this method returns but before the caller can act on the return value.- Returns:
- True if the transaction name has already been set, else false.
- Since:
- 3.9.0
-
getLastTracer
@Deprecated TracedMethod getLastTracer()
Deprecated.usegetTracedMethod()
.Returns this transaction's last tracer.- Returns:
- deprecated
- Since:
- 3.9.0
-
getTracedMethod
TracedMethod getTracedMethod()
Returns theTracedMethod
enclosing the caller.- Returns:
- The
TracedMethod
enclosing the caller. The return value isnull
if the caller is not within a transaction. - Since:
- 3.9.0
-
ignore
void ignore()
Ignore this transaction so that none of its data is reported to the New Relic service.- Since:
- 3.9.0
-
ignoreApdex
void ignoreApdex()
Ignore the current transaction for calculating Apdex score.- Since:
- 3.9.0
-
getRequestMetadata
@Deprecated java.lang.String getRequestMetadata()
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.Get transaction metadata to include in an outbound call. Use this method when implementing cross application tracing support for a transport not supported by New Relic, such as a proprietary RPC transport.Server A
String requestMetadata = NewRelic.getAgent().getTransaction().getRequestMetadata();
...send requestMetadata to Server B as part of an outbound call.
- Returns:
- A string representation of the metadata required for linking this transaction to a remote child transaction, or null if no metadata should be sent.
- Since:
- 3.16.1
-
processRequestMetadata
@Deprecated void processRequestMetadata(java.lang.String requestMetadata)
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.Provide the metadata string from a remote transaction's call togetRequestMetadata()
to the current transaction. Use this method when implementing cross application tracing support for a transport not supported by New Relic, such as a proprietary RPC transport.Server B
... get requestMetadata from request.
NewRelic.getAgent().getTransaction().processRequestMetadata(requestMetadata);
- Parameters:
requestMetadata
- metadata string received from an inbound request.- Since:
- 3.16.1
-
getResponseMetadata
@Deprecated java.lang.String getResponseMetadata()
Deprecated.Instead, use the Distributed Tracing API. There is no equivalent of this method in Distributed Tracing.Get transaction metadata to include in an outbound response. Use this method when implementing cross application tracing support for a transport not supported by New Relic, such as a proprietary RPC transport.This call is time sensitive and should be made as close as possible to the code that writes the response.
Server B
String responseMetadata = NewRelic.getAgent().getTransaction.getResponseMetadata();
... send response containing responseMetadata to server A.
- Returns:
- A string representation of the metadata required when responding to a remote transaction's call, or null if no metadata should be sent.
- Since:
- 3.16.1
-
processResponseMetadata
@Deprecated void processResponseMetadata(java.lang.String responseMetadata)
Deprecated.Instead, use the Distributed Tracing API. There is no equivalent of this method in Distributed Tracing.Provide the metadata string from a remote transaction's call togetResponseMetadata()
to the current transaction. This should only be called on the originating transaction when processing response to a remote call. Use this method when implementing cross application tracing support for a transport not supported by New Relic, such as a proprietary RPC transport.Server A
... get response containing responseMetadata from call to server B.
NewRelic.getAgent().getTransaction().processResponseMetadata(responseMetadata); If a URI is available, please use
processResponseMetadata(String, URI)
.- Parameters:
responseMetadata
- metadata string from a remote transaction (generated bygetResponseMetadata()
).- Since:
- 3.16.1
-
processResponseMetadata
@Deprecated void processResponseMetadata(java.lang.String responseMetadata, java.net.URI uri)
Deprecated.Instead, use the Distributed Tracing API. There is no equivalent of this method in Distributed Tracing.Provide the metadata string from a remote transaction's call togetResponseMetadata()
to the current transaction. This should only be called on the originating transaction when processing response to a remote call. Use this method when implementing cross application tracing support for a transport not supported by New Relic, such as a proprietary RPC transport.Server A
... get response containing responseMetadata from call to server B.
NewRelic.getAgent().getTransaction().processResponseMetadata(responseMetadata, uri); Note that the URI parameter should include a valid scheme, host, and port.
- Parameters:
responseMetadata
- metadata string from a remote transaction (generated bygetResponseMetadata()
).uri
- The external URI for the call.- Since:
- 3.36.0
-
setWebRequest
void setWebRequest(ExtendedRequest request)
Sets the request for the current transaction. Setting the request will convert the current transaction into a web transaction. Successive calls will have no effect (first wins). If this method is used, it's important to also usesetWebResponse(com.newrelic.api.agent.Response)
in order to capture information like the response code for this Transaction.- Parameters:
request
- The current transaction's request.- Since:
- 3.36.0
-
setWebResponse
void setWebResponse(Response response)
Sets the response for the current transaction. Setting the response will convert the current transaction into a web transaction. Successive calls will have no effect (first wins). If this method is used, it's important to also usesetWebRequest(com.newrelic.api.agent.ExtendedRequest)
in order to name the Transaction properly.- Parameters:
response
- The current transaction's response.- Since:
- 3.36.0
-
markResponseSent
boolean markResponseSent()
Marks the time when the last byte of the response left the server as the current timestamp. Successive calls will have no effect (first wins).- Returns:
- True if the call to set the response time was successful
- Since:
- 3.36.0
-
isWebTransaction
boolean isWebTransaction()
Returns true if in a web transaction.- Returns:
- true if this is a web transaction, else false.
- Since:
- 3.36.0
-
ignoreErrors
void ignoreErrors()
Ignore throwable and http status code errors resulting from this transaction.- Since:
- 4.12.0
-
convertToWebTransaction
void convertToWebTransaction()
Turns the current transaction from a background transaction into a web transaction.- Since:
- 3.36.0
-
addOutboundResponseHeaders
void addOutboundResponseHeaders()
Adds headers to the external response so that the response can be recognized on the receiving end. Instruct the transaction to write the outbound response headers. This must be called before response headers are sent and the response is committed. Successive calls will have no effect (first wins). This must be called aftersetWebRequest(ExtendedRequest)
andsetWebResponse(Response)
, which together provide the Agent with the inbound request headers and a place to record the outbound headers.- Since:
- 3.36.0
-
getToken
Token getToken()
Creates aToken
for linking asynchronous work to the currentTransaction
. Subsequent calls to getToken() will return a new Token. A singleToken
can be passed between multiple threads of work that should be linked to the transaction. A transaction will remain open until all tokens are expired or timed out. If getToken() is called outside of aTransaction
a NoOpToken will be returned which will always return false when calling a method on theToken
object.- Returns:
- A token to pass to another thread with work for the current transaction.
- Since:
- 3.37.0
-
startSegment
Segment startSegment(java.lang.String segmentName)
Starts and returns aSegment
. ThisSegment
will show up in the Transaction Breakdown table, as well as the Transaction Trace page. ThisSegment
will be reported in the "Custom/" metric category by default. If you want to specify a custom category usestartSegment(String, String)
instead.
-
startSegment
Segment startSegment(java.lang.String category, java.lang.String segmentName)
Starts and returns aSegment
. ThisSegment
will show up in the Transaction Breakdown table, as well as the Transaction Trace page.- Parameters:
category
- Metric category that will be used for this segment. If null or an empty String, the agent will report this Segment under the "Custom/" category.segmentName
- Name of theSegment
segment in APM. This name will show up in the Transaction Breakdown table, as well as the Transaction Trace page. if null or an empty String, the agent will report "Unnamed Segment".- Returns:
- A started
Segment
. - Since:
- 3.37.0
-
createDistributedTracePayload
@Deprecated DistributedTracePayload createDistributedTracePayload()
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.Create a distributed trace payload. ADistributedTracePayload
should be sent from one service to another when you want to follow a trace throughout a distributed system. ADistributedTracePayload
must be created within an active New RelicTransaction
.- Returns:
- a
DistributedTracePayload
- Since:
- 4.3.0
-
acceptDistributedTracePayload
@Deprecated void acceptDistributedTracePayload(java.lang.String payload)
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.Accept a distributed trace payload. Accepting aDistributedTracePayload
sent from one service to another in a distributed system will result in those services being linked together in a trace of the system. ADistributedTracePayload
must be accepted within an active New RelicTransaction
.- Parameters:
payload
- a String representation of theDistributedTracePayload
to accept- Since:
- 4.3.0
-
acceptDistributedTracePayload
@Deprecated void acceptDistributedTracePayload(DistributedTracePayload payload)
Deprecated.Instead, use the Distributed Tracing APIinsertDistributedTraceHeaders(Headers)
to create a distributed tracing payload andacceptDistributedTraceHeaders(TransportType, Headers)
to link the services together.Accept a distributed trace payload. Accepting aDistributedTracePayload
sent from one service to another in a distributed system will result in those services being linked together in a trace of the system.DistributedTracePayload
must be accepted within an active New RelicTransaction
.- Parameters:
payload
- aDistributedTracePayload
instance to accept- Since:
- 4.3.0
-
insertDistributedTraceHeaders
void insertDistributedTraceHeaders(Headers headers)
Generate distributed trace headers and insert them into theHeaders
. The header names inserted will depend on theHeaders.getHeaderType()
.- Parameters:
headers
- The headers to be updated with distributed trace header names and values.- Since:
- 6.5.0
-
acceptDistributedTraceHeaders
void acceptDistributedTraceHeaders(TransportType transportType, Headers headers)
Accept the distributed trace headers. Accepting distributed trace headers sent from one service to another in a distributed system will result in those services being linked together in a trace of the system. Distributed trace payloads must be accept within an active New RelicTransaction
. The header names accepted will depend on theHeaders.getHeaderType()
.- Parameters:
transportType
- The transport type of headers being accepted.headers
- The headers to be accepted.- Since:
- 6.5.0
-
getSecurityMetaData
java.lang.Object getSecurityMetaData()
Returns the associated security related metadata from this Transaction.- Returns:
- securityMetaData object associated with this transaction.
-
-