otel_dio 0.2.0 copy "otel_dio: ^0.2.0" to clipboard
otel_dio: ^0.2.0 copied to clipboard

OpenTelemetry instrumentation for `package:dio`. An Interceptor that wraps each request in a CLIENT-kind span, sets HTTP semconv attributes and injects W3C trace-context headers.

example/main.dart

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

/// Minimal example: initialize OTel, add the interceptor to a Dio
/// instance, make a request inside an active server-side span, then
/// shut down cleanly.
library;

import 'package:dartastic_opentelemetry/dartastic_opentelemetry.dart';
import 'package:dio/dio.dart';
import 'package:otel_dio/otel_dio.dart';

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

  final dio = Dio(BaseOptions(baseUrl: 'https://httpbin.org'))
    ..interceptors.add(OTelDioInterceptor());

  // Wrap the outbound call in a parent span so the client span has
  // somewhere to be attached. In a real server, the parent would be
  // the incoming-request span you got from your framework's interceptor.
  final tracer = OTel.tracer();
  await tracer.startActiveSpanAsync<void>(
    name: 'serve-request',
    fn: (_) async {
      final response = await dio.get<dynamic>('/status/200');
      print('status: ${response.statusCode}');
    },
  );

  await OTel.shutdown();
}
0
likes
160
points
84
downloads

Documentation

API reference

Publisher

verified publisherdartastic.io

Weekly Downloads

OpenTelemetry instrumentation for `package:dio`. An Interceptor that wraps each request in a CLIENT-kind span, sets HTTP semconv attributes and injects W3C trace-context headers.

Homepage
Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

dartastic_opentelemetry, dartastic_opentelemetry_api, dio

More

Packages that depend on otel_dio