Package io.sentry

Class SentryTracer

java.lang.Object
io.sentry.SentryTracer
All Implemented Interfaces:
ISpan, ITransaction

@Internal public final class SentryTracer extends Object implements ITransaction
  • Constructor Details

  • Method Details

    • scheduleFinish

      public void scheduleFinish()
      Description copied from interface: ITransaction
      Schedules when transaction should be automatically finished.
      Specified by:
      scheduleFinish in interface ITransaction
    • forceFinish

      @NotNull public void forceFinish(@NotNull @NotNull SpanStatus status, boolean dropIfNoChildren, @Nullable @Nullable Hint hint)
      Description copied from interface: ITransaction
      Force finishes the transaction and it's child spans with the specified status. If the transaction is already finished this is a no-op.
      Specified by:
      forceFinish in interface ITransaction
      Parameters:
      status - The status to set the unfinished child spans / transaction to.
      dropIfNoChildren - true, if the transaction should be dropped when it e.g. contains no child spans. Usually true, but can be set to falseS for situations were the transaction and profile provide crucial context (e.g. ANRs)
      hint - An optional hint to pass down to the client/transport layer
    • finish

      public void finish(@Nullable @Nullable SpanStatus status, @Nullable @Nullable SentryDate finishDate, boolean dropIfNoChildren, @Nullable @Nullable Hint hint)
      Specified by:
      finish in interface ITransaction
    • getChildren

      @NotNull public @NotNull List<Span> getChildren()
    • getStartDate

      @NotNull public @NotNull SentryDate getStartDate()
      Description copied from interface: ISpan
      Returns the start date of this span or transaction.
      Specified by:
      getStartDate in interface ISpan
      Returns:
      the start date
    • getFinishDate

      @Nullable public @Nullable SentryDate getFinishDate()
      Description copied from interface: ISpan
      Returns the end date of this span or transaction.
      Specified by:
      getFinishDate in interface ISpan
      Returns:
      the end date
    • startChild

      @NotNull public @NotNull ISpan startChild(@NotNull @NotNull String operation)
      Description copied from interface: ISpan
      Starts a child Span.
      Specified by:
      startChild in interface ISpan
      Parameters:
      operation - - new span operation name
      Returns:
      a new transaction span
    • startChild

      @NotNull public @NotNull ISpan startChild(@NotNull @NotNull String operation, @Nullable @Nullable String description, @Nullable @Nullable SentryDate timestamp, @NotNull @NotNull Instrumenter instrumenter)
      Specified by:
      startChild in interface ISpan
    • startChild

      @NotNull public @NotNull ISpan startChild(@NotNull @NotNull String operation, @Nullable @Nullable String description, @Nullable @Nullable SentryDate timestamp, @NotNull @NotNull Instrumenter instrumenter, @NotNull @NotNull SpanOptions spanOptions)
      Specified by:
      startChild in interface ISpan
    • startChild

      @NotNull public @NotNull ISpan startChild(@NotNull @NotNull String operation, @Nullable @Nullable String description, @Nullable @Nullable SentryDate timestamp)
      Description copied from interface: ITransaction
      Starts a child Span.
      Specified by:
      startChild in interface ITransaction
      Parameters:
      operation - - new span operation name
      description - - the span description
      timestamp - - the start timestamp of the span
      Returns:
      a new transaction span
    • startChild

      @NotNull public @NotNull ISpan startChild(@NotNull @NotNull String operation, @Nullable @Nullable String description)
      Description copied from interface: ISpan
      Starts a child Span.
      Specified by:
      startChild in interface ISpan
      Parameters:
      operation - - new span operation name
      description - - new span description name
      Returns:
      a new transaction span
    • startChild

      @NotNull public @NotNull ISpan startChild(@NotNull @NotNull String operation, @Nullable @Nullable String description, @NotNull @NotNull SpanOptions spanOptions)
      Specified by:
      startChild in interface ISpan
    • toSentryTrace

      @NotNull public @NotNull SentryTraceHeader toSentryTrace()
      Description copied from interface: ISpan
      Returns the trace information that could be sent as a sentry-trace header.
      Specified by:
      toSentryTrace in interface ISpan
      Returns:
      SentryTraceHeader.
    • finish

      public void finish()
      Description copied from interface: ISpan
      Sets span timestamp marking this span as finished.
      Specified by:
      finish in interface ISpan
    • finish

      public void finish(@Nullable @Nullable SpanStatus status)
      Description copied from interface: ISpan
      Sets span timestamp marking this span as finished.
      Specified by:
      finish in interface ISpan
      Parameters:
      status - - the status
    • finish

      @Internal public void finish(@Nullable @Nullable SpanStatus status, @Nullable @Nullable SentryDate finishDate)
      Description copied from interface: ISpan
      Sets span timestamp marking this span as finished.
      Specified by:
      finish in interface ISpan
      Parameters:
      status - - the status
      finishDate - - the end timestamp
    • traceContext

      @Nullable public @Nullable TraceContext traceContext()
      Description copied from interface: ISpan
      Returns the trace context.
      Specified by:
      traceContext in interface ISpan
      Returns:
      a trace context or null if SentryOptions.isTraceSampling() is disabled.
    • toBaggageHeader

      @Nullable public @Nullable BaggageHeader toBaggageHeader(@Nullable @Nullable List<String> thirdPartyBaggageHeaders)
      Description copied from interface: ISpan
      Returns the baggage that can be sent as "baggage" header.
      Specified by:
      toBaggageHeader in interface ISpan
      Returns:
      BaggageHeader or null if SentryOptions.isTraceSampling() is disabled.
    • setOperation

      public void setOperation(@NotNull @NotNull String operation)
      Description copied from interface: ISpan
      Sets span operation.
      Specified by:
      setOperation in interface ISpan
      Parameters:
      operation - - the operation
    • getOperation

      @NotNull public @NotNull String getOperation()
      Description copied from interface: ISpan
      Returns the span operation.
      Specified by:
      getOperation in interface ISpan
      Returns:
      the operation
    • setDescription

      public void setDescription(@Nullable @Nullable String description)
      Description copied from interface: ISpan
      Sets span description.
      Specified by:
      setDescription in interface ISpan
      Parameters:
      description - - the description.
    • getDescription

      @Nullable public @Nullable String getDescription()
      Description copied from interface: ISpan
      Returns the span description.
      Specified by:
      getDescription in interface ISpan
      Returns:
      the description
    • setStatus

      public void setStatus(@Nullable @Nullable SpanStatus status)
      Description copied from interface: ISpan
      Sets span status.
      Specified by:
      setStatus in interface ISpan
      Parameters:
      status - - the status.
    • getStatus

      @Nullable public @Nullable SpanStatus getStatus()
      Description copied from interface: ISpan
      Returns the span status
      Specified by:
      getStatus in interface ISpan
      Returns:
      the status
    • setThrowable

      public void setThrowable(@Nullable @Nullable Throwable throwable)
      Description copied from interface: ISpan
      Sets the throwable that was thrown during the execution of the span.
      Specified by:
      setThrowable in interface ISpan
      Parameters:
      throwable - - the throwable.
    • getThrowable

      @Nullable public @Nullable Throwable getThrowable()
      Description copied from interface: ISpan
      Gets the throwable that was thrown during the execution of the span.
      Specified by:
      getThrowable in interface ISpan
      Returns:
      throwable or null if none
    • getSpanContext

      @NotNull public @NotNull SpanContext getSpanContext()
      Description copied from interface: ISpan
      Gets the span context.
      Specified by:
      getSpanContext in interface ISpan
      Returns:
      the span context
    • setTag

      public void setTag(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Description copied from interface: ISpan
      Sets the tag on span or transaction.
      Specified by:
      setTag in interface ISpan
      Parameters:
      key - the tag key
      value - the tag value
    • getTag

      @Nullable public @Nullable String getTag(@NotNull @NotNull String key)
      Specified by:
      getTag in interface ISpan
    • isFinished

      public boolean isFinished()
      Description copied from interface: ISpan
      Returns if span has finished.
      Specified by:
      isFinished in interface ISpan
      Returns:
      if span has finished.
    • setData

      public void setData(@NotNull @NotNull String key, @NotNull @NotNull Object value)
      Description copied from interface: ISpan
      Sets extra data on span or transaction.
      Specified by:
      setData in interface ISpan
      Parameters:
      key - the data key
      value - the data value
    • getData

      @Nullable public @Nullable Object getData(@NotNull @NotNull String key)
      Description copied from interface: ISpan
      Returns extra data from span or transaction.
      Specified by:
      getData in interface ISpan
      Returns:
      the data
    • setMeasurementFromChild

      @Internal public void setMeasurementFromChild(@NotNull @NotNull String name, @NotNull @NotNull Number value)
    • setMeasurementFromChild

      @Internal public void setMeasurementFromChild(@NotNull @NotNull String name, @NotNull @NotNull Number value, @NotNull @NotNull MeasurementUnit unit)
    • setMeasurement

      public void setMeasurement(@NotNull @NotNull String name, @NotNull @NotNull Number value)
      Description copied from interface: ISpan
      Set a measurement without unit. When setting the measurement without the unit, no formatting will be applied to the measurement value in the Sentry product, and the value will be shown as is.

      NOTE: Setting a measurement with the same name on the same transaction multiple times only keeps the last value.

      Specified by:
      setMeasurement in interface ISpan
      Parameters:
      name - the name of the measurement
      value - the value of the measurement
    • setMeasurement

      public void setMeasurement(@NotNull @NotNull String name, @NotNull @NotNull Number value, @NotNull @NotNull MeasurementUnit unit)
      Description copied from interface: ISpan
      Set a measurement with specific unit.

      NOTE: Setting a measurement with the same name on the same transaction multiple times only keeps the last value.

      Specified by:
      setMeasurement in interface ISpan
      Parameters:
      name - the name of the measurement
      value - the value of the measurement
      unit - the unit the value is measured in
    • getData

      @Nullable public @Nullable Map<String,Object> getData()
    • isSampled

      @Nullable public @Nullable Boolean isSampled()
      Description copied from interface: ITransaction
      Returns if transaction is sampled.
      Specified by:
      isSampled in interface ITransaction
      Returns:
      is sampled
    • isProfileSampled

      @Nullable public @Nullable Boolean isProfileSampled()
      Description copied from interface: ITransaction
      Returns if the profile of a transaction is sampled.
      Specified by:
      isProfileSampled in interface ITransaction
      Returns:
      profile is sampled
    • getSamplingDecision

      @Nullable public @Nullable TracesSamplingDecision getSamplingDecision()
      Specified by:
      getSamplingDecision in interface ITransaction
    • setName

      public void setName(@NotNull @NotNull String name)
      Description copied from interface: ITransaction
      Sets transaction name.
      Specified by:
      setName in interface ITransaction
      Parameters:
      name - - transaction name
    • setName

      @Internal public void setName(@NotNull @NotNull String name, @NotNull @NotNull TransactionNameSource transactionNameSource)
      Specified by:
      setName in interface ITransaction
    • getName

      @NotNull public @NotNull String getName()
      Description copied from interface: ITransaction
      Returns transaction name.
      Specified by:
      getName in interface ITransaction
      Returns:
      transaction name
    • getTransactionNameSource

      @NotNull public @NotNull TransactionNameSource getTransactionNameSource()
      Description copied from interface: ITransaction
      Returns the source of the transaction name.
      Specified by:
      getTransactionNameSource in interface ITransaction
      Returns:
      transaction name source
    • getSpans

      @NotNull public @NotNull List<Span> getSpans()
      Specified by:
      getSpans in interface ITransaction
    • getLatestActiveSpan

      @Nullable public @Nullable Span getLatestActiveSpan()
      Description copied from interface: ITransaction
      Returns the latest span that is not finished.
      Specified by:
      getLatestActiveSpan in interface ITransaction
      Returns:
      span or null if not found.
    • getEventId

      @NotNull public @NotNull SentryId getEventId()
      Description copied from interface: ITransaction
      Returns transaction's event id.
      Specified by:
      getEventId in interface ITransaction
      Returns:
      the event id
    • setContext

      @Internal public void setContext(@NotNull @NotNull String key, @NotNull @NotNull Object context)
      Specified by:
      setContext in interface ITransaction
    • getContexts

      @Internal @NotNull public @NotNull Contexts getContexts()
      Specified by:
      getContexts in interface ITransaction
    • updateEndDate

      public boolean updateEndDate(@NotNull @NotNull SentryDate date)
      Description copied from interface: ISpan
      Updates the end date of the span. Note: This will only update the end date if the span is already finished.
      Specified by:
      updateEndDate in interface ISpan
      Parameters:
      date - the end date to set
      Returns:
      true if the end date was updated, false otherwise
    • isNoOp

      public boolean isNoOp()
      Description copied from interface: ISpan
      Whether this span instance is a NOOP that doesn't collect information
      Specified by:
      isNoOp in interface ISpan
      Returns:
      true if NOOP
    • getLocalMetricsAggregator

      @Nullable public @Nullable LocalMetricsAggregator getLocalMetricsAggregator()
      Description copied from interface: ISpan
      Returns the metrics aggregator for this span.
      Specified by:
      getLocalMetricsAggregator in interface ISpan
      Returns:
      the metrics aggregator