OpenTelemetryAPI
The content in this page is organized in the same order as the OpenTelemetry Specification.
Context
All the MUST items in the original specification are implemented.
Context
is implemented as a wrapper of NamedTuple
, which means it is immutable. Each Task
has exactly ONE Context
instance, which is injected into the task_local_storage
of the current_task
by the parent task automatically.
Type piracy is used to the propagate context between tasks. See more discussions in #32
create_key
is used to create a context key. But it is not exported yet because it seems to be only used internally until now.
Base.getindex(::Context, key)
is implemented so to get a value in a Context
, one can simply call ctx[key]
to get the associated value of a key in a ctx
.
Setting value of a Context
is not directly supported. Given that Context
is immutable, updating an immutable object in Julia seems strange. We provide the with_context
function to create a new context based on the key-value pairs in the current_context
. This syntax is more common than the attach/detach operations in the original specification.
OpenTelemetryAPI.current_context
— MethodReturn the Context
associated with the caller's current execution unit.
OpenTelemetryAPI.with_context
— Methodwith_context(f, [context]; kv...)
Run function f
in the context
. If extra kv
pairs are provided, they will be merged with the context
to form a new context. When context
is not provided, the current_context
will be used.
Propagators
inject_context!
and extract_context
are provided based on the original specification.
The GLOBAL_PROPAGATOR
is set to a CompositePropagator
, with multiple dispatch, each inner propagator can be customized to handle different contexts and carriers. Since it's mainly used internally for now, it's not exposed yet.
OpenTelemetryAPI.TraceContextTextMapPropagator
— TypeTraceContextTextMapPropagator()
This propagator follows the W3C format
Trace
The relationship between trace provider, tracer, span context and span is depicted below:
┌────────────────────────────┐
│ AbstractSpan │
│ ┌──────────────────────┐ │
│ │ Tracer │ │
│ │ ┌────────────────┐ │ │
│ │ │ Abstract │ │ │
│ │ │ TracerProvider │ │ │
│ │ └────────────────┘ │ │
│ │ instrumentation │ │
│ │ ┌────────────────┐ │ │
│ │ │ name │ │ │
│ │ │ version │ │ │
│ │ └────────────────┘ │ │
│ └──────────────────────┘ │
└────────────────────────────┘
In OpenTelemetryAPI.jl
, only one concrete AbstractTracerProvider
(the DummyTracerProvider
) is provided. It is set as the default global_tracer_provider
. Without SDK installed, the with_span
will only create a NonRecordingSpan
. This is to make the OpenTelemetryAPI.jl
lightweight enough so that instrumentation package users can happily add it as a dependency without losing performance.
OpenTelemetryAPI.AbstractSpan
— TypeEach concrete span should have the following interfaces implemented.
OpenTelemetryAPI.Tracer
— TypeTracer(;instrumentation_scope=InstrumentationScope(), provider=global_meter_provider())
OpenTelemetryAPI.attributes
— Methodattributes(s::AbstractSpan)
A BoundedAttributes
is expected.
Do not modify the returned attributes directly. Users should always modify attributes through (s::AbstractSpan)[key]=val
because it will check the is_recording(s)
first.
OpenTelemetryAPI.end_span!
— Methodend_span!([s=current_span()], [t=UInt(time()*10^9)])
Set the end time of the span and trigger span processors. Note t
is the nanoseconds.
OpenTelemetryAPI.global_tracer_provider
— Methodglobal_tracer_provider(p)
Set the global tracer provider to p
.
OpenTelemetryAPI.global_tracer_provider
— Methodglobal_tracer_provider()
Get the global tracer provider.
OpenTelemetryAPI.is_recording
— MethodOpenTelemetryAPI.parent_span_context
— Methodparent_span_context(s::AbstractSpan)
Get the SpanContext
from parent span.
OpenTelemetryAPI.provider
— Methodprovider(s::AbstractSpan)
Get the AbstractTracerProvider
which generates the tracer that the span s
resides in.
OpenTelemetryAPI.resource
— Methodresource(s::AbstractSpan)
Get the associated resource of the span s
. Fall back to resource(provider(::AbstractSpan))
OpenTelemetryAPI.span_context
— Methodspan_context([s::AbstractSpan])
Get the SpanContext
from a span s
. If s
is not specified, current_span()
will be used. nothing
is returned if no span context found.
OpenTelemetryAPI.span_events
— Methodspan_events(s::AbstractSpan)
Get the recorded events in a span.
OpenTelemetryAPI.span_kind
— Methodspan_kind([current_span()])
Return SpanKind
OpenTelemetryAPI.span_links
— Methodspan_links(s::AbstractSpan)
Get the recorded links in a span.
OpenTelemetryAPI.span_name!
— Methodspan_name!([current_span()], name::String)
OpenTelemetryAPI.span_name
— Methodspan_name([current_span()])
OpenTelemetryAPI.span_status!
— Methodspan_status!([current_span()], code::SpanStatusCode, description=nothing)
Update the status of span s
by following the original specification. description
is only considered when the code
is SPAN_STATUS_ERROR
. Only valid when the span is not ended yet.
OpenTelemetryAPI.span_status
— Methodspan_status([current_span()])
Get status of the span. A SpanStatusCode
is returned.
OpenTelemetryAPI.tracer
— Methodtracer(s::AbstractSpan)
Get the Tracer
which generates the span s
.
OpenTelemetryAPI.with_span
— Functionwith_span(f, name::String, [tracer=Tracer()]; kw...)
Call function f
with the current span set a newly created one of name
with tracer
.
Keyword arguments
end_on_exit=true
, controls whether to callend_span!
afterf
or not.record_exception=true
, controls whether to record the exception.set_status_on_exception=true
, decides whether to set status toSPAN_STATUS_ERROR
automatically when an exception is caught.- The rest keyword arguments are forwarded to
create_span
.
OpenTelemetryAPI.with_span
— Methodwith_span(f, s::AbstractSpan; kw...)
Call function f
with the provided span s
.
Keyword arguments
end_on_exit=true
, controls whether to callend_span!
afterf
or not.record_exception=true
, controls whether to record the exception.set_status_on_exception=true
, decides whether to set status toSPAN_STATUS_ERROR
automatically when an exception is caught.
Metric
The relationship between MeterProvider
, Meter
and different instruments are depicted below:
┌─────────────────────────────┐
│AbstractInstrument │
│ │
│ name │
│ unit │
│ description │
│ │
│ meter │
│ ┌───────────────────────┐ │
│ │Meter │ │
│ │ │ │
│ │ provider │ │
│ │ ┌────────────────┐ │ │
│ │ │ Abstract │ │ │
│ │ │ MeterProvider │ │ │
│ │ └────────────────┘ │ │
│ │ name │ │
│ │ version │ │
│ │ schema_url │ │
│ │ │ │
│ │ instrumentation │ │
│ │ ┌────────────────┐ │ │
│ │ │ name │ │ │
│ │ │ version │ │ │
│ │ └────────────────┘ │ │
│ │ instruments │ │
│ │ │ │
│ │ * Counter │ │
│ │ * Histogram │ │
│ │ * UpDownCounter │ │
│ │ * ObservableCounter│ │
│ │ * Observable │ │
│ │ UpDownCounter │ │
│ └───────────────────────┘ │
│ │
└─────────────────────────────┘
- An
Instrument
belongs to aMeter
, eachMeter
may contain many differentInstrument
s. Similarly, aMeter
belongs to aMeterProvider
and aMeterProvider
may contain many differentMeter
s.
OpenTelemetryAPI.Meter
— TypeMeter(name::String;kw...)
Meter is responsible for creating instruments.
Keyword Arguments:
provider::P = global_meter_provider()
instrumentation_scope = InstrumentationScope()
OpenTelemetryAPI.global_meter_provider
— Methodglobal_meter_provider(p)
Set the global meter provider to p
.
OpenTelemetryAPI.global_meter_provider
— Methodglobal_meter_provider()
Get the global meter provider.
Instruments
All instruments provided here can be classified into two categories: AbstractSyncInstrument
and AbstractAsyncInstrument
.
OpenTelemetryAPI.Counter
— TypeCounter{T}(name, meter;unit="", description="") where T
Counter
is a AbstractSyncInstrument
which supports non-negative increments.
See more details from the specification.
OpenTelemetryAPI.Histogram
— TypeHistogram{T}(name, meter; unit = "", description = "") where {T}
Histogram
is an AbstractSyncInstrument
which can be used to report arbitrary values that are likely to be statistically meaningful. It is intended for statistics such as histograms, summaries, and percentile.
See more details from the specification
OpenTelemetryAPI.Measurement
— TypeMeasurement(value, [attributes=BoundedAttributes()])
This is to follow the specification
See also BoundedAttributes
OpenTelemetryAPI.ObservableCounter
— TypeObservableCounter{T}(callback, name, meter; unit = "", description = "") where {T}
ObservableCounter
is an AbstractAsyncInstrument
which reports monotonically increasing value(s) when the instrument is being observed.
See more details from the specification
OpenTelemetryAPI.ObservableGauge
— TypeObservableGauge{T}(callback, name, meter; unit = "", description = "",) where {T}
ObservableGauge
is an AbstractAsyncInstrument
which reports non-additive value(s) (e.g. the room temperature - it makes no sense to report the temperature value from multiple rooms and sum them up) when the instrument is being observed.
See also the details from the specification
OpenTelemetryAPI.ObservableUpDownCounter
— TypeObservableUpDownCounter{T}(callback, name, meter; unit = "", description = "") where {T}
ObservableUpDownCounter
is an AbstractAsyncInstrument
which reports additive value(s) (e.g. the process heap size - it makes sense to report the heap size from multiple processes and sum them up, so we get the total heap usage) when the instrument is being observed.
See more details from the specification.
OpenTelemetryAPI.UpDownCounter
— TypeUpDownCounter{T}(name, meter; unit = "", description = "") where {T}
UpDownCounter
is a AbstractSyncInstrument
which supports increments and decrements.
See also the details from the specification.
Logging
The idea is simple, a OtelLogTransformer
is provided to transform each logging message into a LogRecord
. To understand how to use it, users should be familiar with how TransformerLogger from LoggingExtras.jl works.
OpenTelemetryAPI.LogRecord
— TypeLogRecord(;kw...)
A Julia representation of the Log Data Model.
OpenTelemetryAPI.OtelLogTransformer
— TypeOtelLogTransformer(resource::Resource)
It can be used as a function f
to the TransformerLogger
. After applying this transformer, a LogRecord
will be returned.
Misc
OpenTelemetryAPI.TAttrVal
— TypeValid type of attribute value.
OpenTelemetryAPI.AbstractAsyncInstrument
— TypeAsync instrument usually has a callback function (which is named Observable in OpenTelemetry) to get its measurement.
If the return of the callback function is not a Measurement
, it will be converted into a Measurement
with an empty BoundedAttributes
implicitly when being uploaded to the associated meter provider.
OpenTelemetryAPI.AbstractInstrument
— TypeAbstractInstrument
is the super type of all instruments, which are used to report [
Measurement`](@ref)s.
Each concrete subtype should at least have the following fields:
name
description
unit
meter
, the associatedMeter
See also the specification:
OpenTelemetryAPI.AbstractMeterProvider
— TypeA meter provider defines how to collect and update Measurement
s. Each meter provider should have the following interfaces implemented:
Base.push!(provider, m::Meter)
, register a meter.Base.push!(provider, ins::AbstractInstrument)
, register an instrument.Base.push!(provider, (ins::AbstractInstrument, m::Measurement))
, update a measurement.
OpenTelemetryAPI.AbstractSyncInstrument
— TypeSync instrument usually pass its measurement immediately.
OpenTelemetryAPI.AbstractTracerProvider
— TypeA tracer provider is a part of an Tracer
. For each concrete tracer provider, resource
and OpenTelemetryAPI.create_span(name::String, tracer::Tracer{<:YourCustomProvider})
should also be implemented.
OpenTelemetryAPI.BoundedAttributes
— TypeBoundedAttributes(attrs; count_limit=nothing, value_length_limit=nothing)
This provides a wrapper around attributes (typically AbstractDict
or NamedTuple
) to follow the specification of Attribute.
The following methods from Base
are defined on BoundedAttributes
which are then forwarded to the inner attrs
by default. Feel free to create a PR if you find any method you need is missing:
Base.getindex
Base.setindex!
Base.iterate
Base.length
Base.haskey
Base.push!
. Obviously, an error will be thrown when calling on immutableattrs
s likeNamedTuple
.
OpenTelemetryAPI.CompositePropagator
— TypeCompositePropagator(propagators::Vector)
OpenTelemetryAPI.Event
— TypeEvent(name, attributes; timestamp=time()*10^9)
timestamp
is the nanoseconds.
OpenTelemetryAPI.InstrumentationScope
— TypeInstrumentationScope(;name="OpenTelemetryAPI", version=<default>, schema_url="", attributes=BoundedAttributes())
Usually used in an instrumentation package.
OpenTelemetryAPI.LimitInfo
— TypeLimitInfo(;kw...)
Used in TracerProvider
to configure generated Tracer
.
OpenTelemetryAPI.Link
— TypeLink(span_context, attributes)
See more details at links between spans.
OpenTelemetryAPI.Resource
— TypeResource(;attributes=nothing, schema_url="", default_attributes=OTEL_RESOURCE_ATTRIBUTES())
Quoted from the specification:
Resource captures information about the entity for which telemetry is recorded. For example, metrics exposed by a Kubernetes container can be linked to a resource that specifies the cluster, namespace, pod, and container name.
Resource may capture an entire hierarchy of entity identification. It may describe the host in the cloud and specific container or an application running in the process.
OpenTelemetryAPI.SpanContext
— TypeSpanContext(;span_id, trace_id, is_remote, trace_flag=TraceFlag(), trace_state=TraceState())
A SpanContext
represents the portion of a Span
which must be serialized and propagated along side of a distributed context. SpanContext
s are immutable.
The OpenTelemetry SpanContext
representation conforms to the W3C TraceContext specification. It contains two identifiers - a TraceId
and a SpanId
- along with a set of common TraceFlags
and system-specific TraceState
values.
TraceId
A valid trace identifier is a 16-byte array with at least one non-zero byte.
SpanId
A valid span identifier is an 8-byte array with at least one non-zero byte.
TraceFlags
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.
TraceState
carries vendor-specific trace identification data, represented as a list of key-value pairs. TraceState allows multiple tracing systems to participate in the same trace. It is fully described in the W3C Trace Context specification.
OpenTelemetryAPI.SpanStatus
— TypeSpanStatus(code, description=nothing)
Possible codes are:
SPAN_STATUS_UNSET
SPAN_STATUS_ERROR
SPAN_STATUS_OK
description
is required when code
is SPAN_STATUS_ERROR
.
OpenTelemetryAPI.TraceState
— TypeTraceState(entries::Pair{String,String}...)
TraceState
carries vendor-specific trace identification data, represented as a list of key-value pairs. TraceState
allows multiple tracing systems to participate in the same trace. It is fully described in the W3C Trace Context specification.
Base.getindex
— MethodBase.getindex(s::AbstractSpan, key)
Look up key
in the attributes of the span s
.
Base.haskey
— MethodBase.haskey(s::AbstractSpan, key)
Check if the span s
has the key in its attributes.
Base.push!
— MethodBase.push!([s::AbstractSpan], event::Event)
Add an Event
into the span s
.
Base.push!
— MethodBase.push!([current_span()], link::Link)
Add a Link
into the span s
.
Base.push!
— MethodBase.push!(s::AbstractSpan, ex::Exception; is_rethrow_followed = false)
A specialized variant of Event
to record exceptions. Usually used in a try... catch...end
to capture the backtrace. If the ex
is rethrow
ed in the catch...end
, is_rethrow_followed
should be set to true
.
Base.setindex!
— Method(s::AbstractSpan)[key] = val
Set the attributes in span s
. Only valid when the span is not ended yet.
OpenTelemetryAPI.OTEL_ATTRIBUTE_COUNT_LIMIT
— MethodMaximum allowed span attribute count
OpenTelemetryAPI.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT
— MethodMaximum allowed attribute value size
OpenTelemetryAPI.OTEL_BLRP_EXPORT_TIMEOUT
— MethodMaximum allowed time (in milliseconds) to export data
OpenTelemetryAPI.OTEL_BLRP_MAX_EXPORT_BATCH_SIZE
— MethodMaximum batch size Must be less than or equal to OTELBLRPMAXQUEUESIZE
OpenTelemetryAPI.OTEL_BLRP_MAX_QUEUE_SIZE
— MethodMaximum queue size
OpenTelemetryAPI.OTEL_BLRP_SCHEDULE_DELAY
— MethodDelay interval (in milliseconds) between two consecutive exports
OpenTelemetryAPI.OTEL_BSP_EXPORT_TIMEOUT
— MethodMaximum allowed time (in milliseconds) to export data
OpenTelemetryAPI.OTEL_BSP_MAX_EXPORT_BATCH_SIZE
— MethodMaximum batch size
Must be less than or equal to OTELBSPMAXQUEUESIZE
OpenTelemetryAPI.OTEL_BSP_MAX_QUEUE_SIZE
— MethodMaximum queue size
OpenTelemetryAPI.OTEL_BSP_SCHEDULE_DELAY
— MethodDelay interval (in milliseconds) between two consecutive exports
OpenTelemetryAPI.OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT
— MethodMaximum allowed attribute per span event count
OpenTelemetryAPI.OTEL_EXPORTER_PROMETHEUS_HOST
— MethodHost used by the Prometheus exporter
OpenTelemetryAPI.OTEL_EXPORTER_PROMETHEUS_PORT
— MethodPort used by the Prometheus exporter
OpenTelemetryAPI.OTEL_LINK_ATTRIBUTE_COUNT_LIMIT
— MethodMaximum allowed attribute per span link count
OpenTelemetryAPI.OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT
— MethodMaximum allowed log record attribute count
OpenTelemetryAPI.OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT
— MethodMaximum allowed attribute value size
OpenTelemetryAPI.OTEL_LOGS_EXPORTER
— MethodLogs exporter to be used
OpenTelemetryAPI.OTEL_LOG_LEVEL
— MethodLog level used by the SDK logger.
OpenTelemetryAPI.OTEL_METRICS_EXEMPLAR_FILTER
— MethodFilter for which measurements can become Exemplars.
OpenTelemetryAPI.OTEL_METRICS_EXPORTER
— MethodMetrics exporter to be used
OpenTelemetryAPI.OTEL_METRIC_EXPORT_INTERVAL
— MethodThe time interval (in milliseconds) between the start of two export attempts.
OpenTelemetryAPI.OTEL_METRIC_EXPORT_TIMEOUT
— MethodMaximum allowed time (in milliseconds) to export data.
OpenTelemetryAPI.OTEL_PROPAGATORS
— MethodPropagators to be used as a comma-separated list .
Values MUST be deduplicated in order to register a Propagator
only once.
OpenTelemetryAPI.OTEL_RESOURCE_ATTRIBUTES
— MethodKey-value pairs to be used as resource attributes.
See Resource SDK for more details.
OpenTelemetryAPI.OTEL_SDK_DISABLED
— MethodDisable the SDK for all signals.
Boolean value. If "true", a no-op SDK implementation will be used for all telemetry signals. Any other value or absence of the variable will have no effect and the SDK will remain enabled. This setting has no effect on propagators configured through the OTEL_PROPAGATORS variable.
OpenTelemetryAPI.OTEL_SERVICE_NAME
— MethodSets the value of the service.name
resource attribute.
If service.name
is also provided in OTEL_RESOURCE_ATTRIBUTES
, then OTEL_SERVICE_NAME
takes precedence.
OpenTelemetryAPI.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
— MethodMaximum allowed span attribute count
OpenTelemetryAPI.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT
— MethodMaximum allowed attribute value size
OpenTelemetryAPI.OTEL_SPAN_EVENT_COUNT_LIMIT
— MethodMaximum allowed span event count
OpenTelemetryAPI.OTEL_SPAN_LINK_COUNT_LIMIT
— MethodMaximum allowed span link count
OpenTelemetryAPI.OTEL_TRACES_EXPORTER
— MethodTrace exporter to be used
OpenTelemetryAPI.OTEL_TRACES_SAMPLER
— MethodSampler to be used for traces.
See Sampling
OpenTelemetryAPI.OTEL_TRACES_SAMPLER_ARG
— MethodString value to be used as the sampler argument.
The specified value will only be used if OTELTRACESSAMPLER is set. Each Sampler type defines its own expected input, if any. Invalid or unrecognized input MUST be logged and MUST be otherwise ignored, i.e. the SDK MUST behave as if OTELTRACESSAMPLER_ARG is not set.
OpenTelemetryAPI.clean_attrs!
— MethodFollow the specification on Attribute Limits. The cleaned attributes and the number of dropped elements is returned.
If attrs
is mutable, it may be modified in-place.
OpenTelemetryAPI.create_span
— MethodHere we follow the Behavior of the API in the absence of an installed SDK.
OpenTelemetryAPI.current_span
— Methodcurrent_span([current_context])
Get the span in the current context.
OpenTelemetryAPI.end_time
— Methodend_time(s::AbstractSpan)
Get the end time of span s
in nanoseconds.
OpenTelemetryAPI.extract_attrs
— MethodTurn "a=b,c=d"
into a NamedTuple
OpenTelemetryAPI.extract_context
— Methodextract_context(carrier, [global_propagator], [current_context])
Extracts the value from an incoming request. For example, from the headers of an HTTP request.
OpenTelemetryAPI.inject_context!
— Methodinject(carrier, [global_propagator], [current_context])
Injects the value into a carrier. For example, into the headers of an HTTP request.
OpenTelemetryAPI.n_dropped
— Methodn_dropped(x::BoundedAttributes)
Return the total number of dropped elements since creation.
OpenTelemetryAPI.start_time
— Methodstart_time(s::AbstractSpan)
Get the start time of span s
in nanoseconds.