public interface Segment
Represents a timed unit of work. Like a TracedMethod
, reports a single metric,
generates a single segment in a transaction trace, and can be reported as an external call. Unlike a TracedMethod,
a Segment's timed duration may encompass arbitrary application work; it is not limited to a single method or thread.
Timing begins when the instance is created via Transaction.startSegment(java.lang.String)
and ends when the end()
or ignore()
method is called. These calls can be issued from distinct application threads. If a Segment is
not explicitly ignored or ended it will be timed out according to the segment_timeout
value which is
user configurable in the yaml file or by a Java system property.
A Segment
will show up in the Transaction Breakdown table, as well as the Transaction Trace page in APM.
Modifier and Type | Method and Description |
---|---|
void |
addOutboundRequestHeaders(OutboundHeaders outboundHeaders)
Adds headers to the external request so that the request can be recognized on the receiving end.
|
void |
end()
Stops timing the
Segment . |
Transaction |
getTransaction()
Get the
Transaction of this Segment . |
void |
ignore()
Stops tracking the
Segment and does not report it as part of its parent transaction. |
void |
reportAsExternal(ExternalParameters externalParameters)
Reports this traced method as an HTTP external call, datastore external call, or generic external call.
|
void |
setMetricName(java.lang.String... metricNameParts)
Sets the metric name by concatenating all given metricNameParts with a '/' separating each part.
|
void setMetricName(java.lang.String... metricNameParts)
metricNameParts
- The segments of the metric name. These values will be concatenated together separated by a
`/` char.void reportAsExternal(ExternalParameters externalParameters)
ExternalParameters
to create the externalParameters argument. If you are performing an external
HTTP call, be sure to call addOutboundRequestHeaders(OutboundHeaders)
prior to the request being sent.externalParameters
- The appropriate input parameters depending on the type of external call. See available
Builders in ExternalParameters
for more information.void addOutboundRequestHeaders(OutboundHeaders outboundHeaders)
outboundHeaders
- The headers that will be written to the output stream for the external request. This also
determines if the external call is HTTP or JMS.Transaction getTransaction()
Transaction
of this Segment
.void ignore()
Segment
and does not report it as part of its parent transaction. This method has no
effect if the segment has ended. Every Segment instance must be completed by a call to ignore() or
to end()
.