A span with a valid context, which records unless a sampler dropped it.
| 28 | |
| 29 | |
| 30 | class RecordingSpan(NonRecordingSpan): |
| 31 | """A span with a valid context, which records unless a sampler dropped it.""" |
| 32 | |
| 33 | def __init__(self, attributes: Any, *, sampled: bool) -> None: |
| 34 | flags = TraceFlags(TraceFlags.SAMPLED if sampled else TraceFlags.DEFAULT) |
| 35 | super().__init__(SpanContext(trace_id=1, span_id=1, is_remote=False, trace_flags=flags)) |
| 36 | self.attributes: dict[str, Any] = dict(attributes or {}) |
| 37 | self.sampled = sampled |
| 38 | self.ended = False |
| 39 | |
| 40 | @override |
| 41 | def is_recording(self) -> bool: |
| 42 | return self.sampled and not self.ended |
| 43 | |
| 44 | @override |
| 45 | def set_attribute(self, key: str, value: Any) -> None: |
| 46 | self.attributes[key] = value |
| 47 | |
| 48 | @override |
| 49 | def end(self, end_time: int | None = None) -> None: |
| 50 | self.ended = True |
| 51 | |
| 52 | |
| 53 | class RecordingTracer(Tracer): |