comon_otel 0.0.1-alpha.1
comon_otel: ^0.0.1-alpha.1 copied to clipboard
OpenTelemetry SDK foundation for Dart with traces, metrics, logs, context propagation, and OTLP exporters.
example/comon_otel_example.dart
import 'package:comon_otel/comon_otel.dart';
Future<void> main() async {
await Otel.init(
serviceName: 'comon-otel-example',
exporter: OtelExporter.console,
);
final requestCounter = Otel.instance.meter.createIntCounter(
'example.requests',
description: 'Counts processed example requests',
);
final answer = await Otel.instance.tracer.traceAsync<int>(
'example.compute_answer',
attributes: const <String, Object>{'example.flow': 'quickstart'},
fn: () async {
requestCounter.add(1, attributes: const <String, Object>{'route': '/'});
Otel.instance.logger.info('Computing example answer');
return 42;
},
);
await Otel.forceFlush();
print('answer: $answer');
await Otel.shutdown();
}