farol_grpc 0.1.2
farol_grpc: ^0.1.2 copied to clipboard
gRPC (package:grpc) instrumentation for the Faro RUM client — RPC measurements, errors, and W3C traceparent.
// Minimal usage example for `farol_grpc`. See ../README.md for the
// host-scoping limitation and the injectTraceparent recommendation.
import 'package:farol/farol.dart';
import 'package:farol_grpc/farol_grpc.dart';
import 'package:grpc/grpc.dart';
Future<void> main() async {
Faro.initialize(
FaroConfig(
collectorUrl: Uri.parse('https://faro-collector.example.com/collect'),
app: const FaroApp(name: 'example-app'),
),
);
final channel = ClientChannel(
'api.example.com',
port: 443,
options: const ChannelOptions(credentials: ChannelCredentials.secure()),
);
// Attach the interceptor only to channels you want instrumented — that is
// the reliable way to scope by host (see README "Scoping instrumentation
// by host").
final interceptors = [FaroGrpcInterceptor(injectTraceparent: false)];
// Pass `interceptors:` to your generated client's constructor, e.g.:
// final stub = MyServiceClient(channel, interceptors: interceptors);
assert(interceptors.length == 1);
await channel.shutdown();
}