|
35 | 35 | from .internal import debug |
36 | 36 | from .internal import forksafe |
37 | 37 | from .internal import hostname |
38 | | -from .internal import service |
39 | 38 | from .internal.dogstatsd import get_dogstatsd_client |
40 | 39 | from .internal.logger import get_logger |
41 | 40 | from .internal.logger import hasHandlers |
|
46 | 45 | from .internal.processor.trace import TraceTagsProcessor |
47 | 46 | from .internal.processor.trace import TraceTopLevelSpanProcessor |
48 | 47 | from .internal.runtime import get_runtime_id |
| 48 | +from .internal.service import ServiceStatusError |
49 | 49 | from .internal.utils.formats import asbool |
50 | 50 | from .internal.writer import AgentWriter |
51 | 51 | from .internal.writer import LogWriter |
@@ -332,8 +332,8 @@ def configure( |
332 | 332 |
|
333 | 333 | try: |
334 | 334 | self._writer.stop() |
335 | | - except service.ServiceStatusError: |
336 | | - # It's possible the writer never got started in the first place :( |
| 335 | + except ServiceStatusError: |
| 336 | + # It's possible the writer never got started |
337 | 337 | pass |
338 | 338 |
|
339 | 339 | if writer is not None: |
@@ -394,7 +394,20 @@ def _child_after_fork(self): |
394 | 394 |
|
395 | 395 | self._new_process = True |
396 | 396 |
|
397 | | - def start_span( |
| 397 | + def _start_span_after_shutdown( |
| 398 | + self, |
| 399 | + name, # type: str |
| 400 | + child_of=None, # type: Optional[Union[Span, Context]] |
| 401 | + service=None, # type: Optional[str] |
| 402 | + resource=None, # type: Optional[str] |
| 403 | + span_type=None, # type: Optional[str] |
| 404 | + activate=False, # type: bool |
| 405 | + ): |
| 406 | + # type: (...) -> Span |
| 407 | + log.warning("Spans started after the tracer has been shut down will not be sent to the Datadog Agent.") |
| 408 | + return self._start_span(name, child_of, service, resource, span_type, activate) |
| 409 | + |
| 410 | + def _start_span( |
398 | 411 | self, |
399 | 412 | name, # type: str |
400 | 413 | child_of=None, # type: Optional[Union[Span, Context]] |
@@ -589,6 +602,8 @@ def start_span( |
589 | 602 | self._hooks.emit(self.__class__.start_span, span) |
590 | 603 | return span |
591 | 604 |
|
| 605 | + start_span = _start_span |
| 606 | + |
592 | 607 | def _on_span_finish(self, span): |
593 | 608 | # type: (Span) -> None |
594 | 609 | active = self.current_span() |
@@ -878,6 +893,8 @@ def shutdown(self, timeout=None): |
878 | 893 | atexit.unregister(self._atexit) |
879 | 894 | forksafe.unregister(self._child_after_fork) |
880 | 895 |
|
| 896 | + self.start_span = self._start_span_after_shutdown # type: ignore[assignment] |
| 897 | + |
881 | 898 | @staticmethod |
882 | 899 | def _use_log_writer(): |
883 | 900 | # type: () -> bool |
|
0 commit comments