Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit d1f156c

Browse files
fix: sentry source context (#940)
1 parent fb400f2 commit d1f156c

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ NOTE: all releases may include dependency updates, not specifically mentioned
77
## UNRELEASED
88

99
- feat: integrate try-as library [#912](https://github.com/hypermodeinc/modus/pull/912)
10+
- fix: sentry source context [#940](https://github.com/hypermodeinc/modus/pull/940)
1011

1112
## 2025-07-09 - Runtime v0.18.4
1213

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
5757
# copy runtime binary from the build phase
5858
COPY --from=builder /src/runtime/modus_runtime /usr/bin/modus_runtime
5959

60+
# copy the runtime source code to the container (for Sentry source context)
61+
# keep only go source files and remove tests
62+
COPY ./runtime /src/runtime/
63+
COPY ./lib /src/lib/
64+
RUN find /src -type f ! -name '*.go' -delete && \
65+
find /src -type f -name '*_test.go' -delete && \
66+
find /src -type d -name '*test*' -exec rm -rf {} +
67+
6068
# update certificates and time zones every build
6169
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
6270
ca-certificates \

runtime/sentryutils/sentry.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,20 @@ import (
2626

2727
const max_breadcrumbs = 100
2828

29+
// NOTE: If this code is moved, adjust these constants accordingly.
30+
const thisPackageDepth = 1 // root is 0
31+
const thisPackagePath = "github.com/hypermodeinc/modus/runtime/sentryutils"
32+
2933
var rootSourcePath = func() string {
30-
pc, filename, _, ok := runtime.Caller(0)
34+
_, filename, _, ok := runtime.Caller(0)
3135
if !ok {
3236
return ""
3337
}
34-
35-
callerName := runtime.FuncForPC(pc).Name()
36-
depth := strings.Count(callerName, "/") + 1
37-
s := filename
38-
for range depth {
39-
s = path.Dir(s)
40-
}
41-
return s + "/"
42-
}()
43-
44-
var thisPackagePath = func() string {
45-
pc, _, _, ok := runtime.Caller(0)
46-
if !ok {
47-
return ""
38+
dir := path.Dir(filename)
39+
for range thisPackageDepth {
40+
dir = path.Dir(dir)
4841
}
49-
50-
callerName := runtime.FuncForPC(pc).Name()
51-
i := max(strings.LastIndexByte(callerName, '/'), 0)
52-
j := strings.IndexByte(callerName[i:], '.')
53-
return callerName[0 : i+j]
42+
return dir + "/"
5443
}()
5544

5645
func InitializeSentry() {

0 commit comments

Comments
 (0)