OpenTelemetrySDK

Exporters

Two common exporters are provided to for debugging:

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.

ID Generators

Samplers

Span Processors

OpenTelemetrySDK.BatchSpanProcessorType
BatchSpanProcessor(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.

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 Measurements. Each metric may have many different dimensions configured by BoundedAttributes in a Measurement. For each dimension, we may also collect those Exemplars 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 of instrument => 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.ExemplarType
Exemplar(;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 a Measurement that are not included in a Metric's :attribute_keys field.
  • trace_id, the trace_id in the span context when the measurement happens.
  • span_id, the span_id in the span context when the measurement happens.
OpenTelemetrySDK.HistogramAggType
HistogramAgg(args...)

Arguments:

  • boundaries::NTuple{M, Float64} where M, the boundaries to calculate histogram buckets. Note that -Inf and Inf shouldn't be included.
  • is_record_min
  • is_record_max
  • agg_store
  • exemplar_reservoir_factory, when set to nothing, no exemplar will be stored.
OpenTelemetrySDK.SumAggType
SumAgg(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.ViewType
View(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.AbstractIdGeneratorType

Customized id generators must implement the following two methods:

  • generate_span_id(::AbstractIdGenerator)
  • generate_trace_id(::AbstractIdGenerator)
OpenTelemetrySDK.LimitedType
Limited(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 of AbstractVector.
OpenTelemetrySDK.MetricReaderType
MetricReader([global_meter_provider()], [ConsoleExporter()])

Note that all metrics will be read on initialization.

OpenTelemetrySDK.MetricReaderMethod
(r::MetricReader)()

For async instruments in r, their callbacks will be executed first before reading all the metrics.

OpenTelemetrySDK.OtelBatchLoggerMethod
OtelBatchLogger(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()
Base.closeMethod
close(p::TracerProvider)

Shut down inner span processors and then mark itself as shut down.

Base.flushMethod
flush(p::TracerProvider)

Shorthand to force flush inner span processors

Base.push!Method
Base.push!([p::TracerProvider], sp::AbstractSpanProcessor)

Add an extra span processor sp into the TracerProvider p.

OpenTelemetrySDK.on_end!Method
on_end!(ssp::SimpleSpanProcessor, span)

The span is exported immediately if it is sampled.