-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage examples for async would be really valuable #174
Comments
@time4tea Following interceptor implementation worked for me. import 'package:dio/dio.dart';
import 'package:opentelemetry/api.dart' as otel_api;
class TracingInterceptor implements Interceptor {
static const _spanExtra = 'telemetry_span';
static const _tracerName = 'HTTP-client';
List<otel_api.Attribute> _getRequestAttributes(RequestOptions options) {
// NO-OP
return [];
}
String _getSpanName(RequestOptions options) {
// NO-OP
return 'http';
}
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final requestSpan =
otel_api.globalTracerProvider.getTracer(_tracerName).startSpan(
_getSpanName(options),
kind: otel_api.SpanKind.client,
attributes: _getRequestAttributes(options),
);
// store the span object for later
options.extra[_spanExtra] = requestSpan;
handler.next(options);
}
@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
final requestSpan =
response.requestOptions.extra[_spanExtra] as otel_api.Span;
requestSpan.end();
handler.next(response);
}
@override
void onError(DioException err, ErrorInterceptorHandler handler) {
final requestSpan = err.requestOptions.extra[_spanExtra] as otel_api.Span;
requestSpan.recordException(err);
requestSpan.end();
handler.next(err);
}
}
|
Thank you! I will try this! |
2 tasks
I did try this and it worked very nicely. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hiya - Thanks for this library!
I'm trying to instrument an async process, and its not clear to me how to track the call through the system.
For example, plugging into 'dio' using interceptors, i can create a new span like this:
and then I'm hoping to be able to close the span at the end of the request like this:
however, the spanid at the end is the invalid span, so i guess I'm not doing the right thing with the context. Are there any examples for how to instrument something like
dio
?Of course - if i get this working, it could be contributed, if that were useful.
Thank you!
The text was updated successfully, but these errors were encountered: