| Copyright | (c) Ian Duncan 2021-2026 |
|---|---|
| License | BSD-3 |
| Maintainer | Ian Duncan |
| Stability | experimental |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
OpenTelemetry.Trace.Core
Description
Overview
This module provides the core tracing API for creating and managing spans. Most application code should use OpenTelemetry.Trace (from the SDK package) for initialization and OpenTelemetry.Trace.Monad for a cleaner monadic interface. This module is useful when you need direct control or are writing instrumentation libraries.
Quick example
import OpenTelemetry.Trace.Core
-- Wrap any IO action in a span:
handleRequest :: Tracer -> Request -> IO Response
handleRequest tracer req =
inSpan tracer "handleRequest" defaultSpanArguments $ do
result <- processRequest req
pure result
-- Access the span to add attributes:
fetchUser :: Tracer -> UserId -> IO User
fetchUser tracer uid =
inSpan' tracer "fetchUser" defaultSpanArguments $ \span -> do
addAttribute span "user.id" (toAttribute uid)
user <- db_lookupUser uid
addAttribute span "user.name" (toAttribute (userName user))
pure userKey concepts
TracerProvider- Factory that holds configuration (processors, exporters,
samplers) and creates
Tracers. Typically one per application, created at startup. Tracer- Obtained from a
TracerProvider, scoped to an instrumentation library or application component. Carries the library name and version for attribution. Span- Represents a unit of work. Has a name, start/end timestamps,
attributes, events, links, and status. Created by
inSpanorcreateSpan.
Creating spans
The inSpan family of functions is the primary API:
inSpan: wraps anIO aaction (or anyMonadUnliftIOaction), automatically ending the span and recording exceptions. Captures source location from the call site.inSpan′: likeinSpan, but passes theSpanto the callback so you can add attributes or events during execution. (In Haskell source the name ends with one ASCII prime character.)inSpan′′: raw variant with no automaticcode.*attributes from the call site. Preferred for instrumentation libraries where those attributes would describe library internals rather than user code. (In Haskell source the name ends with two ASCII prime characters.)
For manual span lifecycle management, use createSpan and endSpan.
Adding metadata
inSpan' tracer "processOrder" defaultSpanArguments $ \span -> do
addAttribute span "order.id" (toAttribute orderId)
addAttributes span
[ ("order.total", toAttribute total)
, ("order.currency", toAttribute "USD")
]
addEvent span (newEvent "order.validated")
setStatus span OkError handling
inSpan and inSpan′ automatically catch exceptions, record them on the span (as an exception
event with stack trace), set the span status to Error, and re-throw. You
can also manually set error status:
setStatus span (Error "payment declined") recordException span mempty Nothing myException
Source location
inSpan, inSpan′, and createSpan automatically add source location
attributes from GHC's HasCallStack. The attribute names depend on the
OTEL_SEMCONV_STABILITY_OPT_IN setting:
- Default (
Old):code.function,code.namespace,code.filepath,code.lineno code:code.function.name,code.file.path,code.line.number(stable semconv v1.33+)code/dup: both old and stable names emitted
If you provide any code.* attribute yourself in
SpanArguments, the automatic attributes are suppressed.
Spec reference
Synopsis
- data TracerProvider
- createTracerProvider :: MonadIO m => [SpanProcessor] -> TracerProviderOptions -> m TracerProvider
- shutdownTracerProvider :: MonadIO m => TracerProvider -> Maybe Int -> m ShutdownResult
- data ShutdownResult
- worstShutdown :: ShutdownResult -> ShutdownResult -> ShutdownResult
- forceFlushTracerProvider :: MonadIO m => TracerProvider -> Maybe Int -> m FlushResult
- data FlushResult
- getTracerProviderResources :: TracerProvider -> MaterializedResources
- getTracerProviderPropagators :: TracerProvider -> TextMapPropagator
- getGlobalTracerProvider :: MonadIO m => m TracerProvider
- setGlobalTracerProvider :: MonadIO m => TracerProvider -> m ()
- emptyTracerProviderOptions :: TracerProviderOptions
- data TracerProviderOptions = TracerProviderOptions {
- tracerProviderOptionsIdGenerator :: IdGenerator
- tracerProviderOptionsSampler :: Sampler
- tracerProviderOptionsResources :: MaterializedResources
- tracerProviderOptionsAttributeLimits :: AttributeLimits
- tracerProviderOptionsSpanLimits :: SpanLimits
- tracerProviderOptionsPropagators :: TextMapPropagator
- tracerProviderOptionsExceptionHandlers :: [ExceptionHandler]
- data Tracer
- tracerName :: Tracer -> InstrumentationLibrary
- tracerIsEnabled :: Tracer -> Bool
- class HasTracer s where
- makeTracer :: TracerProvider -> InstrumentationLibrary -> TracerOptions -> Tracer
- getTracer :: MonadIO m => TracerProvider -> InstrumentationLibrary -> TracerOptions -> m Tracer
- getImmutableSpanTracer :: ImmutableSpan -> Tracer
- getTracerTracerProvider :: Tracer -> TracerProvider
- data InstrumentationLibrary = InstrumentationLibrary {}
- instrumentationLibrary :: Text -> Text -> InstrumentationLibrary
- withSchemaUrl :: Text -> InstrumentationLibrary -> InstrumentationLibrary
- withLibraryAttributes :: Attributes -> InstrumentationLibrary -> InstrumentationLibrary
- detectInstrumentationLibrary :: (Quasi m, Quote m) => m Exp
- data TracerOptions = TracerOptions {}
- tracerOptions :: TracerOptions
- data Span
- toImmutableSpan :: MonadIO m => Span -> m (Either FrozenOrDropped ImmutableSpan)
- data FrozenOrDropped
- data ImmutableSpan = ImmutableSpan {
- spanContext :: !SpanContext
- spanKind :: !SpanKind
- spanStart :: !Timestamp
- spanParent :: !(Maybe Span)
- spanTracer :: !Tracer
- spanHot :: !(IORef SpanHot)
- data SpanHot = SpanHot {}
- data SpanContext = SpanContext {
- traceFlags :: !TraceFlags
- isRemote :: !Bool
- traceId :: !TraceId
- spanId :: !SpanId
- traceState :: !TraceState
- data TraceFlags
- traceFlagsValue :: TraceFlags -> Word8
- traceFlagsFromWord8 :: Word8 -> TraceFlags
- defaultTraceFlags :: TraceFlags
- isSampled :: TraceFlags -> Bool
- setSampled :: TraceFlags -> TraceFlags
- unsetSampled :: TraceFlags -> TraceFlags
- isRandom :: TraceFlags -> Bool
- setRandom :: TraceFlags -> TraceFlags
- unsetRandom :: TraceFlags -> TraceFlags
- inSpan :: (MonadUnliftIO m, HasCallStack) => Tracer -> Text -> SpanArguments -> m a -> m a
- inSpan' :: (MonadUnliftIO m, HasCallStack) => Tracer -> Text -> SpanArguments -> (Span -> m a) -> m a
- inSpan'' :: (MonadUnliftIO m, HasCallStack) => Tracer -> Text -> SpanArguments -> (Span -> m a) -> m a
- createSpan :: (MonadIO m, HasCallStack) => Tracer -> Context -> Text -> SpanArguments -> m Span
- createSpanWithoutCallStack :: MonadIO m => Tracer -> Context -> Text -> SpanArguments -> m Span
- wrapSpanContext :: SpanContext -> Span
- wrapDroppedContext :: SpanContext -> Span
- data SpanKind
- defaultSpanArguments :: SpanArguments
- data SpanArguments = SpanArguments {
- kind :: SpanKind
- attributes :: AttributeMap
- links :: [NewLink]
- startTime :: Maybe Timestamp
- data Event = Event {}
- data NewEvent = NewEvent {}
- addEvent :: MonadIO m => Span -> NewEvent -> m ()
- updateName :: MonadIO m => Span -> Text -> m ()
- addAttribute :: (MonadIO m, ToAttribute a) => Span -> Text -> a -> m ()
- addAttributes :: MonadIO m => Span -> HashMap Text Attribute -> m ()
- addAttributes' :: MonadIO m => Span -> AttrsBuilder -> m ()
- spanGetAttributes :: MonadIO m => Span -> m Attributes
- data Attribute
- class ToAttribute a where
- toAttribute :: a -> Attribute
- data PrimitiveAttribute
- class ToPrimitiveAttribute a where
- data AttrsBuilder
- attr :: ToAttribute a => Text -> a -> AttrsBuilder
- optAttr :: ToAttribute a => Text -> Maybe a -> AttrsBuilder
- (.@) :: ToAttribute a => AttributeKey a -> a -> AttrsBuilder
- (.@?) :: ToAttribute a => AttributeKey a -> Maybe a -> AttrsBuilder
- buildAttrs :: AttrsBuilder -> AttributeMap
- data Link = Link {}
- data NewLink = NewLink {}
- addLink :: MonadIO m => Span -> NewLink -> m ()
- recordException :: (MonadIO m, Exception e) => Span -> AttributeMap -> Maybe Timestamp -> e -> m ()
- recordError :: (MonadIO m, Exception e) => Span -> e -> m ()
- setStatus :: MonadIO m => Span -> SpanStatus -> m ()
- data SpanStatus
- data ExceptionClassification
- data ExceptionResponse = ExceptionResponse {}
- type ExceptionHandler = SomeException -> Maybe ExceptionResponse
- defaultExceptionResponse :: ExceptionResponse
- resolveException :: Tracer -> SomeException -> ExceptionResponse
- endSpan :: MonadIO m => Span -> Maybe Timestamp -> m ()
- getSpanContext :: MonadIO m => Span -> m SpanContext
- isRecording :: MonadIO m => Span -> m Bool
- isValid :: SpanContext -> Bool
- spanIsRemote :: MonadIO m => Span -> m Bool
- getActiveSpan :: MonadIO m => m (Maybe Span)
- withActiveSpan :: MonadIO m => (Span -> m ()) -> m ()
- getActiveSpanContext :: MonadIO m => m (Maybe SpanContext)
- newEvent :: Text -> NewEvent
- newEventWith :: Text -> AttributeMap -> NewEvent
- data Timestamp
- getTimestamp :: MonadIO m => m Timestamp
- timestampNanoseconds :: Timestamp -> Word64
- unsafeReadSpan :: MonadIO m => Span -> m ImmutableSpan
- whenSpanIsRecording :: MonadIO m => Span -> m () -> m ()
- codeAttributes :: StabilityOpt -> String -> SrcLoc -> AttributeMap
- ownCodeAttributes :: HasCallStack => AttributeMap
- callerAttributes :: HasCallStack => AttributeMap
- addAttributesToSpanArguments :: AttributeMap -> SpanArguments -> SpanArguments
- data SpanLimits = SpanLimits {}
- defaultSpanLimits :: SpanLimits
- bracketError :: MonadUnliftIO m => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c
TracerProvider operations
data TracerProvider Source #
Factory for creating Tracer instances. Holds configuration shared
across all tracers: processors, sampler, resource, limits, and propagators.
Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracerprovider
Since: 0.0.1.0
createTracerProvider :: MonadIO m => [SpanProcessor] -> TracerProviderOptions -> m TracerProvider Source #
Initialize a new tracer provider
You should generally use getGlobalTracerProvider for most applications.
Since: 0.0.1.0
shutdownTracerProvider Source #
Arguments
| :: MonadIO m | |
| => TracerProvider | |
| -> Maybe Int | Optional timeout in microseconds, defaults to 5,000,000 (5s) |
| -> m ShutdownResult |
This method provides a way for provider to do any cleanup required.
This will also trigger shutdowns on all internal processors.
Since: 0.0.1.0
data ShutdownResult Source #
Since: 0.0.1.0
Constructors
| ShutdownSuccess | |
| ShutdownFailure | |
| ShutdownTimeout |
Instances
| Show ShutdownResult Source # | |
Defined in OpenTelemetry.Internal.Common.Types Methods showsPrec :: Int -> ShutdownResult -> ShowS # show :: ShutdownResult -> String # showList :: [ShutdownResult] -> ShowS # | |
| Eq ShutdownResult Source # | |
Defined in OpenTelemetry.Internal.Common.Types Methods (==) :: ShutdownResult -> ShutdownResult -> Bool # (/=) :: ShutdownResult -> ShutdownResult -> Bool # | |
worstShutdown :: ShutdownResult -> ShutdownResult -> ShutdownResult Source #
Combine two shutdown results, preferring the "worst" outcome. Failure > Timeout > Success.
Since: 0.4.0.0
forceFlushTracerProvider Source #
Arguments
| :: MonadIO m | |
| => TracerProvider | |
| -> Maybe Int | Optional timeout in microseconds, defaults to 5,000,000 (5s) |
| -> m FlushResult | Result that denotes whether the flush action succeeded, failed, or timed out. |
This method provides a way for provider to immediately export all spans that have not yet been exported for all the internal processors.
Since: 0.0.1.0
data FlushResult Source #
The outcome of a call to OpenTelemetry.Trace.forceFlush or OpenTelemetry.Log.forceFlush
Since: 0.0.1.0
Constructors
| FlushTimeout | One or more spans or |
| FlushSuccess | Flushing spans or |
| FlushError | One or more exporters failed to successfully export one or more
unexported spans or |
Instances
| Show FlushResult Source # | |
Defined in OpenTelemetry.Internal.Common.Types Methods showsPrec :: Int -> FlushResult -> ShowS # show :: FlushResult -> String # showList :: [FlushResult] -> ShowS # | |
| Eq FlushResult Source # | |
Defined in OpenTelemetry.Internal.Common.Types | |
getTracerProviderResources :: TracerProvider -> MaterializedResources Source #
Since: 0.0.1.0
getTracerProviderPropagators :: TracerProvider -> TextMapPropagator Source #
Since: 0.0.1.0
getGlobalTracerProvider :: MonadIO m => m TracerProvider Source #
Access the globally configured TracerProvider. Once the
the global tracer provider is initialized via the OpenTelemetry SDK,
Tracers created from this TracerProvider will export spans to their
configured exporters. Prior to that, any Tracers acquired from the
uninitialized TracerProvider will create no-op spans.
Since: 0.0.1.0
setGlobalTracerProvider :: MonadIO m => TracerProvider -> m () Source #
Overwrite the globally configured TracerProvider.
Tracers acquired from the previously installed TracerProvider
will continue to use that TracerProviders configured span processors,
exporters, and other settings.
Since: 0.0.1.0
emptyTracerProviderOptions :: TracerProviderOptions Source #
Options for creating a TracerProvider with invalid ids, no resources, default limits, and no propagators.
In effect, tracing is a no-op when using this configuration.
Since: 0.0.1.0
data TracerProviderOptions Source #
Options used when creating a TracerProvider.
Since: 0.0.1.0
Constructors
| TracerProviderOptions | |
Fields
| |
Tracer operations
Creates and manages Spans for a specific instrumentation scope.
Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracer
Since: 0.0.1.0
tracerName :: Tracer -> InstrumentationLibrary Source #
Get the name of the Tracer
Since: 0.0.10
tracerIsEnabled :: Tracer -> Bool Source #
Check if the Tracer is enabled.
This function helps users avoid performing computationally expensive operations
when creating Spans if the tracer is not enabled.
A Tracer is considered enabled if it has at least one configured processor.
If the TracerProvider has no processors, all spans will be dropped, so the
tracer is disabled.
Callers SHOULD invoke this before each span creation to get the most up-to-date response, as the result may change over time.
Since: 0.3.1.0
makeTracer :: TracerProvider -> InstrumentationLibrary -> TracerOptions -> Tracer Source #
Construct a Tracer from a provider, library, and options.
Prefer a non-empty libraryName per the OpenTelemetry specification; use getTracer
if you want a warning when the name is empty.
Since: 0.0.1.0
getTracer :: MonadIO m => TracerProvider -> InstrumentationLibrary -> TracerOptions -> m Tracer Source #
Like makeTracer but caches by InstrumentationLibrary, so repeated
calls with the same scope return the same Tracer instance.
Spec: implementations SHOULD return a single Tracer per InstrumentationScope.
Since: 0.0.1.0
getImmutableSpanTracer :: ImmutableSpan -> Tracer Source #
Since: 0.0.1.0
getTracerTracerProvider :: Tracer -> TracerProvider Source #
Since: 0.0.1.0
data InstrumentationLibrary Source #
An instrumentation scope identifies the library or component providing
instrumentation. The OpenTelemetry specification renamed this concept from
"Instrumentation Library" to "Instrumentation Scope"; this type retains
the old constructor name for backwards compatibility but InstrumentationScope
is the preferred type alias.
Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/
Since: 0.0.1.0
Constructors
| InstrumentationLibrary | |
Fields
| |
Instances
instrumentationLibrary :: Text -> Text -> InstrumentationLibrary Source #
Create an InstrumentationLibrary with a name and version.
Schema URL and attributes default to empty.
Prefer instrumentationScope for new code.
Since: 0.4.0.0
withSchemaUrl :: Text -> InstrumentationLibrary -> InstrumentationLibrary Source #
Set the schema URL on an InstrumentationLibrary.
Since: 0.4.0.0
withLibraryAttributes :: Attributes -> InstrumentationLibrary -> InstrumentationLibrary Source #
Set attributes on an InstrumentationLibrary.
Since: 0.4.0.0
detectInstrumentationLibrary :: (Quasi m, Quote m) => m Exp Source #
Works out the instrumentation library for your package.
Since: 0.0.1.0
data TracerOptions Source #
Tracer configuration options.
Since: 0.0.1.0
Constructors
| TracerOptions | |
Fields
| |
tracerOptions :: TracerOptions Source #
Default Tracer options
Since: 0.0.1.0
Span operations
A single unit of work in a distributed trace.
A span carries a name, timestamps, attributes, events, links, and a
SpanContext (trace ID + span ID). The three constructors represent:
Span: a live, recording span created by this process.FrozenSpan: a non-recording wrapper around a remoteSpanContext, used as a parent when continuing a trace from another process.Dropped: a span that was not sampled. Carries enough context (trace ID, span ID) for propagation but records nothing.
Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#span
Since: 0.0.1.0
toImmutableSpan :: MonadIO m => Span -> m (Either FrozenOrDropped ImmutableSpan) Source #
Extracts the values from a Span if it is still mutable. Returns a Left with FrozenOrDropped if the Span is frozen or dropped.
Since: 0.0.1.0
data FrozenOrDropped Source #
Since: 0.0.1.0
Constructors
| SpanFrozen | |
| SpanDropped |
Instances
| Show FrozenOrDropped Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods showsPrec :: Int -> FrozenOrDropped -> ShowS # show :: FrozenOrDropped -> String # showList :: [FrozenOrDropped] -> ShowS # | |
| Eq FrozenOrDropped Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods (==) :: FrozenOrDropped -> FrozenOrDropped -> Bool # (/=) :: FrozenOrDropped -> FrozenOrDropped -> Bool # | |
data ImmutableSpan Source #
The representation of a Span for processors and exporters.
Cold (immutable) fields live directly in the record and are never copied.
Hot (mutable) fields sit behind an IORef so that CAS operations only
allocate a fresh SpanHot instead of the entire span.
Since: 0.0.1.0
Constructors
| ImmutableSpan | |
Fields
| |
Instances
| Show ImmutableSpan Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods showsPrec :: Int -> ImmutableSpan -> ShowS # show :: ImmutableSpan -> String # showList :: [ImmutableSpan] -> ShowS # | |
Mutable fields of a span, stored behind an IORef and updated via CAS.
Only ~48 bytes, so each CAS allocates much less than copying the full span.
Since: 0.0.1.0
Constructors
| SpanHot | |
Fields
| |
data SpanContext Source #
The serializable portion of a Span: trace ID, span ID, trace flags,
and trace state. Immutable once created.
Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext W3C: https://www.w3.org/TR/trace-context/
Since: 0.0.1.0
Constructors
| SpanContext | |
Fields
| |
Instances
| Show SpanContext Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods showsPrec :: Int -> SpanContext -> ShowS # show :: SpanContext -> String # showList :: [SpanContext] -> ShowS # | |
| Eq SpanContext Source # | |
Defined in OpenTelemetry.Internal.Trace.Types | |
W3c Trace flags
data TraceFlags Source #
Contain details about the trace. Unlike TraceState values, TraceFlags are present in all traces. The current version of the specification only supports a single flag called sampled.
Since: 0.0.1.0
Instances
| Show TraceFlags Source # | |
Defined in OpenTelemetry.Common Methods showsPrec :: Int -> TraceFlags -> ShowS # show :: TraceFlags -> String # showList :: [TraceFlags] -> ShowS # | |
| Eq TraceFlags Source # | |
Defined in OpenTelemetry.Common | |
| Ord TraceFlags Source # | |
Defined in OpenTelemetry.Common Methods compare :: TraceFlags -> TraceFlags -> Ordering # (<) :: TraceFlags -> TraceFlags -> Bool # (<=) :: TraceFlags -> TraceFlags -> Bool # (>) :: TraceFlags -> TraceFlags -> Bool # (>=) :: TraceFlags -> TraceFlags -> Bool # max :: TraceFlags -> TraceFlags -> TraceFlags # min :: TraceFlags -> TraceFlags -> TraceFlags # | |
traceFlagsValue :: TraceFlags -> Word8 Source #
Get the current bitmask for the TraceFlags, useful for serialization purposes.
Since: 0.0.1.0
traceFlagsFromWord8 :: Word8 -> TraceFlags Source #
Create a TraceFlags, from an arbitrary Word8. Note that for backwards-compatibility
reasons, no checking is performed to determine whether the TraceFlags bitmask provided
is valid.
Since: 0.0.1.0
defaultTraceFlags :: TraceFlags Source #
TraceFlags with the sampled flag not set. This means that it is up to the
sampling configuration to decide whether or not to sample the trace.
Since: 0.0.1.0
isSampled :: TraceFlags -> Bool Source #
Will the trace associated with this TraceFlags value be sampled?
Since: 0.0.1.0
setSampled :: TraceFlags -> TraceFlags Source #
Set the sampled flag on the TraceFlags
Since: 0.0.1.0
unsetSampled :: TraceFlags -> TraceFlags Source #
Unset the sampled flag on the TraceFlags. This means that the
application may choose whether or not to emit this Trace.
Since: 0.0.1.0
isRandom :: TraceFlags -> Bool Source #
Test the W3C Level 2 random flag (bit 1). When set, the trace-id
has sufficient randomness for probabilistic sampling decisions.
See https://www.w3.org/TR/trace-context-2/#random-trace-id-flag.
Since: 0.4.0.0
setRandom :: TraceFlags -> TraceFlags Source #
Set the W3C Level 2 random flag (bit 1) on the TraceFlags.
Indicates that the trace-id was generated with a CSPRNG or equivalent
and has sufficient randomness for probabilistic sampling.
Since: 0.4.0.0
unsetRandom :: TraceFlags -> TraceFlags Source #
Unset the W3C Level 2 random flag (bit 1).
Since: 0.4.0.0
Creating Spans
Arguments
| :: (MonadUnliftIO m, HasCallStack) | |
| => Tracer | |
| -> Text | The name of the span. This may be updated later via |
| -> SpanArguments | Additional options for creating the span, such as |
| -> m a | The action to perform. |
| -> m a |
The simplest function for annotating code with trace information.
Since: 0.0.1.0
Arguments
| :: (MonadUnliftIO m, HasCallStack) | |
| => Tracer | |
| -> Text | The name of the span. This may be updated later via |
| -> SpanArguments | |
| -> (Span -> m a) | |
| -> m a |
Arguments
| :: (MonadUnliftIO m, HasCallStack) | |
| => Tracer | |
| -> Text | The name of the span. This may be updated later via |
| -> SpanArguments | |
| -> (Span -> m a) | |
| -> m a |
Like inSpan′ (the Haskell name has one ASCII prime), but does not add
automatic caller source location attributes.
Since: 0.4.0.0
Arguments
| :: (MonadIO m, HasCallStack) | |
| => Tracer |
|
| -> Context | Context, potentially containing a parent span. If no existing parent (or context) exists,
you can use |
| -> Text | Span name |
| -> SpanArguments | Additional span information |
| -> m Span | The created span. Try and infer source code information unless the user has set any of the attributes already, which we take as an indication that our automatic strategy won't work well. |
createSpanWithoutCallStack Source #
Arguments
| :: MonadIO m | |
| => Tracer |
|
| -> Context | Context, potentially containing a parent span. If no existing parent (or context) exists,
you can use |
| -> Text | Span name |
| -> SpanArguments | Additional span information |
| -> m Span | The created span. |
The same thing as createSpan, except that it does not have a HasCallStack constraint.
Since: 0.0.1.0
wrapSpanContext :: SpanContext -> Span Source #
Wrap a SpanContext as a non-recording Span (FrozenSpan).
Since: 0.0.1.0
wrapDroppedContext :: SpanContext -> Span Source #
Construct a non-recording parent span representing a dropped (not sampled) trace, e.g. for tests or when continuing a trace whose parent was not recorded.
Since: 0.4.0.0
SpanKind describes the relationship between the Span, its parents, and its children in a Trace. SpanKind describes two independent properties that benefit tracing systems during analysis.
The first property described by SpanKind reflects whether the Span is a remote child or parent. Spans with a remote parent are interesting because they are sources of external load. Spans with a remote child are interesting because they reflect a non-local system dependency.
The second property described by SpanKind reflects whether a child Span represents a synchronous call. When a child span is synchronous, the parent is expected to wait for it to complete under ordinary circumstances. It can be useful for tracing systems to know this property, since synchronous Spans may contribute to the overall trace latency. Asynchronous scenarios can be remote or local.
In order for SpanKind to be meaningful, callers SHOULD arrange that a single Span does not serve more than one purpose. For example, a server-side span SHOULD NOT be used directly as the parent of another remote span. As a simple guideline, instrumentation should create a new Span prior to extracting and serializing the SpanContext for a remote call.
To summarize the interpretation of these kinds
SpanKind | Synchronous | Asynchronous | Remote Incoming | Remote Outgoing |
|---|---|---|---|---|
Client | yes | yes | ||
Server | yes | yes | ||
Producer | yes | maybe | ||
Consumer | yes | maybe | ||
Internal |
Since: 0.0.1.0
Constructors
| Server | Indicates that the span covers server-side handling of a synchronous RPC or other remote request.
This span is the child of a remote |
| Client | Indicates that the span describes a synchronous request to some remote service.
This span is the parent of a remote |
| Producer | Indicates that the span describes the parent of an asynchronous request.
This parent span is expected to end before the corresponding child |
| Consumer | Indicates that the span describes the child of an asynchronous |
| Internal | Default value. Indicates that the span represents an internal operation within an application, as opposed to an operations with remote parents or children. |
defaultSpanArguments :: SpanArguments Source #
Smart constructor for SpanArguments providing reasonable values for most Spans created
that are internal to an application.
Defaults:
kind:Internalattributes:[]links:[]startTime:Nothing(getTimestampwill be called uponSpancreation)
Since: 0.0.1.0
data SpanArguments Source #
Non-name fields that may be set on initial creation of a Span.
Since: 0.0.1.0
Constructors
| SpanArguments | |
Fields
| |
Recording Events
A “log” that happens as part of a span. An operation that is too fast for its own span, but too unique to roll up into its parent span.
Events contain a name, a timestamp, and an optional set of Attributes, along with a timestamp. Events represent an event that occurred at a specific time within a span’s workload.
Since: 0.0.1.0
Constructors
| Event | |
Fields
| |
A “log” that happens as part of a span. An operation that is too fast for its own span, but too unique to roll up into its parent span.
Events contain a name, a timestamp, and an optional set of Attributes, along with a timestamp. Events represent an event that occurred at a specific time within a span’s workload.
When creating an event, this is the version that you will use. Attributes added that exceed the configured attribute limits will be dropped,
which is accounted for in the Event structure.
Since: 0.0.1.0
Constructors
| NewEvent | |
Fields
| |
addEvent :: MonadIO m => Span -> NewEvent -> m () Source #
Add an event to a recording span. Events will not be recorded for remote spans and dropped spans.
Since: 0.0.1.0
Enriching Spans with additional information
Arguments
| :: MonadIO m | |
| => Span | |
| -> Text | The new span name, which supersedes whatever was passed in when the Span was started |
| -> m () |
Updates the Span name. Upon this update, any sampling behavior based on Span name will depend on the implementation.
Note that Samplers can only consider information already present during span creation. Any changes done later, including updated span name, cannot change their decisions.
Alternatives for the name update may be late Span creation, when Span is started with the explicit timestamp from the past at the moment where the final Span name is known, or reporting a Span with the desired name as a child Span.
Since: 0.0.1.0
Arguments
| :: (MonadIO m, ToAttribute a) | |
| => Span | Span to add the attribute to |
| -> Text | Attribute name |
| -> a | Attribute value |
| -> m () |
Add an attribute to a span. Only affects recording spans.
See the OTel attribute naming conventions for guidance on choosing attribute names.
Since: 0.0.1.0
addAttributes :: MonadIO m => Span -> HashMap Text Attribute -> m () Source #
A convenience function related to addAttribute that adds multiple attributes to a span at the same time.
This function may be slightly more performant than repeatedly calling addAttribute.
Since: 0.0.1.0
addAttributes' :: MonadIO m => Span -> AttrsBuilder -> m () Source #
Like addAttributes, but takes an AttrsBuilder instead of a HashMap.
More efficient when setting many attributes at once.
With typed AttributeKeys from semantic conventions:
addAttributes'span $ SC.http_request_method.@method <> SC.url_full.@url <> SC.server_port.@?mPort
With plain Text keys:
addAttributes'span $attr"custom.key" value <>optAttr"custom.optional" mValue
Since: 0.4.1.0
spanGetAttributes :: MonadIO m => Span -> m Attributes Source #
This can be useful for pulling data for attributes and using it to copy / otherwise use the data to further enrich instrumentation.
Since: 0.0.1.0
Constructors
| AttributeValue PrimitiveAttribute | |
| AttributeArray [PrimitiveAttribute] |
Instances
| Data Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Attribute -> c Attribute # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Attribute # toConstr :: Attribute -> Constr # dataTypeOf :: Attribute -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Attribute) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Attribute) # gmapT :: (forall b. Data b => b -> b) -> Attribute -> Attribute # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Attribute -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Attribute -> r # gmapQ :: (forall d. Data d => d -> u) -> Attribute -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Attribute -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Attribute -> m Attribute # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Attribute -> m Attribute # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Attribute -> m Attribute # | |||||
| IsString Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods fromString :: String -> Attribute # | |||||
| Generic Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Associated Types
| |||||
| Read Attribute | |||||
| Show Attribute | |||||
| Eq Attribute | |||||
| Ord Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute | |||||
| Hashable Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute | |||||
| FromAttribute Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods fromAttribute :: Attribute -> Maybe Attribute # | |||||
| ToAttribute Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Attribute -> Attribute # | |||||
| Lift Attribute | |||||
| type Rep Attribute | |||||
Defined in OpenTelemetry.Attributes.Attribute type Rep Attribute = D1 ('MetaData "Attribute" "OpenTelemetry.Attributes.Attribute" "hs-opentelemetry-api-types-1.0.0.0-inplace" 'False) (C1 ('MetaCons "AttributeValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 PrimitiveAttribute)) :+: C1 ('MetaCons "AttributeArray" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [PrimitiveAttribute]))) | |||||
class ToAttribute a where #
Minimal complete definition
Nothing
Methods
toAttribute :: a -> Attribute #
Instances
| ToAttribute Int64 | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Int64 -> Attribute # | |
| ToAttribute Attribute | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Attribute -> Attribute # | |
| ToAttribute PrimitiveAttribute | |
Defined in OpenTelemetry.Attributes.Attribute Methods | |
| ToAttribute Text | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Text -> Attribute # | |
| ToAttribute Bool | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Bool -> Attribute # | |
| ToAttribute Double | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Double -> Attribute # | |
| ToAttribute Int | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: Int -> Attribute # | |
| ToPrimitiveAttribute a => ToAttribute [a] | |
Defined in OpenTelemetry.Attributes.Attribute Methods toAttribute :: [a] -> Attribute # | |
data PrimitiveAttribute #
Constructors
| TextAttribute Text | |
| BoolAttribute Bool | |
| DoubleAttribute !Double | |
| IntAttribute !Int64 |
Instances
| Data PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PrimitiveAttribute -> c PrimitiveAttribute # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PrimitiveAttribute # toConstr :: PrimitiveAttribute -> Constr # dataTypeOf :: PrimitiveAttribute -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PrimitiveAttribute) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrimitiveAttribute) # gmapT :: (forall b. Data b => b -> b) -> PrimitiveAttribute -> PrimitiveAttribute # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r # gmapQ :: (forall d. Data d => d -> u) -> PrimitiveAttribute -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> PrimitiveAttribute -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> PrimitiveAttribute -> m PrimitiveAttribute # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PrimitiveAttribute -> m PrimitiveAttribute # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PrimitiveAttribute -> m PrimitiveAttribute # | |||||
| IsString PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods fromString :: String -> PrimitiveAttribute # | |||||
| Generic PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Associated Types
Methods from :: PrimitiveAttribute -> Rep PrimitiveAttribute x # to :: Rep PrimitiveAttribute x -> PrimitiveAttribute # | |||||
| Read PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods readsPrec :: Int -> ReadS PrimitiveAttribute # readList :: ReadS [PrimitiveAttribute] # | |||||
| Show PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods showsPrec :: Int -> PrimitiveAttribute -> ShowS # show :: PrimitiveAttribute -> String # showList :: [PrimitiveAttribute] -> ShowS # | |||||
| Eq PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods (==) :: PrimitiveAttribute -> PrimitiveAttribute -> Bool # (/=) :: PrimitiveAttribute -> PrimitiveAttribute -> Bool # | |||||
| Ord PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods compare :: PrimitiveAttribute -> PrimitiveAttribute -> Ordering # (<) :: PrimitiveAttribute -> PrimitiveAttribute -> Bool # (<=) :: PrimitiveAttribute -> PrimitiveAttribute -> Bool # (>) :: PrimitiveAttribute -> PrimitiveAttribute -> Bool # (>=) :: PrimitiveAttribute -> PrimitiveAttribute -> Bool # max :: PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute # min :: PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute # | |||||
| Hashable PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute | |||||
| FromAttribute PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods | |||||
| FromPrimitiveAttribute PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe PrimitiveAttribute # | |||||
| ToAttribute PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods | |||||
| ToPrimitiveAttribute PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods toPrimitiveAttribute :: PrimitiveAttribute -> PrimitiveAttribute # | |||||
| Lift PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute Methods lift :: Quote m => PrimitiveAttribute -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => PrimitiveAttribute -> Code m PrimitiveAttribute # | |||||
| type Rep PrimitiveAttribute | |||||
Defined in OpenTelemetry.Attributes.Attribute type Rep PrimitiveAttribute = D1 ('MetaData "PrimitiveAttribute" "OpenTelemetry.Attributes.Attribute" "hs-opentelemetry-api-types-1.0.0.0-inplace" 'False) ((C1 ('MetaCons "TextAttribute" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "BoolAttribute" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Bool))) :+: (C1 ('MetaCons "DoubleAttribute" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 Double)) :+: C1 ('MetaCons "IntAttribute" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 Int64)))) | |||||
class ToPrimitiveAttribute a where #
Methods
toPrimitiveAttribute :: a -> PrimitiveAttribute #
Instances
| ToPrimitiveAttribute Int64 | |
Defined in OpenTelemetry.Attributes.Attribute Methods | |
| ToPrimitiveAttribute PrimitiveAttribute | |
Defined in OpenTelemetry.Attributes.Attribute Methods toPrimitiveAttribute :: PrimitiveAttribute -> PrimitiveAttribute # | |
| ToPrimitiveAttribute Text | |
Defined in OpenTelemetry.Attributes.Attribute Methods | |
| ToPrimitiveAttribute Bool | |
Defined in OpenTelemetry.Attributes.Attribute Methods | |
| ToPrimitiveAttribute Double | |
Defined in OpenTelemetry.Attributes.Attribute Methods | |
| ToPrimitiveAttribute Int | |
Defined in OpenTelemetry.Attributes.Attribute Methods | |
Attribute builder
data AttrsBuilder Source #
Church-encoded left fold over attribute key-value pairs. Avoids allocating
intermediate tuples, list spines, or HashMaps when adding multiple
attributes to a span.
Construct individual entries with attr / .@ and combine with <>.
GHC can inline and fuse static builder expressions, eliminating all
intermediate allocation.
addAttributes'span $ SC.http_request_method.@method <> SC.url_full.@url <> SC.server_port.@?mPort
Since: 0.4.0.0
Instances
| Monoid AttrsBuilder Source # | |
Defined in OpenTelemetry.Attributes Methods mempty :: AttrsBuilder # mappend :: AttrsBuilder -> AttrsBuilder -> AttrsBuilder # mconcat :: [AttrsBuilder] -> AttrsBuilder # | |
| Semigroup AttrsBuilder Source # | |
Defined in OpenTelemetry.Attributes Methods (<>) :: AttrsBuilder -> AttrsBuilder -> AttrsBuilder # sconcat :: NonEmpty AttrsBuilder -> AttrsBuilder # stimes :: Integral b => b -> AttrsBuilder -> AttrsBuilder # | |
attr :: ToAttribute a => Text -> a -> AttrsBuilder Source #
optAttr :: ToAttribute a => Text -> Maybe a -> AttrsBuilder Source #
Build an optional attribute entry. Nothing contributes nothing
to the builder (zero cost).
Since: 0.4.0.0
(.@) :: ToAttribute a => AttributeKey a -> a -> AttrsBuilder infixl 8 Source #
Build an attribute entry from a typed AttributeKey. Type-safe:
the value type must match the key's phantom type.
SC.http_request_method .@ (GET :: Text)
Since: 0.4.0.0
(.@?) :: ToAttribute a => AttributeKey a -> Maybe a -> AttrsBuilder infixl 8 Source #
Build an optional attribute entry from a typed AttributeKey.
Nothing contributes nothing to the builder.
Since: 0.4.0.0
buildAttrs :: AttrsBuilder -> AttributeMap Source #
Materialize a builder into an AttributeMap. Useful when a raw
HashMap is needed (e.g. for NewEvent attributes or SpanArguments).
Since: 0.4.0.0
Frozen (immutable) version of NewLink, stored on completed spans.
Created internally by freezing a NewLink; attributes are truncated per the
configured limits. See NewLink for full documentation on link semantics.
Since: 0.0.1.0
Constructors
| Link | |
Fields
| |
This is a link that is being added to a span which is going to be created.
A Span may be linked to zero or more other Spans (defined by SpanContext) that are causally related.
Links can point to Spans inside a single Trace or across different Traces. Links can be used to represent
batched operations where a Span was initiated by multiple initiating Spans, each representing a single incoming
item being processed in the batch.
Another example of using a Link is to declare the relationship between the originating and following trace. This can be used when a Trace enters trusted boundaries of a service and service policy requires the generation of a new Trace rather than trusting the incoming Trace context. The new linked Trace may also represent a long running asynchronous data processing operation that was initiated by one of many fast incoming requests.
When using the scatter/gather (also called fork/join) pattern, the root operation starts multiple downstream processing operations and all of them are aggregated back in a single Span. This last Span is linked to many operations it aggregates. All of them are the Spans from the same Trace. And similar to the Parent field of a Span. It is recommended, however, to not set parent of the Span in this scenario as semantically the parent field represents a single parent scenario, in many cases the parent Span fully encloses the child Span. This is not the case in scatter/gather and batch scenarios.
Since: 0.0.1.0
Constructors
| NewLink | |
Fields
| |
addLink :: MonadIO m => Span -> NewLink -> m () Source #
Add a link to a recording span.
Since: 0.0.1.0
Recording error information
recordException :: (MonadIO m, Exception e) => Span -> AttributeMap -> Maybe Timestamp -> e -> m () Source #
A specialized variant of addEvent that records attributes conforming to
the OpenTelemetry specification's
semantic conventions
Since: 0.0.1.0
recordError :: (MonadIO m, Exception e) => Span -> e -> m () Source #
Record an error and set the span status in one call.
Combines setStatus with Error and recordException. This is a common
pattern when handling errors outside of inSpan (which does this
automatically for uncaught exceptions).
case result of Left err -> recordError span err Right _ -> setStatus span Ok
Since: 0.4.1.0
setStatus :: MonadIO m => Span -> SpanStatus -> m () Source #
Sets the Status of the Span. If used, this will override the default Span status, which is Unset.
These values form a total order: Ok > Error > Unset. This means that setting Status with StatusCode=Ok will override any prior or future attempts to set span Status with StatusCode=Error or StatusCode=Unset.
Since: 0.0.1.0
data SpanStatus Source #
The status of a Span. This may be used to indicate the successful
completion of a span.
The default is Unset.
Ok is final: once a span's status is Ok, subsequent setStatus calls
are ignored. Error can be set from Unset, and Ok can override Error
(or Unset). Transitions: Unset -> Error, Unset -> Ok, Error -> Ok.
An Ord instance is provided (Ok > Error > Unset) for convenience but
does not govern status-setting precedence.
Since: 0.0.1.0
Constructors
| Unset | The default status. |
| Error Text | The operation contains an error. The text field may be empty, or else provide a description of the error. |
| Ok | The operation has been validated by an Application developer or Operator to have completed successfully. |
Instances
| Show SpanStatus Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods showsPrec :: Int -> SpanStatus -> ShowS # show :: SpanStatus -> String # showList :: [SpanStatus] -> ShowS # | |
| Eq SpanStatus Source # | |
Defined in OpenTelemetry.Internal.Trace.Types | |
| Ord SpanStatus Source # | Ok > Error > Unset. This ordering is for sorting/display; status-setting
precedence is handled by |
Defined in OpenTelemetry.Internal.Trace.Types Methods compare :: SpanStatus -> SpanStatus -> Ordering # (<) :: SpanStatus -> SpanStatus -> Bool # (<=) :: SpanStatus -> SpanStatus -> Bool # (>) :: SpanStatus -> SpanStatus -> Bool # (>=) :: SpanStatus -> SpanStatus -> Bool # max :: SpanStatus -> SpanStatus -> SpanStatus # min :: SpanStatus -> SpanStatus -> SpanStatus # | |
Exception handling
data ExceptionClassification Source #
How an exception should be treated by the tracing system when caught
by inSpan and similar bracket-style functions.
Since: 0.4.0.0
Constructors
| ErrorException | Set span status to |
| RecordedException | Record an exception event on the span, but do not set the span status
to |
| IgnoredException | Do not record an exception event and do not set the span status to
|
Instances
| Show ExceptionClassification Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods showsPrec :: Int -> ExceptionClassification -> ShowS # show :: ExceptionClassification -> String # showList :: [ExceptionClassification] -> ShowS # | |
| Eq ExceptionClassification Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods (==) :: ExceptionClassification -> ExceptionClassification -> Bool # (/=) :: ExceptionClassification -> ExceptionClassification -> Bool # | |
| Ord ExceptionClassification Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods compare :: ExceptionClassification -> ExceptionClassification -> Ordering # (<) :: ExceptionClassification -> ExceptionClassification -> Bool # (<=) :: ExceptionClassification -> ExceptionClassification -> Bool # (>) :: ExceptionClassification -> ExceptionClassification -> Bool # (>=) :: ExceptionClassification -> ExceptionClassification -> Bool # max :: ExceptionClassification -> ExceptionClassification -> ExceptionClassification # min :: ExceptionClassification -> ExceptionClassification -> ExceptionClassification # | |
data ExceptionResponse Source #
The result of classifying an exception via an ExceptionHandler.
Since: 0.4.0.0
Constructors
| ExceptionResponse | |
Fields
| |
type ExceptionHandler = SomeException -> Maybe ExceptionResponse Source #
A function that inspects a SomeException and optionally classifies it.
Returns Nothing to indicate this handler does not recognize the exception,
deferring to the next handler in the chain. Returns
to provide a classification and optional extra attributes.Just ExceptionResponse
Multiple handlers are chained: tracer-level handlers are consulted first,
then provider-level handlers. The first Just result wins. If all handlers
return Nothing, the default behavior (ErrorException with no extra
attributes) applies.
Since: 0.4.0.0
defaultExceptionResponse :: ExceptionResponse Source #
The default response when no handler matches: classify as ErrorException
with no additional attributes.
Since: 0.4.0.0
resolveException :: Tracer -> SomeException -> ExceptionResponse Source #
Resolve exception classification by consulting tracer-level handlers first,
then provider-level handlers. Returns defaultExceptionResponse if no handler
matches.
Since: 0.4.0.0
Completing Spans
Arguments
| :: MonadIO m | |
| => Span | |
| -> Maybe Timestamp | Optional |
| -> m () |
Signals that the operation described by this span has now (or at the time optionally specified) ended.
This does have any effects on child spans. Those may still be running and can be ended later.
This also does not inactivate the Span in any Context it is active in. It is still possible to use an ended span as parent via a Context it is contained in. Also, putting the Span into a Context will still work after the Span was ended.
Since: 0.0.1.0
Accessing other Span information
getSpanContext :: MonadIO m => Span -> m SpanContext Source #
When sending tracing information across process boundaries,
the SpanContext is used to serialize the relevant information.
Since: 0.0.1.0
isRecording :: MonadIO m => Span -> m Bool Source #
Returns whether the Span is currently recording.
A live Span created by this process returns True until endSpan is
called. A FrozenSpan (non-recording context-only wrapper, e.g. from
wrapSpanContext) and a Dropped span always return False.
Since: 0.0.1.0
isValid :: SpanContext -> Bool Source #
Returns True if the SpanContext has a non-zero TraceID and a non-zero SpanID.
Spec: "true if the SpanContext has a non-zero TraceID and a non-zero SpanID".
Since: 0.0.1.0
spanIsRemote :: MonadIO m => Span -> m Bool Source #
Returns True if the SpanContext was propagated from a remote parent,
When extracting a SpanContext through the Propagators API, isRemote MUST return True,
whereas for the SpanContext of any child spans it MUST return False.
Since: 0.0.1.0
Active span
withActiveSpan :: MonadIO m => (Span -> m ()) -> m () Source #
Run an action on the active span. If there is no active span in the current context, the action is silently skipped.
withActiveSpan $ \span -> do addAttribute span "user.id" (toAttribute userId) addEvent span (newEvent "cache-miss")
Since: 0.4.1.0
getActiveSpanContext :: MonadIO m => m (Maybe SpanContext) Source #
Retrieve the SpanContext of the active span, useful for log
correlation (extracting trace/span IDs) without needing the full Span
handle.
Since: 0.4.1.0
Event constructors
newEvent :: Text -> NewEvent Source #
Construct a NewEvent with just a name (no attributes, current timestamp).
addEvent span (newEvent "cache-miss")
Since: 0.4.1.0
newEventWith :: Text -> AttributeMap -> NewEvent Source #
Construct a NewEvent with a name and attributes (current timestamp).
addEvent span (newEventWith "retry" [("attempt", toAttribute retryCount)])
Since: 0.4.1.0
Utilities
Wall-clock timestamp stored as nanoseconds since Unix epoch. Matches the OTLP wire format directly (fixed64 nanoseconds).
Since: 0.0.1.0
Instances
| Read Timestamp Source # | |
| Show Timestamp Source # | |
| Eq Timestamp Source # | |
| Ord Timestamp Source # | |
getTimestamp :: MonadIO m => m Timestamp Source #
Sometimes, you may have a more accurate notion of when a traced
operation has ended. In this case you may call getTimestamp, and then
supply endSpan with the more accurate timestamp you have acquired.
When using the monadic interface, (such as inSpan, you may call
endSpan early to record the information, and the first call to endSpan will be honored.
Since: 0.0.1.0
timestampNanoseconds :: Timestamp -> Word64 Source #
Nanoseconds since the Unix epoch.
Since: 0.0.1.0
unsafeReadSpan :: MonadIO m => Span -> m ImmutableSpan Source #
Really only intended for tests, this function does not conform to semantic versioning .
Since: 0.0.1.0
whenSpanIsRecording :: MonadIO m => Span -> m () -> m () Source #
Run an action only when the span is recording. Use this to guard expensive attribute computation that would be wasted on non-recording spans.
Since: 0.0.1.0
codeAttributes :: StabilityOpt -> String -> SrcLoc -> AttributeMap Source #
ownCodeAttributes :: HasCallStack => AttributeMap Source #
Creates source code attributes describing the caller of the current function. You should use this if you are getting source code attributes from inside a function that is creating a span.
Respects OTEL_SEMCONV_STABILITY_OPT_IN=code to select stable vs legacy attribute names.
Note: this will return nothing if the call stack is frozen.
callerAttributes :: HasCallStack => AttributeMap Source #
Creates source code attributes describing where the current function is called. You should use this if you are getting source code attributes from inside a "span creation" function.
Respects OTEL_SEMCONV_STABILITY_OPT_IN=code to select stable vs legacy attribute names.
Note: this will return nothing if the call stack is frozen.
addAttributesToSpanArguments :: AttributeMap -> SpanArguments -> SpanArguments Source #
Attributes are added to the end of the span argument list, so will be discarded if the number of attributes in the span exceeds the limit.
Limits
data SpanLimits Source #
Configurable limits on span attributes, events, and links.
Spec: https://opentelemetry.io/docs/specs/otel/trace/sdk/#span-limits
Since: 0.0.1.0
Constructors
| SpanLimits | |
Instances
| Show SpanLimits Source # | |
Defined in OpenTelemetry.Internal.Trace.Types Methods showsPrec :: Int -> SpanLimits -> ShowS # show :: SpanLimits -> String # showList :: [SpanLimits] -> ShowS # | |
| Eq SpanLimits Source # | |
Defined in OpenTelemetry.Internal.Trace.Types | |
defaultSpanLimits :: SpanLimits Source #
Since: 0.0.1.0
bracketError :: MonadUnliftIO m => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c Source #
Like bracket, but provides the after function with information about
uncaught exceptions.
Since: 0.1.0.0