Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add tracing client test
  • Loading branch information
buenaflor committed Sep 4, 2023
commit 3c639b38b87f217537d555797c7ccac039f41fef
3 changes: 1 addition & 2 deletions dart/lib/src/http_client/tracing_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class TracingClient extends BaseClient {
final scope = _hub.scope;
final propagationContext = scope.propagationContext;

final traceHeader = SentryTraceHeader(
propagationContext.traceId, propagationContext.spanId);
final traceHeader = propagationContext.toSentryTrace();
addSentryTraceheader(traceHeader, request.headers);

final baggage = propagationContext.baggage;
Expand Down
4 changes: 4 additions & 0 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'hint.dart';

import 'hub.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry.dart';
import 'sentry_client.dart';
import 'sentry_user_feedback.dart';
Expand Down Expand Up @@ -166,4 +167,7 @@ class HubAdapter implements Hub {
String transaction,
) =>
Sentry.currentHub.setSpanContext(throwable, span, transaction);

@override
Scope get scope => Sentry.currentHub.scope;
}
4 changes: 4 additions & 0 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:meta/meta.dart';
import 'hint.dart';
import 'hub.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry_client.dart';
import 'sentry_options.dart';
import 'sentry_user_feedback.dart';
Expand Down Expand Up @@ -118,4 +119,7 @@ class NoOpHub implements Hub {

@override
void setSpanContext(throwable, ISentrySpan span, String transaction) {}

@override
Scope get scope => Scope(_options);
}
2 changes: 2 additions & 0 deletions dart/lib/src/propagation_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ class PropagationContext {
traceId = SentryId.newId();
spanId = SpanId.newId();
}

SentryTraceHeader toSentryTrace() => SentryTraceHeader(traceId, spanId);
}
31 changes: 31 additions & 0 deletions dart/test/http_client/tracing_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,37 @@ void main() {

await sut.get(requestUri);
});

test('set headers from propagationContext when tracing is disabled', () async {
fixture._options.enableTracing = false;
final sut = fixture.getSut(
client: fixture.getClient(statusCode: 200, reason: 'OK'),
);

final propagationContext = fixture._hub.scope.propagationContext;
propagationContext.baggage = SentryBaggage({'foo': 'bar'});

final response = await sut.get(requestUri);

expect(response.request!.headers['sentry-trace'],
propagationContext.toSentryTrace().value);
expect(response.request!.headers['baggage'], 'foo=bar');
});

test('set headers from propagationContext when no transaction', () async {
final sut = fixture.getSut(
client: fixture.getClient(statusCode: 200, reason: 'OK'),
);

final propagationContext = fixture._hub.scope.propagationContext;
propagationContext.baggage = SentryBaggage({'foo': 'bar'});

final response = await sut.get(requestUri);

expect(response.request!.headers['sentry-trace'],
propagationContext.toSentryTrace().value);
expect(response.request!.headers['baggage'], 'foo=bar');
});
});
}

Expand Down