Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,33 @@ await FlutterOTel.initialize(
);
```

### Network Requests (Android / iOS / desktop)

Outside the browser there is nothing to patch, so wrap the client your app
uses. Each request gets a `GET host/path` client span (`event.type=xhr`), the
same name the web SDK uses, and carries trace headers so your backend's spans
join the app's trace:

```dart
final client = http.Client().instrument(); // package:http
dio.addOTelInstrumentation(); // dio
```

By default both W3C (`traceparent`) and B3 (`b3`, `x-b3-*`) headers are sent.
To send only one:

```dart
final client = http.Client().instrument(
config: const HttpInstrumentationConfig(
tracePropagationFormat: TracePropagationFormat.b3, // or .w3c
),
);
```

Use `shouldInstrument: (url) => ...` to skip URLs. Skipped requests get no
span and no headers. On web the browser instrumentation already covers every
client, so wrap only when `!kIsWeb` to avoid a second span per request.

### Platform-Specific Exporters

Flutterrific automatically selects the right protocol:
Expand Down
19 changes: 8 additions & 11 deletions lib/src/web/web_instrumentation_options.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Licensed under the Apache License, Version 2.0

/// Trace-context header formats injected into instrumented requests.
enum TracePropagationFormat {
/// W3C `traceparent` only.
w3c,

/// B3 single (`b3`) and multi (`X-B3-*`) headers.
b3,

/// W3C plus both B3 encodings (browser SDK default).
all,
}
import 'package:middleware_dart_opentelemetry/middleware_dart_opentelemetry.dart'
show TracePropagationFormat;

// One enum for web and mobile: the web options take it here, and the mobile
// `HttpInstrumentationConfig` (OTelHttpClient / OTelDioInterceptor) takes the
// same type.
export 'package:middleware_dart_opentelemetry/middleware_dart_opentelemetry.dart'
show TracePropagationFormat;

/// Browser instrumentation for Flutter web, mirroring the Middleware browser
/// SDK (`@middleware.io/browser`). Ignored on every other platform.
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: middleware_flutter_opentelemetry
description: "A Flutter package for OpenTelemetry based on middleware_dart_opentelemetry"
version: 2.1.0
version: 2.1.1
homepage: https://middleware.io
repository: https://github.com/middleware-labs/flutter-sdk.git

Expand All @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
middleware_dart_opentelemetry: ^1.0.6
middleware_dart_opentelemetry: ^1.0.7
# Pinned: 1.0.0-rc.1 removed the Flutter semantic enums
# (NavigationAction, AppLifecycleSemantics, InteractionType, ...) this SDK
# builds against.
Expand Down
Loading