tangled
alpha
login
or
join now
stream.place
/
streamplace
74
fork
atom
Live video on the AT Protocol
74
fork
atom
overview
issues
1
pulls
pipelines
sentry dsn injection only on web
Natalie Bridgers
6 months ago
8f141ae0
31a40d70
+41
-12
5 changed files
expand all
collapse all
unified
split
js
app
components
provider
provider.shared.tsx
pkg
api
api.go
config
config.go
linking
linking.go
linking_test.go
+12
-1
js/app/components/provider/provider.shared.tsx
···
26
26
import * as Application from "expo-application";
27
27
import Constants from "expo-constants";
28
28
import * as Updates from "expo-updates";
29
29
+
import { Platform } from "react-native";
29
30
Sentry.setExtras({
30
31
manifest: Updates.manifest,
31
32
linkingUri: Constants.linkingUri,
···
44
45
children: React.ReactNode;
45
46
linking: LinkingOptions<ReactNavigation.RootParamList>;
46
47
}) {
48
48
+
// get proper DSN for environment
49
49
+
// on ios/android it's process.env.EXPO_PUBLIC_SENTRY_DSN
50
50
+
// on web it will be injected at runtime
51
51
+
let dsn = undefined;
52
52
+
if (Platform.OS === "web") {
53
53
+
dsn = (window as any).SENTRY_DSN;
54
54
+
} else {
55
55
+
dsn = process.env.EXPO_PUBLIC_SENTRY_DSN || undefined;
56
56
+
}
57
57
+
47
58
Sentry.init({
48
48
-
dsn: process.env.EXPO_PUBLIC_SENTRY_DSN || undefined,
59
59
+
dsn,
49
60
// Adds more context data to events (IP address, cookies, user, etc.)
50
61
// For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/
51
62
sendDefaultPii: true,
+2
-2
pkg/api/api.go
···
314
314
return
315
315
}
316
316
if errors.Is(err, ErrorIndex) || f == "" {
317
317
-
bs, err := linker.GenerateDefaultCard(ctx, req.URL)
317
317
+
bs, err := linker.GenerateDefaultCard(ctx, req.URL, a.CLI.SentryDSN)
318
318
if err != nil {
319
319
log.Error(ctx, "error generating default card", "error", err)
320
320
}
···
357
357
defaultHandler.ServeHTTP(w, req)
358
358
return
359
359
}
360
360
-
bs, err := linker.GenerateStreamerCard(ctx, req.URL, lsv)
360
360
+
bs, err := linker.GenerateStreamerCard(ctx, req.URL, lsv, a.CLI.SentryDSN)
361
361
if err != nil {
362
362
log.Error(ctx, "error generating html", "error", err)
363
363
defaultHandler.ServeHTTP(w, req)
+2
pkg/config/config.go
···
116
116
LivepeerHelp bool
117
117
PLCURL string
118
118
SQLLogging bool
119
119
+
SentryDSN string
119
120
}
120
121
121
122
func (cli *CLI) NewFlagSet(name string) *flag.FlagSet {
···
180
181
fs.BoolVar(&cli.LivepeerHelp, "livepeer-help", false, "print help for livepeer flags and exit")
181
182
fs.StringVar(&cli.PLCURL, "plc-url", "https://plc.directory", "url of the plc directory")
182
183
fs.BoolVar(&cli.SQLLogging, "sql-logging", false, "enable sql logging")
184
184
+
fs.StringVar(&cli.SentryDSN, "sentry-dsn", "", "sentry dsn for error reporting")
183
185
184
186
lpFlags := flag.NewFlagSet("livepeer", flag.ContinueOnError)
185
187
_ = starter.NewLivepeerConfig(lpFlags)
+24
-8
pkg/linking/linking.go
···
25
25
}
26
26
27
27
type PageConfig struct {
28
28
-
Title string
29
29
-
Metas []MetaTag
28
28
+
Title string
29
29
+
Metas []MetaTag
30
30
+
SentryDSN string
30
31
}
31
32
32
33
// Define all meta tags in a structured way
···
36
37
Content string
37
38
}
38
39
39
39
-
func (l *Linker) GenerateStreamerCard(ctx context.Context, u *url.URL, lsv *streamplace.Livestream_LivestreamView) ([]byte, error) {
40
40
+
func (l *Linker) GenerateStreamerCard(ctx context.Context, u *url.URL, lsv *streamplace.Livestream_LivestreamView, sentryDSN string) ([]byte, error) {
40
41
if u == nil {
41
42
return nil, errors.New("url is nil")
42
43
}
···
79
80
}
80
81
81
82
return l.GenerateHTML(ctx, &PageConfig{
82
82
-
Title: pageTitle,
83
83
-
Metas: metaTags,
83
83
+
Title: pageTitle,
84
84
+
Metas: metaTags,
85
85
+
SentryDSN: sentryDSN,
84
86
})
85
87
}
86
88
87
87
-
func (l *Linker) GenerateDefaultCard(ctx context.Context, u *url.URL) ([]byte, error) {
89
89
+
func (l *Linker) GenerateDefaultCard(ctx context.Context, u *url.URL, sentryDSN string) ([]byte, error) {
88
90
if u == nil {
89
91
return nil, errors.New("url is nil")
90
92
}
···
114
116
}
115
117
116
118
return l.GenerateHTML(ctx, &PageConfig{
117
117
-
Title: "Stream.place",
118
118
-
Metas: metaTags,
119
119
+
Title: "Stream.place",
120
120
+
Metas: metaTags,
121
121
+
SentryDSN: sentryDSN,
119
122
})
120
123
}
121
124
···
180
183
{Key: tag.Type, Val: tag.Key},
181
184
{Key: "content", Val: tag.Content},
182
185
},
186
186
+
})
187
187
+
}
188
188
+
189
189
+
// Add Sentry DSN script if configured
190
190
+
if pc.SentryDSN != "" {
191
191
+
script := &html.Node{
192
192
+
Type: html.ElementNode,
193
193
+
Data: "script",
194
194
+
}
195
195
+
head.AppendChild(script)
196
196
+
script.AppendChild(&html.Node{
197
197
+
Type: html.TextNode,
198
198
+
Data: `window.SENTRY_DSN = "` + pc.SentryDSN + `";`,
183
199
})
184
200
}
185
201
+1
-1
pkg/linking/linking_test.go
···
62
62
Record: &lexutil.LexiconTypeDecoder{Val: ls},
63
63
Uri: "at://did:plc:2zmxikig2sj7gqaezl5gntae/place.stream.livestream/3ll5zuop2k22x",
64
64
}
65
65
-
linkCard, err := linker.GenerateStreamerCard(context.Background(), u, lsv)
65
65
+
linkCard, err := linker.GenerateStreamerCard(context.Background(), u, lsv, "")
66
66
require.NoError(t, err)
67
67
linkStr := string(linkCard)
68
68
require.True(t, strings.Contains(linkStr, "iame.li"))