otel_logging 0.1.0-beta.1 copy "otel_logging: ^0.1.0-beta.1" to clipboard
otel_logging: ^0.1.0-beta.1 copied to clipboard

Bridge `package:logging` records into the OpenTelemetry logs SDK so trace_id / span_id correlation lights up automatically for any Dart app using the Dart team's standard logging package.

example/main.dart

// Licensed under the Apache License, Version 2.0
// Copyright 2025, Mindful Software LLC, All rights reserved.

/// Minimal example: install the bridge, emit a few records (one of them
/// inside an active span so trace_id/span_id correlation lights up), then
/// uninstall and shut down cleanly.
library;

import 'package:dartastic_opentelemetry/dartastic_opentelemetry.dart';
import 'package:logging/logging.dart';
import 'package:otel_logging/otel_logging.dart';

Future<void> main() async {
  await OTel.initialize(
    serviceName: 'logging-bridge-example',
    serviceVersion: '0.0.1',
  );

  PackageLoggingBridge.install();

  Logger.root.level = Level.ALL;

  // Off-span — no trace correlation.
  Logger('startup').info('process started');

  // In-span — record will carry the active span's trace_id / span_id.
  await OTel.tracer().startActiveSpanAsync<void>(
    name: 'serve-request',
    fn: (_) async {
      Logger('handler').warning('upstream took >500ms');
    },
  );

  // Lifecycle: cancel the subscription before main() returns.
  await PackageLoggingBridge.uninstall();
  await OTel.shutdown();
}
1
likes
140
points
34
downloads

Documentation

API reference

Publisher

verified publisherdartastic.io

Weekly Downloads

Bridge `package:logging` records into the OpenTelemetry logs SDK so trace_id / span_id correlation lights up automatically for any Dart app using the Dart team's standard logging package.

License

Apache-2.0 (license)

Dependencies

dartastic_opentelemetry, dartastic_opentelemetry_api, logging

More

Packages that depend on otel_logging