OpenTelemetrySDK
Exporters
Two common exporters are provided to for debugging:
OpenTelemetrySDK.ConsoleExporter
— TypeConsoleExporter(;io=stdout)
Print an AbstractSpan
or Metric
into io
.
OpenTelemetrySDK.InMemoryExporter
— TypeInMemoryExporter(;pool=[], is_closed=false)
Simply store all export!
ed elements into the pool
.
Tracer
TracerProvider
In SDK, TracerProvider
and Span
are provided to replace the dummy ones in API. Span
is not exported since we mainly use with_span
to create new spans.
OpenTelemetrySDK.TracerProvider
— TypeTracerProvider(;kw...)
Keyword Arguments
sampler
::AbstractSampler
=DEFAULT_ON
resource
=Resource
()span_processor
::AbstractSpanProcessor
=SimpleSpanProcessor
(ConsoleExporter
)id_generator
::AbstractIdGenerator
=RandomIdGenerator
()limit_info
=LimitInfo
()
The following extra methods are provided beyond those defined in AbstractTracerProvider
:
ID Generators
OpenTelemetrySDK.RandomIdGenerator
— TypeRandomIdGenerator(rng=Random.GLOBAL_RNG)
Use the rng
to generate a random trace id or span id.
Samplers
OpenTelemetrySDK.ALWAYS_OFF
— ConstantAlways drop the span.
OpenTelemetrySDK.ALWAYS_ON
— ConstantAlways sample the span.
OpenTelemetrySDK.DEFAULT_OFF
— ConstantSampler that respects its parent span's sampling decision, but otherwise never samples.
OpenTelemetrySDK.DEFAULT_ON
— ConstantSampler that respects its parent span's sampling decision, but otherwise always samples.
Span Processors
OpenTelemetrySDK.BatchSpanProcessor
— TypeBatchSpanProcessor(exporter;kw...)
Keyword arguments
max_queue_size
scheduled_delay_millis
export_timeout_millis
max_export_batch_size
The default values of above keyword arugments are read from corresponding environment variables.
OpenTelemetrySDK.CompositSpanProcessor
— TypeCompositSpanProcessor(processors...)
A wrapper of different concrete span processors. Users can also push!
new span processors into it after construction. See also SimpleSpanProcessor
.
OpenTelemetrySDK.SimpleSpanProcessor
— TypeSimpleSpanProcessor(exporter)
Export each span immediately when on_end!
is called on this processor.
Metric
The current implementation of metrics in SDK is mainly inspired by the dotnet sdk.
┌──────────────────────────────────────────┐
│MeterProvider │
│ │
│ meters │
│ views │
│ │
│ instrument_associated_metric_names │
│ instrument => Set{metric_name} │
│ │
│ metrics │
│ name => metric │
│ ┌───────────────────────────────────┐ │
│ │Metric │ │
│ │ │ │
│ │ name │ │
│ │ description │ │
│ │ criteria │ │
│ │ aggregation │ │
│ │ ┌──────────────────────────┐ │ │
│ │ │AggregationStore │ │ │
│ │ │ │ │ │
│ │ │ attributes => data_point│ │ │
│ │ │ ┌─────────────────┐ │ │ │
│ │ │ │AbstractDataPoint│ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ value │ │ │ │
│ │ │ │ start_time │ │ │ │
│ │ │ │ end_time │ │ │ │
│ │ │ │ exemplars │ │ │ │
│ │ │ │ ┌────────────┐ │ │ │ │
│ │ │ │ │Exemplar │ │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ │ │ value │ │ │ │ │
│ │ │ │ │ trace_id │ │ │ │ │
│ │ │ │ │ span_id │ │ │ │ │
│ │ │ │ └────────────┘ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ └─────────────────┘ │ │ │
│ │ │ │ │ │
│ │ └──────────────────────────┘ │ │
│ │ │ │
│ └───────────────────────────────────┘ │
│ │
└──────────────────────────────────────────┘
A View
specifies which instruments are grouped together through Criteria
. For each view, a Metric
is created to store the Measurement
s. Each metric may have many different dimensions configured by BoundedAttributes
in a Measurement
. For each dimension, we may also collect those Exemplar
s in the mean while.
Design decisions
- For each registered instrument, we have stored the associated metrics configured by views into the
instrument_associated_metric_names
field. So that for each pair ofinstrument => measurement
, we can quickly determine which metrics to update. - To make sure that measurements of the same attribute key-values but with different order can be updated in the same dimension in the
AggregationStore
, a design from opentelemetry-dotnet#2374 is borrowed here.
OpenTelemetrySDK.DROP
— ConstantAll measurement will be dropped.
OpenTelemetrySDK.Exemplar
— TypeExemplar(;kw...)
Exemplars are example data points for aggregated data. Read the specification to understand its relation to trace and metric.
Keyword arguments:
value
time_unix_nano
filtered_attributes
, extra attributes of aMeasurement
that are not included in aMetric
's:attribute_keys
field.trace_id
, thetrace_id
in the span context when the measurement happens.span_id
, thespan_id
in the span context when the measurement happens.
OpenTelemetrySDK.HistogramAgg
— TypeHistogramAgg(args...)
Arguments:
boundaries::NTuple{M, Float64} where M
, the boundaries to calculate histogram buckets. Note that-Inf
andInf
shouldn't be included.is_record_min
is_record_max
agg_store
exemplar_reservoir_factory
, when set tonothing
, no exemplar will be stored.
OpenTelemetrySDK.HistogramAgg
— MethodHistogramAgg{T}(;boundaries = DEFAULT_HISTOGRAM_BOUNDARIES, is_record_min = true, is_record_max = true)
OpenTelemetrySDK.LastValueAgg
— TypeLastValueAgg(agg_store::AggregationStore, exemplar_reservoir_factory)
When exemplar_reservoir_factory
set to nothing
, no exemplar will be stored.
See more details in the specification.
OpenTelemetrySDK.LastValueAgg
— MethodLastValueAgg{T}()
OpenTelemetrySDK.SumAgg
— TypeSumAgg(agg_store::AggregationStore, exemplar_reservoir_factory)
When exemplar_reservoir_factory
set to nothing
, no exemplar will be stored. See more details in the specification.
OpenTelemetrySDK.SumAgg
— MethodSumAgg{T}()
OpenTelemetrySDK.MeterProvider
— MethodMeterProvider(;resource = Resource(), views = View[], max_metrics = nothing)
If views
is empty, a default one (View(;instrument_name="*")
) will be added to enable all metrics.
OpenTelemetrySDK.metrics
— Methodmetrics([global_meter_provider()])
OpenTelemetrySDK.View
— TypeView(name=nothing;kwargs...)
The name
support wildcard.
See more details in the specification.
Keyword arguments
description = nothing
,attribute_keys = nothing
,extra_dimensions = BoundedAttributes()
,aggregation = nothing
,instrument_name = nothing
,instrument_type = nothing
,meter_name = nothing
,meter_version = nothing
,meter_schema_url = nothing
,
Misc
OpenTelemetrySDK.AbstractExporter
— TypeAn AbstractExporter
is to export a collection of AbstractSpan
s and (or) Metric
s. Each method should have the following interfaces implemented:
OpenTelemetrySDK.AbstractIdGenerator
— TypeCustomized id generators must implement the following two methods:
generate_span_id(::AbstractIdGenerator)
generate_trace_id(::AbstractIdGenerator)
OpenTelemetrySDK.AbstractMetricReader
— TypeAll metric readers should implement close(::AbstractMetricReader)
and (r::AbstractMetricReader)()
.
Builtin readers:
OpenTelemetrySDK.AbstractSampler
— TypeA sampler controls whether to drop a span or not when creating new spans in a certain context. Each sampler should have the should_sample
method implemented.
OpenTelemetrySDK.AbstractSpanProcessor
— TypeEach span processor must implement the following methods:
OpenTelemetrySDK.AggregationStore
— MethodAggregationStore{D}(max_points=nothing) where D<:DataPoint
The AggregationStore
holds all the aggregated datapoints in a Metric
.
OpenTelemetrySDK.Limited
— TypeLimited(container; limit=32)
Create a container wrapper with limited elements.
The following methods from Base
are defined on Limited
which are then forwarded to the inner container
. 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!
. Only defined on containers ofAbstractVector
.
OpenTelemetrySDK.MetricReader
— TypeMetricReader([global_meter_provider()], [ConsoleExporter()])
Note that all metrics will be read on initialization.
OpenTelemetrySDK.MetricReader
— Method(r::MetricReader)()
For async instruments in r
, their callbacks will be executed first before reading all the metrics.
OpenTelemetrySDK.OtelBatchLogger
— MethodOtelBatchLogger(exporter;kw...)
OtelBatchLogger
is a Sink
(see LoggingExtras.jl to understand the concept). Note that it will create a OtelLogTransformer
on construction and apply it automatically on each log message.
Keyword arguments
max_queue_size=nothing
scheduled_delay_millis = nothing
export_timeout_millis = nothing
max_export_batch_size = nothing
resource = Resource()
instrumentation_scope = InstrumentationScope()
OpenTelemetrySDK.PeriodicMetricReader
— TypePeriodicMetricReader(reader; export_interval_seconds = 60, export_timeout_seconds = 30)
Periodically call the reader
in the background.
OpenTelemetrySDK.PeriodicMetricReader
— MethodFor PeriodicMetricReader
, there's no need to call this method since the read operation will be done periodically in the background.
Base.close
— Methodclose(p::TracerProvider)
Shut down inner span processors and then mark itself as shut down.
Base.flush
— Methodflush(p::TracerProvider)
Shorthand to force flush inner span processors
Base.push!
— MethodBase.push!([p::TracerProvider], sp::AbstractSpanProcessor)
Add an extra span processor sp
into the TracerProvider
p.
OpenTelemetrySDK.on_end!
— Methodon_end!(ssp::SimpleSpanProcessor, span)
The span
is exported immediately if it is sampled.
OpenTelemetrySDK.on_start!
— Methodon_start!(ssp::SimpleSpanProcessor, span)
OpenTelemetrySDK.should_sample
— Functionshould_sample(s::AbstractSampler, args...)
Arguments
parent_span_ctx
::SpanContext
,trace_id
::TraceIdType
,name::String
, the span namekind
::SpanKind
,attributes
,StaticBoundedAttributes
orDynamicAttrs
links
, vector ofLink
trace_state
::TraceState
,