Line data Source code
1 : // Licensed under the Apache License, Version 2.0
2 : // Copyright 2025, Michael Bushe, All rights reserved.
3 :
4 : import 'package:dartastic_opentelemetry_api/dartastic_opentelemetry_api.dart';
5 : import 'sampler.dart';
6 :
7 : /// A sampler that always samples every trace.
8 : ///
9 : /// This sampler implements the "always on" sampling strategy, which means
10 : /// it will record and sample every span regardless of any other factors.
11 : /// This is useful for debugging and development environments where you
12 : /// want to see all spans.
13 : ///
14 : /// More information:
15 : /// https://opentelemetry.io/docs/specs/otel/trace/sdk/#alwayson
16 : class AlwaysOnSampler implements Sampler {
17 : /// Gets a description of this sampler.
18 : ///
19 : /// @return The string "AlwaysOnSampler"
20 2 : @override
21 : String get description => 'AlwaysOnSampler';
22 :
23 : /// Creates a new AlwaysOnSampler.
24 81 : const AlwaysOnSampler();
25 :
26 : /// Always returns a decision to record and sample the span.
27 : ///
28 : /// This method ignores all parameters and always returns a decision
29 : /// to record and sample the span.
30 : ///
31 : /// @param parentContext Ignored
32 : /// @param traceId Ignored
33 : /// @param name Ignored
34 : /// @param spanKind Ignored
35 : /// @param attributes Ignored
36 : /// @param links Ignored
37 : /// @return A sampling result with decision set to recordAndSample
38 30 : @override
39 : SamplingResult shouldSample({
40 : required Context parentContext,
41 : required String traceId,
42 : required String name,
43 : required SpanKind spanKind,
44 : required Attributes? attributes,
45 : required List<SpanLink>? links,
46 : }) {
47 : return const SamplingResult(
48 : decision: SamplingDecision.recordAndSample,
49 : source: SamplingDecisionSource.tracerConfig,
50 : );
51 : }
52 : }
|