Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/sentry/integrations/perforce/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ def get_blame_for_files(
# already part of the depot path we get from stacktrace (SourceLineInfo)
depot_path = self.build_depot_path(file.repo, file.path, None)

# If revision is available from symcache, append it to depot path
# This allows us to get the exact changelist that created this revision
if file.revision:
depot_path = f"{depot_path}#{file.revision}"

# Use p4 changes -m 1 -l to get most recent change for this file
# -m 1: limit to 1 result (most recent)
# -l: include full changelist description
Expand Down Expand Up @@ -554,6 +559,7 @@ def get_blame_for_files(
ref=file.ref,
repo=file.repo,
code_mapping=file.code_mapping,
revision=file.revision,
commit=commit,
)
blames.append(blame_info)
Expand Down
16 changes: 16 additions & 0 deletions src/sentry/integrations/perforce/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ def source_url_matches(self, url: str) -> bool:

return False

def get_stacktrace_link(
Copy link
Member

Choose a reason for hiding this comment

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

The default get_stacktrace_link implementation has some tags being set on the scope. Are these applicable here?

Example

scope.set_tag("stacktrace_link.tried_version", False)

Not sure if it's strictly necessary in this PR but we'd also eventually want to have SLOs for this function because the parent implementation is being overwritten

with self.record_event(
SCMIntegrationInteractionType.GET_STACKTRACE_LINK
).capture() as lifecycle:

self, repo: Repository, filepath: str, default: str, version: str | None
) -> str | None:
"""
Get stacktrace link for Perforce file.

For Perforce, version represents the file revision number.
We append it to the filepath using Perforce's #revision syntax.
"""
# Append version/revision to filepath if provided
if version:
filepath = f"{filepath}#{version}"

# Use parent implementation with the modified filepath
return self.check_file(repo, filepath, default)

def check_file(self, repo: Repository, filepath: str, branch: str | None = None) -> str | None:
"""
Check if a file exists in the Perforce depot and return the URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SourceLineInfo:
ref: str
repo: Repository
code_mapping: RepositoryProjectPathConfig
revision: str | None


@dataclass
Expand Down
1 change: 1 addition & 0 deletions src/sentry/integrations/utils/commit_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def _generate_integration_to_files_mapping(
ref=code_mapping.default_branch or "master",
repo=code_mapping.repository,
code_mapping=code_mapping,
revision=frame.revision,
)
)
break
Expand Down
4 changes: 3 additions & 1 deletion src/sentry/integrations/utils/stacktrace_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def get_stacktrace_config(
result["error"] = "stack_root_mismatch"
continue

outcome = get_link(config, src_path, ctx["commit_id"])
# Use commit_id if available, otherwise fall back to revision (from symcache)
version = ctx["commit_id"] if ctx["commit_id"] else ctx.get("revision")
outcome = get_link(config, src_path, version)
result["iteration_count"] += 1

result["current_config"] = {
Expand Down
4 changes: 4 additions & 0 deletions src/sentry/interfaces/stacktrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def to_python(cls, data, **kwargs):
"platform",
"post_context",
"pre_context",
"revision",
"source_link",
"symbol",
"symbol_addr",
Expand Down Expand Up @@ -198,6 +199,7 @@ def to_json(self):
"lineno": self.lineno,
"colno": self.colno,
"lock": self.lock,
"revision": self.revision or None,
"source_link": self.source_link or None,
}
)
Expand Down Expand Up @@ -233,6 +235,7 @@ def get_api_context(self, is_public=False, platform=None, pad_addr=None):
"trust": self.trust,
"errors": self.errors,
"lock": self.lock,
"revision": self.revision,
"sourceLink": source_link,
}

Expand Down Expand Up @@ -291,6 +294,7 @@ def get_meta_context(self, meta, is_public=False, platform=None):
"trust": meta.get("trust"),
"errors": meta.get("errors"),
"lock": meta.get("lock"),
"revision": meta.get("revision"),
"sourceLink": meta.get("source_link"),
}

Expand Down
4 changes: 3 additions & 1 deletion src/sentry/issues/endpoints/project_stacktrace_link.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import TypedDict
from typing import NotRequired, TypedDict

from django.http import QueryDict
from rest_framework.request import Request
Expand Down Expand Up @@ -36,6 +36,7 @@ class StacktraceLinkContext(TypedDict):
module: str | None
package: str | None
sdk_name: str | None
revision: NotRequired[str | None]


def generate_context(parameters: QueryDict) -> StacktraceLinkContext:
Expand All @@ -51,6 +52,7 @@ def generate_context(parameters: QueryDict) -> StacktraceLinkContext:
"package": parameters.get("package"),
"line_no": parameters.get("lineNo"),
"group_id": parameters.get("groupId"),
"revision": parameters.get("revision"),
}


Expand Down
2 changes: 2 additions & 0 deletions src/sentry/lang/native/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def _merge_frame(new_frame, symbolicated, platform="native"):
new_frame["post_context"] = symbolicated["post_context"]
if symbolicated.get("source_link"):
new_frame["source_link"] = symbolicated["source_link"]
if symbolicated.get("revision"):
new_frame["revision"] = symbolicated["revision"]

addr_mode = symbolicated.get("addr_mode")
if addr_mode is None:
Expand Down
1 change: 1 addition & 0 deletions src/sentry/utils/event_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class EventFrame:
function: str | None = None
package: str | None = None
module: str | None = None
revision: str | None = None
Copy link
Member

Choose a reason for hiding this comment

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

Will the frame dictionaries contain revision in order for this to work?

EventFrame.from_dict(frame)
for frame in frames
if frame.get("lineno") is not None and frame.get("in_app")


@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> EventFrame:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down Expand Up @@ -61,6 +62,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down Expand Up @@ -61,6 +62,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down Expand Up @@ -61,6 +62,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down Expand Up @@ -61,6 +62,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand All @@ -51,6 +52,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: Class.myfunc
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down Expand Up @@ -71,6 +72,7 @@ get_api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: tests/sentry/event_manager/interfaces/test_threads.py
source: tests/sentry/event_manager/interfaces/test_threads.py::test_basics
---
api_context:
values:
Expand Down Expand Up @@ -30,6 +30,7 @@ api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand All @@ -54,6 +55,7 @@ api_context:
package: null
platform: null
rawFunction: null
revision: null
sourceLink: null
symbol: null
symbolAddr: null
Expand Down
Loading
Loading