diff --git a/lib/api.dart b/lib/api.dart index 220f481e..7c59b27a 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -10,8 +10,6 @@ export 'src/api/resource/resource.dart' show Resource; export 'src/api/span_processors/span_processor.dart' show SpanProcessor; export 'src/api/trace/id_generator.dart' show IdGenerator; export 'src/api/trace/nonrecording_span.dart' show NonRecordingSpan; -export 'src/api/trace/sampler.dart' show Sampler; -export 'src/api/trace/sampling_result.dart' show Decision, SamplingResult; export 'src/api/trace/span.dart' show Span, SpanKind; export 'src/api/trace/span_context.dart' show SpanContext; export 'src/api/trace/span_id.dart' show SpanId; diff --git a/lib/sdk.dart b/lib/sdk.dart index 08086340..205c73df 100644 --- a/lib/sdk.dart +++ b/lib/sdk.dart @@ -12,11 +12,13 @@ export 'src/sdk/trace/exporters/console_exporter.dart' show ConsoleExporter; export 'src/sdk/trace/id_generator.dart' show IdGenerator; export 'src/sdk/trace/propagation/w3c_trace_context_propagator.dart' show W3CTraceContextPropagator; -export 'src/sdk/trace/samplers/always_off_sampler.dart' show AlwaysOffSampler; -export 'src/sdk/trace/samplers/always_on_sampler.dart' show AlwaysOnSampler; -export 'src/sdk/trace/samplers/parent_based_sampler.dart' +export 'src/sdk/trace/sampling/always_off_sampler.dart' show AlwaysOffSampler; +export 'src/sdk/trace/sampling/always_on_sampler.dart' show AlwaysOnSampler; +export 'src/sdk/trace/sampling/parent_based_sampler.dart' show ParentBasedSampler; -export 'src/sdk/trace/samplers/sampling_result.dart' show SamplingResult; +export 'src/sdk/trace/sampling/sampler.dart' show Sampler; +export 'src/sdk/trace/sampling/sampling_result.dart' + show Decision, SamplingResult; export 'src/sdk/trace/span.dart' show Span; export 'src/sdk/trace/span_context.dart' show SpanContext; export 'src/sdk/trace/span_processors/batch_processor.dart' diff --git a/lib/src/sdk/trace/samplers/sampling_result.dart b/lib/src/sdk/trace/samplers/sampling_result.dart deleted file mode 100644 index 8657b568..00000000 --- a/lib/src/sdk/trace/samplers/sampling_result.dart +++ /dev/null @@ -1,13 +0,0 @@ -import '../../../../api.dart'; -import '../../../api/trace/sampling_result.dart' as api; - -class SamplingResult implements api.SamplingResult { - @override - final api.Decision decision; - @override - final List spanAttributes; - @override - final TraceState traceState; - - SamplingResult(this.decision, this.spanAttributes, this.traceState); -} diff --git a/lib/src/sdk/trace/samplers/always_off_sampler.dart b/lib/src/sdk/trace/sampling/always_off_sampler.dart similarity index 74% rename from lib/src/sdk/trace/samplers/always_off_sampler.dart rename to lib/src/sdk/trace/sampling/always_off_sampler.dart index 7d875698..6d23ddd4 100644 --- a/lib/src/sdk/trace/samplers/always_off_sampler.dart +++ b/lib/src/sdk/trace/sampling/always_off_sampler.dart @@ -1,12 +1,12 @@ import '../../../../api.dart' as api; import '../../../../sdk.dart' as sdk; -class AlwaysOffSampler implements api.Sampler { +class AlwaysOffSampler implements sdk.Sampler { @override String get description => 'AlwaysOffSampler'; @override - api.SamplingResult shouldSample( + sdk.SamplingResult shouldSample( api.Context context, api.TraceId traceId, String spanName, @@ -14,7 +14,7 @@ class AlwaysOffSampler implements api.Sampler { bool spanIsRemote, List spanAttributes, List links) { - return sdk.SamplingResult(api.Decision.drop, spanAttributes, + return sdk.SamplingResult(sdk.Decision.drop, spanAttributes, context.spanContext?.traceState ?? sdk.TraceState.empty()); } } diff --git a/lib/src/sdk/trace/samplers/always_on_sampler.dart b/lib/src/sdk/trace/sampling/always_on_sampler.dart similarity index 75% rename from lib/src/sdk/trace/samplers/always_on_sampler.dart rename to lib/src/sdk/trace/sampling/always_on_sampler.dart index 5b4af13e..889714bb 100644 --- a/lib/src/sdk/trace/samplers/always_on_sampler.dart +++ b/lib/src/sdk/trace/sampling/always_on_sampler.dart @@ -1,12 +1,12 @@ import '../../../../api.dart' as api; import '../../../../sdk.dart' as sdk; -class AlwaysOnSampler implements api.Sampler { +class AlwaysOnSampler implements sdk.Sampler { @override String get description => 'AlwaysOnSampler'; @override - api.SamplingResult shouldSample( + sdk.SamplingResult shouldSample( api.Context context, api.TraceId traceId, String spanName, @@ -14,7 +14,7 @@ class AlwaysOnSampler implements api.Sampler { bool spanIsRemote, List spanAttributes, List spanLinks) { - return sdk.SamplingResult(api.Decision.recordAndSample, spanAttributes, + return sdk.SamplingResult(sdk.Decision.recordAndSample, spanAttributes, context.spanContext?.traceState ?? sdk.TraceState.empty()); } } diff --git a/lib/src/sdk/trace/samplers/parent_based_sampler.dart b/lib/src/sdk/trace/sampling/parent_based_sampler.dart similarity index 87% rename from lib/src/sdk/trace/samplers/parent_based_sampler.dart rename to lib/src/sdk/trace/sampling/parent_based_sampler.dart index 53d7896f..2519fba1 100644 --- a/lib/src/sdk/trace/samplers/parent_based_sampler.dart +++ b/lib/src/sdk/trace/sampling/parent_based_sampler.dart @@ -1,12 +1,12 @@ import '../../../../api.dart' as api; import '../../../../sdk.dart' as sdk; -class ParentBasedSampler implements api.Sampler { - final api.Sampler _root; - final api.Sampler _remoteParentSampled; - final api.Sampler _remoteParentNotSampled; - final api.Sampler _localParentSampled; - final api.Sampler _localParentNotSampled; +class ParentBasedSampler implements sdk.Sampler { + final sdk.Sampler _root; + final sdk.Sampler _remoteParentSampled; + final sdk.Sampler _remoteParentNotSampled; + final sdk.Sampler _localParentSampled; + final sdk.Sampler _localParentNotSampled; ParentBasedSampler(this._root, {remoteParentSampled, @@ -24,7 +24,7 @@ class ParentBasedSampler implements api.Sampler { String get description => 'ParentBasedSampler{root=${_root.description}}'; @override - api.SamplingResult shouldSample( + sdk.SamplingResult shouldSample( api.Context context, api.TraceId traceId, String spanName, diff --git a/lib/src/api/trace/sampler.dart b/lib/src/sdk/trace/sampling/sampler.dart similarity index 79% rename from lib/src/api/trace/sampler.dart rename to lib/src/sdk/trace/sampling/sampler.dart index 7596f306..02a10c9c 100644 --- a/lib/src/api/trace/sampler.dart +++ b/lib/src/sdk/trace/sampling/sampler.dart @@ -1,9 +1,10 @@ -import '../../../api.dart' as api; +import '../../../../api.dart' as api; +import '../../../../sdk.dart' as sdk; /// Represents an entity which determines whether a [api.Span] should be sampled /// and sent for collection. abstract class Sampler { - api.SamplingResult shouldSample( + sdk.SamplingResult shouldSample( api.Context context, api.TraceId traceId, String spanName, diff --git a/lib/src/api/trace/sampling_result.dart b/lib/src/sdk/trace/sampling/sampling_result.dart similarity index 51% rename from lib/src/api/trace/sampling_result.dart rename to lib/src/sdk/trace/sampling/sampling_result.dart index e45cae06..28d868ce 100644 --- a/lib/src/api/trace/sampling_result.dart +++ b/lib/src/sdk/trace/sampling/sampling_result.dart @@ -1,4 +1,4 @@ -import '../../../api.dart' as api; +import '../../../../api.dart' as api; enum Decision { drop, @@ -6,10 +6,8 @@ enum Decision { recordAndSample, } -/// Represents the result of a Sampler as to whether a Span should -/// be processed for collection. -abstract class SamplingResult { - final api.Decision decision; +class SamplingResult { + final Decision decision; final List spanAttributes; final api.TraceState traceState; diff --git a/lib/src/sdk/trace/tracer.dart b/lib/src/sdk/trace/tracer.dart index 2cd783a6..38d96ff6 100644 --- a/lib/src/sdk/trace/tracer.dart +++ b/lib/src/sdk/trace/tracer.dart @@ -7,7 +7,7 @@ import '../../../sdk.dart' as sdk; class Tracer implements api.Tracer { final List _processors; final api.Resource _resource; - final api.Sampler _sampler; + final sdk.Sampler _sampler; final api.IdGenerator _idGenerator; final api.InstrumentationLibrary _instrumentationLibrary; sdk.SpanLimits _spanLimits; @@ -49,7 +49,7 @@ class Tracer implements api.Tracer { final samplerResult = _sampler.shouldSample( context, traceId, name, kind, false, attributes, links); - final traceFlags = (samplerResult.decision == api.Decision.recordAndSample) + final traceFlags = (samplerResult.decision == sdk.Decision.recordAndSample) ? api.TraceFlags.sampled : api.TraceFlags.none; final spanContext = diff --git a/lib/src/sdk/trace/tracer_provider.dart b/lib/src/sdk/trace/tracer_provider.dart index e1ee9102..d2140d92 100644 --- a/lib/src/sdk/trace/tracer_provider.dart +++ b/lib/src/sdk/trace/tracer_provider.dart @@ -6,14 +6,14 @@ class TracerProvider implements api.TracerProvider { final Map _tracers = {}; List _processors; api.Resource _resource; - api.Sampler _sampler; + sdk.Sampler _sampler; api.IdGenerator _idGenerator; sdk.SpanLimits _spanLimits; TracerProvider( {List processors, api.Resource resource, - api.Sampler sampler, + sdk.Sampler sampler, api.IdGenerator idGenerator, sdk.SpanLimits spanLimits}) { _processors = processors ?? []; // Default to a no-op TracerProvider. diff --git a/test/unit/sdk/samplers/always_off_sampler_test.dart b/test/unit/sdk/sampling/always_off_sampler_test.dart similarity index 94% rename from test/unit/sdk/samplers/always_off_sampler_test.dart rename to test/unit/sdk/sampling/always_off_sampler_test.dart index eb49cc58..8c233eb2 100644 --- a/test/unit/sdk/samplers/always_off_sampler_test.dart +++ b/test/unit/sdk/sampling/always_off_sampler_test.dart @@ -20,7 +20,7 @@ void main() { final result = sdk.AlwaysOffSampler().shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, [], []); - expect(result.decision, equals(api.Decision.drop)); + expect(result.decision, equals(sdk.Decision.drop)); expect(result.spanAttributes, equals([])); expect(result.traceState, same(traceState)); }); @@ -49,7 +49,7 @@ void main() { false, attributesList, []); - expect(result.decision, equals(api.Decision.drop)); + expect(result.decision, equals(sdk.Decision.drop)); expect(result.spanAttributes, attributesList); expect(result.traceState.isEmpty, isTrue); }); diff --git a/test/unit/sdk/samplers/always_on_sampler_test.dart b/test/unit/sdk/sampling/always_on_sampler_test.dart similarity index 92% rename from test/unit/sdk/samplers/always_on_sampler_test.dart rename to test/unit/sdk/sampling/always_on_sampler_test.dart index c4fec32f..77a54835 100644 --- a/test/unit/sdk/samplers/always_on_sampler_test.dart +++ b/test/unit/sdk/sampling/always_on_sampler_test.dart @@ -20,7 +20,7 @@ void main() { final result = sdk.AlwaysOnSampler().shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, [], []); - expect(result.decision, equals(api.Decision.recordAndSample)); + expect(result.decision, equals(sdk.Decision.recordAndSample)); expect(result.spanAttributes, equals([])); expect(result.traceState, same(traceState)); }); @@ -39,7 +39,7 @@ void main() { final result = sdk.AlwaysOnSampler().shouldSample(api.Context.root, traceId, testSpan.name, api.SpanKind.internal, false, [], []); - expect(result.decision, equals(api.Decision.recordAndSample)); + expect(result.decision, equals(sdk.Decision.recordAndSample)); expect(result.spanAttributes, equals([])); expect(result.traceState.isEmpty, isTrue); }); diff --git a/test/unit/sdk/samplers/parent_based_sampler_test.dart b/test/unit/sdk/sampling/parent_based_sampler_test.dart similarity index 92% rename from test/unit/sdk/samplers/parent_based_sampler_test.dart rename to test/unit/sdk/sampling/parent_based_sampler_test.dart index 4eec10d7..2b4c42c3 100644 --- a/test/unit/sdk/samplers/parent_based_sampler_test.dart +++ b/test/unit/sdk/sampling/parent_based_sampler_test.dart @@ -27,7 +27,7 @@ void main() { final result = testSampler.shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, null, []); - expect(result.decision, equals(api.Decision.recordAndSample)); + expect(result.decision, equals(sdk.Decision.recordAndSample)); expect(result.spanAttributes, equals(null)); expect(result.traceState.isEmpty, isTrue); }); @@ -45,7 +45,7 @@ void main() { final result = testSampler.shouldSample(api.Context.root, traceId, testSpan.name, api.SpanKind.internal, false, null, []); - expect(result.decision, equals(api.Decision.recordAndSample)); + expect(result.decision, equals(sdk.Decision.recordAndSample)); expect(result.spanAttributes, equals(null)); expect(result.traceState.isEmpty, isTrue); }); @@ -67,7 +67,7 @@ void main() { final result = testSampler.shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, null, []); - expect(result.decision, equals(api.Decision.recordAndSample)); + expect(result.decision, equals(sdk.Decision.recordAndSample)); expect(result.spanAttributes, equals(null)); expect(result.traceState, same(traceState)); }); @@ -89,7 +89,7 @@ void main() { final result = testSampler.shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, [], []); - expect(result.decision, equals(api.Decision.drop)); + expect(result.decision, equals(sdk.Decision.drop)); expect(result.spanAttributes, equals([])); expect(result.traceState, same(traceState)); }); @@ -111,7 +111,7 @@ void main() { final result = testSampler.shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, [], []); - expect(result.decision, equals(api.Decision.recordAndSample)); + expect(result.decision, equals(sdk.Decision.recordAndSample)); expect(result.spanAttributes, equals([])); expect(result.traceState, same(traceState)); }); @@ -133,7 +133,7 @@ void main() { final result = testSampler.shouldSample(testContext, traceId, testSpan.name, api.SpanKind.internal, false, [], []); - expect(result.decision, equals(api.Decision.drop)); + expect(result.decision, equals(sdk.Decision.drop)); expect(result.spanAttributes, equals([])); expect(result.traceState, same(traceState)); });