Copyright | (c) Ian Duncan 2021 |
---|---|
License | BSD-3 |
Maintainer | Ian Duncan |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Trace and Span Id generation
No Aeson instances are provided since they've got the potential to be transport-specific in format. Use newtypes for serialisation instead.
Synopsis
- data TraceId
- newTraceId :: MonadIO m => IdGenerator -> m TraceId
- isEmptyTraceId :: TraceId -> Bool
- traceIdBytes :: TraceId -> ByteString
- bytesToTraceId :: ByteString -> Either String TraceId
- baseEncodedToTraceId :: Base -> ByteString -> Either String TraceId
- traceIdBaseEncodedBuilder :: Base -> TraceId -> Builder
- traceIdBaseEncodedByteString :: Base -> TraceId -> ByteString
- traceIdBaseEncodedText :: Base -> TraceId -> Text
- data SpanId
- newSpanId :: MonadIO m => IdGenerator -> m SpanId
- isEmptySpanId :: SpanId -> Bool
- spanIdBytes :: SpanId -> ByteString
- bytesToSpanId :: ByteString -> Either String SpanId
- data Base = Base16
- baseEncodedToSpanId :: Base -> ByteString -> Either String SpanId
- spanIdBaseEncodedBuilder :: Base -> SpanId -> Builder
- spanIdBaseEncodedByteString :: Base -> SpanId -> ByteString
- spanIdBaseEncodedText :: Base -> SpanId -> Text
Working with TraceId
s
A valid trace identifier is a 16-byte array with at least one non-zero byte.
Instances
IsString TraceId Source # | |
Defined in OpenTelemetry.Internal.Trace.Id fromString :: String -> TraceId # | |
Generic TraceId Source # | |
Show TraceId Source # | |
Eq TraceId Source # | |
Ord TraceId Source # | |
Defined in OpenTelemetry.Internal.Trace.Id | |
Hashable TraceId Source # | |
Defined in OpenTelemetry.Internal.Trace.Id | |
type Rep TraceId Source # | |
Defined in OpenTelemetry.Internal.Trace.Id type Rep TraceId = D1 ('MetaData "TraceId" "OpenTelemetry.Internal.Trace.Id" "hs-opentelemetry-api-0.2.0.0-2Szn2AZ2vnoHm5uYEjNBGv" 'True) (C1 ('MetaCons "TraceId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ShortByteString))) |
Creating TraceId
s
newTraceId :: MonadIO m => IdGenerator -> m TraceId Source #
Generate a TraceId
using the provided IdGenerator
This function is generally called by the hs-opentelemetry-sdk
,
but may be useful in some testing situations.
Since: 0.1.0.0
Checking TraceId
s for validity
isEmptyTraceId :: TraceId -> Bool Source #
Check whether all bytes in the TraceId
are zero.
Since: 0.1.0.0
Encoding / decoding TraceId
from bytes
traceIdBytes :: TraceId -> ByteString Source #
Access the byte-level representation of the provided TraceId
Since: 0.1.0.0
bytesToTraceId :: ByteString -> Either String TraceId Source #
Convert a ByteString
to a TraceId
. Will fail if the ByteString
is not exactly 16 bytes long.
Since: 0.1.0.0
Encoding / decoding TraceId
from a given Base
encoding
baseEncodedToTraceId :: Base -> ByteString -> Either String TraceId Source #
Convert a ByteString
of a specified base-encoding into a TraceId
.
Will fail if the decoded value is not exactly 16 bytes long.
Since: 0.1.0.0
traceIdBaseEncodedByteString :: Base -> TraceId -> ByteString Source #
Output a TraceId
into a base-encoded ByteString
.
Since: 0.1.0.0
Working with SpanId
s
A valid span identifier is an 8-byte array with at least one non-zero byte.
Creating SpanId
s
newSpanId :: MonadIO m => IdGenerator -> m SpanId Source #
Generate a SpanId
using the provided IdGenerator
This function is generally called by the hs-opentelemetry-sdk
,
but may be useful in some testing situations.
Since: 0.1.0.0
Checking SpanId
s for validity
isEmptySpanId :: SpanId -> Bool Source #
Check whether all bytes in the SpanId
are zero.
Since: 0.1.0.0
Encoding / decoding SpanId
from bytes
spanIdBytes :: SpanId -> ByteString Source #
Access the byte-level representation of the provided SpanId
Since: 0.1.0.0
bytesToSpanId :: ByteString -> Either String SpanId Source #
Convert a ByteString
of a specified base-encoding into a SpanId
.
Will fail if the decoded value is not exactly 8 bytes long.
Since: 0.1.0.0
Encoding / decoding SpanId
from a given Base
encoding
The different bases that can be used.
See RFC4648 for details. In particular, Base64 can be standard or URL-safe. URL-safe encoding is often used in other specifications without padding characters.
RFC 2045 defines a separate Base64 encoding, which is not supported. This format requires a newline at least every 76 encoded characters, which works around limitations of older email programs that could not handle long lines. Be aware that other languages, such as Ruby, encode the RFC 2045 version by default. To decode their output, remove all newlines before decoding.
Examples
A quick example to show the differences:
>>>
let input = "Is 3 > 2?" :: ByteString
>>>
let convertedTo base = convertToBase base input :: ByteString
>>>
convertedTo Base16
"49732033203e20323f">>>
convertedTo Base32
"JFZSAMZAHYQDEPY=">>>
convertedTo Base64
"SXMgMyA+IDI/">>>
convertedTo Base64URLUnpadded
"SXMgMyA-IDI_">>>
convertedTo Base64OpenBSD
"QVKeKw.8GBG9"
Base16 | similar to hexadecimal |
baseEncodedToSpanId :: Base -> ByteString -> Either String SpanId Source #
Convert a ByteString
of a specified base-encoding into a SpanId
.
Will fail if the decoded value is not exactly 8 bytes long.
Since: 0.1.0.0
spanIdBaseEncodedByteString :: Base -> SpanId -> ByteString Source #
Output a SpanId
into a base-encoded ByteString
.
Since: 0.1.0.0