Skip to content

Commit

Permalink
chore(telemetry): make logs less noisy and more clear [backport 2.19] (
Browse files Browse the repository at this point in the history
…#11876)

Backport 33b2499 from #11853 to 2.19.

Partially Resolves: #10842

- Removes exception traceback from telemetry client logs. We should not
generate a traceback everytime we fail to send telemetry payloads to the
agent. This traceback is noisy and not actionable.
- Updates telemetry client log message to clearly state that
instrumentation telemetry failed to send and not user telemetry (ex:
traces, logs, metrics).

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

Co-authored-by: Munir Abdinur <[email protected]>
Co-authored-by: Emmett Butler <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 3d0089c commit 8d79908
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions ddtrace/internal/telemetry/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ def send_event(self, request: Dict) -> Optional[httplib.HTTPResponse]:
conn.request("POST", self._endpoint, rb_json, headers)
resp = get_connection_response(conn)
if resp.status < 300:
log.debug("sent %d in %.5fs to %s. response: %s", len(rb_json), sw.elapsed(), self.url, resp.status)
log.debug(
"Instrumentation Telemetry sent %d in %.5fs to %s. response: %s",
len(rb_json),
sw.elapsed(),
self.url,
resp.status,
)
else:
log.debug("failed to send telemetry to %s. response: %s", self.url, resp.status)
except Exception:
log.debug("failed to send telemetry to %s.", self.url, exc_info=True)
log.debug("Failed to send Instrumentation Telemetry to %s. response: %s", self.url, resp.status)
except Exception as e:
log.debug("Failed to send Instrumentation Telemetry to %s. Error: %s", self.url, str(e))
finally:
if conn is not None:
conn.close()
Expand Down
2 changes: 1 addition & 1 deletion tests/telemetry/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def test_send_failing_request(mock_status, telemetry_writer):
telemetry_writer.periodic(force_flush=True)
# asserts unsuccessful status code was logged
log.debug.assert_called_with(
"failed to send telemetry to %s. response: %s",
"Failed to send Instrumentation Telemetry to %s. response: %s",
telemetry_writer._client.url,
mock_status,
)
Expand Down

0 comments on commit 8d79908

Please sign in to comment.