The MoonBit implementation of OpenTelemetry.
Dependencies
| Package | Use it for |
|---|---|
| moonbit-community/opentelemetry | Small public entry point for library instrumentation: tracer(), meter(), logger(), attributes, baggage, and context aliases. |
| moonbit-community/opentelemetry/interface/trace | Trace API: spans, span builders, events, links, status, and no-op trace behavior. |
| moonbit-community/opentelemetry/interface/metrics | Metrics API: meters, counters, up-down counters, histograms, gauges, and observable instruments. |
| moonbit-community/opentelemetry/interface/logs | Log bridge API: structured log records that can be correlated with traces. |
| moonbit-community/opentelemetry/interface/context | Immutable context container used to carry span context, baggage, and telemetry suppression. |
| moonbit-community/opentelemetry/interface/propagation | W3C trace-context and baggage propagation through text carriers such as HTTP headers. |
| moonbit-community/opentelemetry/interface/global | Process-wide API providers. Libraries normally read from here indirectly through the root package. |
| moonbit-community/opentelemetry/sdk | Application-side SDK facade for providers, processors, readers, resources, samplers, and global SDK helpers. |
| moonbit-community/opentelemetry/sdk/global | Process-wide SDK providers used by the SDK facade. Use sdk.set_*_provider() to wire SDK providers into the public root package. |
| moonbit-community/opentelemetry/print | Human-readable stdout exporters for examples, local debugging, and tests. |
| moonbit-community/opentelemetry/otlp | OTLP HTTP exporters for traces, logs, and metrics. |
| moonbit-community/opentelemetry/semantics/* | Generated semantic-convention constants for standard attribute and metric names. |
| moonbit-community/opentelemetry/protocol/* | Low-level generated OTLP protobuf/JSON models. Most users do not need these directly. |
///|
async fn _readme_trace_to_stdout() -> Unit {
let exporter = @print.SpanExporter::new()
let provider = @sdk.tracer_provider_builder()
.with_simple_exporter(exporter.into_span_exporter())
.build()
@sdk.set_tracer_provider(provider)
let tracer = tracer("checkout-service", version=Some("1.0.0"))
let span = tracer.start("charge-card")
span.set_attribute(KeyValue::new("payment.system", String("test")))
span.set_status(@trace.Status::ok())
span.end()
ignore(provider.shutdown())
}///|
pub async fn _library_operation() -> Unit {
let tracer = tracer(
"moonbit-community/example-library",
version=Some("0.1.0"),
)
let span = tracer.start("example.operation")
span.set_attribute(KeyValue::new("example.kind", String("demo")))
// Library work goes here.
span.end()
}///|
async fn _spawn_background_tasks_shape() -> Unit {
@async.with_task_group(group => @sdk.spawn_background_tasks(group))
}///|
fn _record_request_metrics() -> Unit {
let meter = meter("checkout-service")
let request_count = meter.u64_counter("http.server.request.count").build()
let request_latency = meter
.f64_histogram("http.server.duration")
.with_unit("ms")
.build()
request_count.add(1UL, attributes=[
KeyValue::new("http.request.method", String("POST")),
])
request_latency.record(32.5, attributes=[
KeyValue::new("http.route", String("/checkout")),
])
}///|
async fn _emit_structured_log() -> Unit {
let logger = logger("checkout-service")
if logger.event_enabled(Info, "checkout") {
let record = logger.create_log_record()
record.set_event_name("checkout.completed")
record.set_target("checkout")
record.set_severity_number(Info)
record.set_body(String("checkout completed"))
record.add_attribute("cart.items", Int(3L))
logger.emit(record)
}
}///|
fn _inject_headers(context : Context) -> Map[String, String] {
let headers = {}
get_text_map_propagator(propagator => {
propagator.inject_context(context, headers)
})
headers
}docker run --rm -p 4318:4318 otel/opentelemetry-collector:latest| Area | Variables |
|---|---|
| Resource | OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES |
| Trace sampling | OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG |
| Trace limits | OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_EVENT_COUNT_LIMIT, OTEL_SPAN_LINK_COUNT_LIMIT |
| Batch spans | OTEL_BSP_SCHEDULE_DELAY, OTEL_BSP_MAX_QUEUE_SIZE, OTEL_BSP_MAX_EXPORT_BATCH_SIZE, OTEL_BSP_EXPORT_TIMEOUT |
| Batch logs | OTEL_BLRP_SCHEDULE_DELAY, OTEL_BLRP_MAX_QUEUE_SIZE, OTEL_BLRP_MAX_EXPORT_BATCH_SIZE, OTEL_BLRP_EXPORT_TIMEOUT |
| Periodic metrics | OTEL_METRIC_EXPORT_INTERVAL |
| OTLP exporter | OTEL_EXPORTER_OTLP_* plus signal-specific TRACES, METRICS, and LOGS variants |
///|
fn _semantic_convention_attribute() -> Array[KeyValue] {
[KeyValue::new(@semtrace.HTTP_REQUEST_METHOD, String("GET"))]
}The MoonBit implementation of OpenTelemetry.
Dependencies