Skip to content

feat(ourlogs): canonicalize paths from the logger integration #4336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025

Conversation

colin-sentry
Copy link
Member

@colin-sentry colin-sentry commented Apr 28, 2025

We'd like to allow linking to the 'source code' line in the logs page - this canonicalizes the path relative to the project root (if one is defined)

Screenshot 2025-04-28 at 12 03 45 PM

Solves LOGS-58

@colin-sentry colin-sentry requested a review from a team as a code owner April 28, 2025 16:03
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.29%. Comparing base (7f01372) to head (81797d1).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/logging.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4336      +/-   ##
==========================================
- Coverage   80.29%   80.29%   -0.01%     
==========================================
  Files         142      142              
  Lines       15934    15937       +3     
  Branches     2726     2727       +1     
==========================================
+ Hits        12794    12796       +2     
- Misses       2263     2267       +4     
+ Partials      877      874       -3     
Files with missing lines Coverage Δ
sentry_sdk/integrations/logging.py 82.80% <50.00%> (-0.32%) ⬇️

... and 4 files with indirect coverage changes

Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please address comment before merging @colin-sentry. A test case would also be awesome

@@ -374,7 +375,10 @@ def _capture_log_from_record(client, record):
if record.lineno:
attrs["code.line.number"] = record.lineno
if record.pathname:
attrs["code.file.path"] = record.pathname
if record.pathname.startswith(project_root):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project_root might be None so we need to be more careful here:

Suggested change
if record.pathname.startswith(project_root):
if project_root is not None and record.pathname.startswith(project_root):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, test added too

Verified

This commit was signed with the committer’s verified signature.

Verified

This commit was signed with the committer’s verified signature.
@colin-sentry colin-sentry force-pushed the canonicalize_logger_paths branch from d946062 to 81797d1 Compare April 29, 2025 17:46
@colin-sentry colin-sentry enabled auto-merge (squash) April 29, 2025 17:46
@colin-sentry colin-sentry merged commit 2f54dbd into master Apr 29, 2025
134 of 135 checks passed
@colin-sentry colin-sentry deleted the canonicalize_logger_paths branch April 29, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants