Package io.sentry
Interface IHub
- All Known Implementing Classes:
Hub
,HubAdapter
,NoOpHub
public interface IHub
SDK API contract which combines a client and scope management
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBreadcrumb
(@NotNull Breadcrumb breadcrumb) Adds a breadcrumb to the current Scopevoid
addBreadcrumb
(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint) Adds a breadcrumb to the current Scopedefault void
addBreadcrumb
(@NotNull String message) Adds a breadcrumb to the current Scopedefault void
addBreadcrumb
(@NotNull String message, @NotNull String category) Adds a breadcrumb to the current Scopevoid
bindClient
(@NotNull ISentryClient client) Binds a different client to the hub@NotNull SentryId
captureCheckIn
(@NotNull CheckIn checkIn) default @NotNull SentryId
captureEnvelope
(@NotNull SentryEnvelope envelope) Captures an envelope.@NotNull SentryId
captureEnvelope
(@NotNull SentryEnvelope envelope, @Nullable Hint hint) Captures an envelope.default @NotNull SentryId
captureEvent
(@NotNull SentryEvent event) Captures the event.default @NotNull SentryId
captureEvent
(@NotNull SentryEvent event, @NotNull ScopeCallback callback) Captures the event.@NotNull SentryId
captureEvent
(@NotNull SentryEvent event, @Nullable Hint hint) Captures the event.@NotNull SentryId
captureEvent
(@NotNull SentryEvent event, @Nullable Hint hint, @NotNull ScopeCallback callback) Captures the event.default @NotNull SentryId
captureException
(@NotNull Throwable throwable) Captures the exception.default @NotNull SentryId
captureException
(@NotNull Throwable throwable, @NotNull ScopeCallback callback) Captures the exception.@NotNull SentryId
captureException
(@NotNull Throwable throwable, @Nullable Hint hint) Captures the exception.@NotNull SentryId
captureException
(@NotNull Throwable throwable, @Nullable Hint hint, @NotNull ScopeCallback callback) Captures the exception.default @NotNull SentryId
captureMessage
(@NotNull String message) Captures the message.default @NotNull SentryId
captureMessage
(@NotNull String message, @NotNull ScopeCallback callback) Captures the message.@NotNull SentryId
captureMessage
(@NotNull String message, @NotNull SentryLevel level) Captures the message.@NotNull SentryId
captureMessage
(@NotNull String message, @NotNull SentryLevel level, @NotNull ScopeCallback callback) Captures the message.@NotNull SentryId
captureReplay
(@NotNull SentryReplayEvent replay, @Nullable Hint hint) default @NotNull SentryId
captureTransaction
(@NotNull SentryTransaction transaction, @Nullable Hint hint) default @NotNull SentryId
captureTransaction
(@NotNull SentryTransaction transaction, @Nullable TraceContext traceContext) Captures the transaction and enqueues it for sending to Sentry server.default @NotNull SentryId
captureTransaction
(@NotNull SentryTransaction transaction, @Nullable TraceContext traceContext, @Nullable Hint hint) Captures the transaction and enqueues it for sending to Sentry server.@NotNull SentryId
captureTransaction
(@NotNull SentryTransaction transaction, @Nullable TraceContext traceContext, @Nullable Hint hint, @Nullable ProfilingTraceData profilingTraceData) Captures the transaction and enqueues it for sending to Sentry server.void
captureUserFeedback
(@NotNull UserFeedback userFeedback) Captures a manually created user feedback and sends it to Sentry.void
Deletes current breadcrumbs from the current scope.@NotNull IHub
clone()
Clones the Hubvoid
close()
Flushes out the queue for up to timeout seconds and disable the Hub.void
close
(boolean isRestarting) Flushes out the queue for up to timeout seconds and disable the Hub.void
configureScope
(@NotNull ScopeCallback callback) Configures the scope through the callback.@Nullable TransactionContext
continueTrace
(@Nullable String sentryTrace, @Nullable List<String> baggageHeaders) Continue a trace based on HTTP header values.void
Ends the current sessionvoid
flush
(long timeoutMillis) Flushes events queued up, but keeps the Hub enabled.@Nullable BaggageHeader
Returns the "baggage" header that allows tracing across services.@NotNull SentryId
Last event id recorded in the current scope@NotNull SentryOptions
Gets theSentryOptions
attached to current scope.@Nullable RateLimiter
@Nullable ISpan
getSpan()
Gets the current active transaction or span.@Nullable SentryTraceHeader
Returns the "sentry-trace" header that allows tracing across services.@Nullable ITransaction
Returns the transaction.@Nullable Boolean
Returns if the App has crashed (Process has terminated) during the last run.boolean
Check if the Hub is enabled/active.boolean
Whether the transport is healthy.@NotNull MetricsApi
metrics()
void
popScope()
Removes the first scopevoid
Pushes a new scope while inheriting the current scope's data.void
removeExtra
(@NotNull String key) Removes the extra key to an arbitrary value to the current Scopevoid
Removes the tag to a string value to the current Scopedefault void
Deprecated.void
Report a screen has been fully loaded.void
Sets the extra key to an arbitrary value to the current Scope, overwriting a potential previous valuevoid
setFingerprint
(@NotNull List<String> fingerprint) Sets the fingerprint to group specific events together to the current Scope.void
setLevel
(@Nullable SentryLevel level) Sets the level of all events sent within current Scopevoid
setSpanContext
(@NotNull Throwable throwable, @NotNull ISpan span, @NotNull String transactionName) void
Sets the tag to a string value to the current Scope, overwriting a potential previous valuevoid
setTransaction
(@Nullable String transaction) Sets the name of the current transaction to the current Scope.void
Shallow merges user configuration (email, username, etc) to the current Scope.void
Starts a new session.default @NotNull ITransaction
startTransaction
(@NotNull TransactionContext transactionContexts) Creates a Transaction and returns the instance.@NotNull ITransaction
startTransaction
(@NotNull TransactionContext transactionContext, @NotNull TransactionOptions transactionOptions) Creates a Transaction and returns the instance.default @NotNull ITransaction
startTransaction
(@NotNull String name, @NotNull String operation) Creates a Transaction and returns the instance.default @NotNull ITransaction
startTransaction
(@NotNull String name, @NotNull String operation, @NotNull TransactionOptions transactionOptions) Creates a Transaction and returns the instance.@Nullable SentryTraceHeader
Deprecated.please usegetTraceparent()
instead.void
withScope
(@NotNull ScopeCallback callback) Runs the callback with a new scope which gets dropped at the end.
-
Method Details
-
isEnabled
boolean isEnabled()Check if the Hub is enabled/active.- Returns:
- true if its enabled or false otherwise.
-
captureEvent
@NotNull @NotNull SentryId captureEvent(@NotNull @NotNull SentryEvent event, @Nullable @Nullable Hint hint) Captures the event.- Parameters:
event
- the eventhint
- SDK specific but provides high level information about the origin of the event- Returns:
- The Id (SentryId object) of the event
-
captureEvent
Captures the event.- Parameters:
event
- the event- Returns:
- The Id (SentryId object) of the event
-
captureEvent
@NotNull default @NotNull SentryId captureEvent(@NotNull @NotNull SentryEvent event, @NotNull @NotNull ScopeCallback callback) Captures the event.- Parameters:
event
- the eventcallback
- The callback to configure the scope for a single invocation.- Returns:
- The Id (SentryId object) of the event
-
captureEvent
@NotNull @NotNull SentryId captureEvent(@NotNull @NotNull SentryEvent event, @Nullable @Nullable Hint hint, @NotNull @NotNull ScopeCallback callback) Captures the event.- Parameters:
event
- the eventhint
- SDK specific but provides high level information about the origin of the eventcallback
- The callback to configure the scope for a single invocation.- Returns:
- The Id (SentryId object) of the event
-
captureMessage
Captures the message.- Parameters:
message
- The message to send.- Returns:
- The Id (SentryId object) of the event
-
captureMessage
@NotNull @NotNull SentryId captureMessage(@NotNull @NotNull String message, @NotNull @NotNull SentryLevel level) Captures the message.- Parameters:
message
- The message to send.level
- The message level.- Returns:
- The Id (SentryId object) of the event
-
captureMessage
@NotNull @NotNull SentryId captureMessage(@NotNull @NotNull String message, @NotNull @NotNull SentryLevel level, @NotNull @NotNull ScopeCallback callback) Captures the message.- Parameters:
message
- The message to send.level
- The message level.callback
- The callback to configure the scope for a single invocation.- Returns:
- The Id (SentryId object) of the event
-
captureMessage
@NotNull default @NotNull SentryId captureMessage(@NotNull @NotNull String message, @NotNull @NotNull ScopeCallback callback) Captures the message.- Parameters:
message
- The message to send.callback
- The callback to configure the scope for a single invocation.- Returns:
- The Id (SentryId object) of the event
-
captureEnvelope
@NotNull @NotNull SentryId captureEnvelope(@NotNull @NotNull SentryEnvelope envelope, @Nullable @Nullable Hint hint) Captures an envelope.- Parameters:
envelope
- the SentryEnvelope to send.hint
- SDK specific but provides high level information about the origin of the event- Returns:
- The Id (SentryId object) of the event
-
captureEnvelope
Captures an envelope.- Parameters:
envelope
- the SentryEnvelope to send.- Returns:
- The Id (SentryId object) of the event
-
captureException
@NotNull @NotNull SentryId captureException(@NotNull @NotNull Throwable throwable, @Nullable @Nullable Hint hint) Captures the exception.- Parameters:
throwable
- The exception.hint
- SDK specific but provides high level information about the origin of the event- Returns:
- The Id (SentryId object) of the event
-
captureException
Captures the exception.- Parameters:
throwable
- The exception.- Returns:
- The Id (SentryId object) of the event
-
captureException
@NotNull default @NotNull SentryId captureException(@NotNull @NotNull Throwable throwable, @NotNull @NotNull ScopeCallback callback) Captures the exception.- Parameters:
throwable
- The exception.callback
- The callback to configure the scope for a single invocation.- Returns:
- The Id (SentryId object) of the event
-
captureException
@NotNull @NotNull SentryId captureException(@NotNull @NotNull Throwable throwable, @Nullable @Nullable Hint hint, @NotNull @NotNull ScopeCallback callback) Captures the exception.- Parameters:
throwable
- The exception.hint
- SDK specific but provides high level information about the origin of the eventcallback
- The callback to configure the scope for a single invocation.- Returns:
- The Id (SentryId object) of the event
-
captureUserFeedback
Captures a manually created user feedback and sends it to Sentry.- Parameters:
userFeedback
- The user feedback to send to Sentry.
-
startSession
void startSession()Starts a new session. If there's a running session, it ends it before starting the new one. -
endSession
void endSession()Ends the current session -
close
void close()Flushes out the queue for up to timeout seconds and disable the Hub. -
close
void close(boolean isRestarting) Flushes out the queue for up to timeout seconds and disable the Hub.- Parameters:
isRestarting
- if true, avoids locking the main thread when finishing the queue.
-
addBreadcrumb
Adds a breadcrumb to the current Scope- Parameters:
breadcrumb
- the breadcrumbhint
- SDK specific but provides high level information about the origin of the event
-
addBreadcrumb
Adds a breadcrumb to the current Scope- Parameters:
breadcrumb
- the breadcrumb
-
addBreadcrumb
Adds a breadcrumb to the current Scope- Parameters:
message
- rendered as text and the whitespace is preserved.
-
addBreadcrumb
Adds a breadcrumb to the current Scope- Parameters:
message
- rendered as text and the whitespace is preserved.category
- Categories are dotted strings that indicate what the crumb is or where it comes from.
-
setLevel
Sets the level of all events sent within current Scope- Parameters:
level
- the Sentry level
-
setTransaction
Sets the name of the current transaction to the current Scope.- Parameters:
transaction
- the transaction
-
setUser
Shallow merges user configuration (email, username, etc) to the current Scope.- Parameters:
user
- the user
-
setFingerprint
Sets the fingerprint to group specific events together to the current Scope.- Parameters:
fingerprint
- the fingerprints
-
clearBreadcrumbs
void clearBreadcrumbs()Deletes current breadcrumbs from the current scope. -
setTag
Sets the tag to a string value to the current Scope, overwriting a potential previous value- Parameters:
key
- the keyvalue
- the value
-
removeTag
Removes the tag to a string value to the current Scope- Parameters:
key
- the key
-
setExtra
Sets the extra key to an arbitrary value to the current Scope, overwriting a potential previous value- Parameters:
key
- the keyvalue
- the value
-
removeExtra
Removes the extra key to an arbitrary value to the current Scope- Parameters:
key
- the key
-
getLastEventId
Last event id recorded in the current scope- Returns:
- last SentryId
-
pushScope
void pushScope()Pushes a new scope while inheriting the current scope's data. -
popScope
void popScope()Removes the first scope -
withScope
Runs the callback with a new scope which gets dropped at the end. If you're using the Sentry SDK in globalHubMode (defaults to true on Android)Sentry.init(Sentry.OptionsConfiguration, boolean)
calling withScope is discouraged, as scope changes may be dropped when executed in parallel. UseconfigureScope(ScopeCallback)
instead.- Parameters:
callback
- the callback
-
configureScope
Configures the scope through the callback.- Parameters:
callback
- The configure scope callback.
-
bindClient
Binds a different client to the hub- Parameters:
client
- the client.
-
isHealthy
boolean isHealthy()Whether the transport is healthy.- Returns:
- true if the transport is healthy
-
flush
void flush(long timeoutMillis) Flushes events queued up, but keeps the Hub enabled. Not implemented yet.- Parameters:
timeoutMillis
- time in milliseconds
-
clone
Clones the Hub- Returns:
- the cloned Hub
-
captureTransaction
@Internal @NotNull @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable TraceContext traceContext, @Nullable @Nullable Hint hint, @Nullable @Nullable ProfilingTraceData profilingTraceData) Captures the transaction and enqueues it for sending to Sentry server.- Parameters:
transaction
- the transactiontraceContext
- the trace contexthint
- the hintsprofilingTraceData
- the profiling trace data- Returns:
- transaction's id
-
captureTransaction
@Internal @NotNull default @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable TraceContext traceContext, @Nullable @Nullable Hint hint) Captures the transaction and enqueues it for sending to Sentry server.- Parameters:
transaction
- the transactiontraceContext
- the trace contexthint
- the hints- Returns:
- transaction's id
-
captureTransaction
@Internal @NotNull default @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable Hint hint) -
captureTransaction
@Internal @NotNull default @NotNull SentryId captureTransaction(@NotNull @NotNull SentryTransaction transaction, @Nullable @Nullable TraceContext traceContext) Captures the transaction and enqueues it for sending to Sentry server.- Parameters:
transaction
- the transactiontraceContext
- the trace context- Returns:
- transaction's id
-
startTransaction
@NotNull default @NotNull ITransaction startTransaction(@NotNull @NotNull TransactionContext transactionContexts) Creates a Transaction and returns the instance.- Parameters:
transactionContexts
- the transaction contexts- Returns:
- created transaction
-
startTransaction
@NotNull default @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation) Creates a Transaction and returns the instance. Based on theSentryOptions.getTracesSampleRate()
the decision if transaction is sampled will be taken byTracesSampler
.- Parameters:
name
- the transaction nameoperation
- the operation- Returns:
- created transaction
-
startTransaction
@NotNull default @NotNull ITransaction startTransaction(@NotNull @NotNull String name, @NotNull @NotNull String operation, @NotNull @NotNull TransactionOptions transactionOptions) Creates a Transaction and returns the instance. Based on theSentryOptions.getTracesSampleRate()
the decision if transaction is sampled will be taken byTracesSampler
.- Parameters:
name
- the transaction nameoperation
- the operationtransactionOptions
- the transaction options- Returns:
- created transaction
-
startTransaction
@NotNull @NotNull ITransaction startTransaction(@NotNull @NotNull TransactionContext transactionContext, @NotNull @NotNull TransactionOptions transactionOptions) Creates a Transaction and returns the instance. Based on the passed transaction context and transaction options the decision if transaction is sampled will be taken byTracesSampler
.- Parameters:
transactionContext
- the transaction contexttransactionOptions
- the transaction options- Returns:
- created transaction.
-
traceHeaders
Deprecated.please usegetTraceparent()
instead.Returns the "sentry-trace" header that allows tracing across services. Can also be used in <meta> HTML tags. Also seegetBaggage()
.- Returns:
- sentry trace header or null
-
setSpanContext
@Internal void setSpanContext(@NotNull @NotNull Throwable throwable, @NotNull @NotNull ISpan span, @NotNull @NotNull String transactionName) AssociatesISpan
and the transaction name with theThrowable
. Used to determine in which trace the exception has been thrown in framework integrations.- Parameters:
throwable
- the throwablespan
- the span contexttransactionName
- the transaction name
-
getSpan
Gets the current active transaction or span.- Returns:
- the active span or null when no active transaction is running
-
getTransaction
Returns the transaction.- Returns:
- the transaction or null when no active transaction is running.
-
getOptions
Gets theSentryOptions
attached to current scope.- Returns:
- the options attached to current scope.
-
isCrashedLastRun
Returns if the App has crashed (Process has terminated) during the last run. It only returns true or false if offline caching {SentryOptions.getCacheDirPath()
} is set with a valid dir.If the call to this method is early in the App lifecycle and the SDK could not check if the App has crashed in the background, the check is gonna do IO in the calling thread.
- Returns:
- true if App has crashed, false otherwise, and null if not evaluated yet
-
reportFullyDisplayed
void reportFullyDisplayed()Report a screen has been fully loaded. That means all data needed by the UI was loaded. If time-to-full-display tracing {SentryOptions.isEnableTimeToFullDisplayTracing()
} is disabled this call is ignored.This method is safe to be called multiple times. If the time-to-full-display span is already finished, this call will be ignored.
-
reportFullDisplayed
Deprecated. -
continueTrace
@Nullable @Nullable TransactionContext continueTrace(@Nullable @Nullable String sentryTrace, @Nullable @Nullable List<String> baggageHeaders) Continue a trace based on HTTP header values. If no "sentry-trace" header is provided a random trace ID and span ID is created.- Parameters:
sentryTrace
- "sentry-trace" headerbaggageHeaders
- "baggage" headers- Returns:
- a transaction context for starting a transaction or null if performance is disabled
-
getTraceparent
Returns the "sentry-trace" header that allows tracing across services. Can also be used in <meta> HTML tags. Also seegetBaggage()
.- Returns:
- sentry trace header or null
-
getBaggage
Returns the "baggage" header that allows tracing across services. Can also be used in <meta> HTML tags. Also seegetTraceparent()
.- Returns:
- baggage header or null
-
captureCheckIn
-
captureReplay
@NotNull @NotNull SentryId captureReplay(@NotNull @NotNull SentryReplayEvent replay, @Nullable @Nullable Hint hint) -
getRateLimiter
-
metrics
-
reportFullyDisplayed()
.