Interface Segment
-
- All Superinterfaces:
AttributeHolder
public interface Segment extends AttributeHolder
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 theend()
orignore()
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 thesegment_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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method 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 theSegment
and complete the execution on this thread.void
endAsync()
Stops timing theSegment
and complete the execution on another thread.Transaction
getTransaction()
Get theTransaction
of thisSegment
.void
ignore()
Stops tracking theSegment
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.-
Methods inherited from interface com.newrelic.api.agent.AttributeHolder
addCustomAttribute, addCustomAttribute, addCustomAttribute, addCustomAttributes
-
-
-
-
Method Detail
-
setMetricName
void setMetricName(java.lang.String... metricNameParts)
Sets the metric name by concatenating all given metricNameParts with a '/' separating each part.- Parameters:
metricNameParts
- The segments of the metric name. These values will be concatenated together separated by a `/` char.- Since:
- 3.37.0
-
reportAsExternal
void reportAsExternal(ExternalParameters externalParameters)
Reports this traced method as an HTTP external call, datastore external call, or generic external call. UseExternalParameters
to create the externalParameters argument. If you are performing an external HTTP call, be sure to calladdOutboundRequestHeaders(OutboundHeaders)
prior to the request being sent.- Parameters:
externalParameters
- The appropriate input parameters depending on the type of external call. See available Builders inExternalParameters
for more information.- Since:
- 3.37.0
-
addOutboundRequestHeaders
void addOutboundRequestHeaders(OutboundHeaders outboundHeaders)
Adds headers to the external request so that the request can be recognized on the receiving end. To be called when performing an outbound external request using HTTP or JMS. This method must be called before any headers are written to the output stream. This method is generally used in conjunction with reportAsExternal.- Parameters:
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.- Since:
- 3.37.0
-
getTransaction
Transaction getTransaction()
Get theTransaction
of thisSegment
.- Returns:
- The Transaction.
- Since:
- 3.37.0
-
ignore
void ignore()
Stops tracking theSegment
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 toend()
.- Since:
- 3.37.0
-
end
void end()
Stops timing theSegment
and complete the execution on this thread. Only the first call to this method will have an effect. Every Segment instance must be completed by a call toignore()
or to end()/endAsync().- Since:
- 3.37.0
-
endAsync
void endAsync()
Stops timing theSegment
and complete the execution on another thread. This method is preferred overend()
when the underlying segment is running on a single threaded event loop. Only the first call to this method will have an effect. Every Segment instance must be completed by a call toignore()
or to end()/endAsync().- Since:
- 5.4.0
-
-