dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

chore(telemetry): register after fork hooks on initialization

Open mabdinur opened this issue 3 years ago • 0 comments

Description

app-started, app-closed, and app-heartbeat telemetry events should not be sent in a child processes. To avoid sending these events in child processes forksafe.register(TelemetryWriter._fork_writer) needs to be called as early as possible.

Currently TelemetryWriter._fork_writer is registered in TelemetryWriter.enabled() and this method is called right before the first trace is sent to the agent. Registering TelemetryWriter._fork_writer in TelemetryWriter.__init__() instead will reduce the likelihood that telemetry events get sent in child processes since the telemetry_writer is initialized on import ddtrace (ddtrace/__init__.py imports ddtrace/tracer.py which import ddtrace/internal/writer.py which imports ddtrace/internal/telemetry/__init__.py).

Note - This does not prevent the ddtrace library from sending telemetry in all child processes. If ddtrace is imported after the main process forks this issue can still occur.

Checklist

Motivation

Design

Testing strategy

Relevant issue(s)

Testing strategy

Reviewer Checklist

  • [ ] Title is accurate.
  • [ ] Description motivates each change.
  • [ ] No unnecessary changes were introduced in this PR.
  • [ ] PR cannot be broken up into smaller PRs.
  • [ ] Avoid breaking API changes unless absolutely necessary.
  • [ ] Tests provided or description of manual testing performed is included in the code or PR.
  • [ ] Release note has been added for fixes and features, or else changelog/no-changelog label added.
  • [ ] All relevant GitHub issues are correctly linked.
  • [ ] Backports are identified and tagged with Mergifyio.
  • [ ] Add to milestone.

mabdinur avatar Oct 14 '22 15:10 mabdinur