Skip to content

Commit 3e4cc5c

Browse files
committed
feat: exception analytics
1 parent c86a24f commit 3e4cc5c

File tree

13 files changed

+111
-33
lines changed

13 files changed

+111
-33
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
]
1616
},
1717
"fable": {
18-
"version": "3.7.2",
18+
"version": "3.7.4",
1919
"commands": [
2020
"fable"
2121
]

RELEASE_NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
1.3.0 - 27 Feb 2022
2+
- Improved Host validation pattern
3+
- Improved PI error messages
4+
- Relaxed Homebridge schema requirements
5+
- Fallback for layout unavailability
6+
- Exception analytics
7+
- Dependencies update
8+
19
1.2.0 - 9 Feb 2022
210
- New accessory selector show all accessories and disable not compatible accessories
311
- Added support for accessories outside of room layout

src/StreamDeck.Homebridge/App.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ let connectElgatoStreamDeckSocket (inPort:string, inUUID:string, inMessageType:s
3535
let agent = PluginAgent.createPluginAgent()
3636
connectPlugin args agent
3737
| "registerPropertyInspector" ->
38-
let subcribe model =
38+
let subscribe model =
3939
let sub (dispatch: PiView.PiMsg -> unit) =
4040
let agent = PiAgent.createPiAgent dispatch
4141
connectPropertyInspector args agent
4242
Cmd.ofSub sub
4343

4444
Program.mkProgram (PiView.init false) PiView.update PiView.view
45-
|> Program.withSubscription subcribe
45+
|> Program.withSubscription subscribe
4646
|> Program.withReactBatched "elmish-app"
4747
|> Program.run
4848
| _ ->

src/StreamDeck.Homebridge/Domain.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ let inline tryParse<'t> (setting:obj) : 't option =
2626
|> Option.bind (fun json ->
2727
match Json.tryConvertFromJsonAs json with
2828
| Ok x -> Some x
29-
| _ -> None
30-
)
29+
| Error e ->
30+
GTag.logException e
31+
None
32+
)

src/StreamDeck.Homebridge/GTag.fs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module StreamDeck.Homebridge.GTag
2+
3+
open Fable.Core
4+
5+
[<Emit("gtag('event', $0, $1)")>]
6+
let private log (eventName: string) (eventParams: obj): unit = jsNative
7+
8+
/// gtag('event', 'exception', {
9+
/// 'description': 'error_description',
10+
/// 'fatal': false // set to true if the error is fatal
11+
/// });
12+
let logException (description: string) =
13+
log "exception" {|
14+
description = description
15+
fatal = false
16+
|}
17+
18+
/// gtag('event', <action>, {
19+
/// 'event_category': <category>,
20+
/// 'event_label': <label>,
21+
/// 'value': <value>
22+
/// });
23+
let logEvent (action: string) (category: string) (label:string) (value:int) =
24+
log action {|
25+
event_category = category
26+
event_label = label
27+
value = value
28+
|}

src/StreamDeck.Homebridge/HomebridgeClient.fs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,52 +98,55 @@ let authenticate (serverInfo:Domain.GlobalSettings) =
9898
username = serverInfo.UserName
9999
password = serverInfo.Password
100100
|}
101-
let! responce =
101+
let! response =
102102
Http.request $"{serverInfo.Host}/api/auth/login"
103103
|> Http.method POST
104104
|> Http.content (BodyContent.Text body)
105105
|> Http.header (Headers.contentType "application/json")
106106
|> Http.withTimeout 5_000
107107
|> Http.send
108108
return
109-
if responce.statusCode = 201 then
110-
Json.tryParseAs<AuthResult> responce.responseText
111-
else Error ($"Unsuccessful login: Server is unavailable or login/password is incorrect. {responce.responseText}")
109+
if response.statusCode = 201 then
110+
Json.tryParseAs<AuthResult> response.responseText
111+
else
112+
let msg = $"Unsuccessful login: Server is unavailable or login/password is incorrect. {response.responseText}"
113+
GTag.logException msg
114+
Error msg
112115
}
113116

114117
let getConfigEditorInfo host (auth:AuthResult) =
115118
async {
116-
let! responce =
119+
let! response =
117120
Http.request $"%s{host}/api/config-editor"
118121
|> sendWithAuth auth
119122
return
120-
if responce.statusCode = 200 then
121-
Json.tryParseAs<ConfigEditorInfo> responce.responseText
122-
else Error ($"Cannot get config editor info from {host}. {responce.responseText}")
123+
if response.statusCode = 200 then
124+
Json.tryParseAs<ConfigEditorInfo> response.responseText
125+
else Error ($"Cannot get config editor info from {host}. {response.responseText}")
123126
}
124127

125128
let getAccessories host (auth:AuthResult) =
126129
async {
127-
let! responce =
130+
let! response =
128131
Http.request $"%s{host}/api/accessories"
129132
|> Http.withTimeout 20_000
130133
|> sendWithAuth auth
131134
return
132-
if responce.statusCode = 200 then
133-
Json.tryParseAs<AccessoryDetails[]> responce.responseText
134-
else Error ($"Cannot get accessories list from {host}. {responce.responseText}")
135+
if response.statusCode = 200 then
136+
Json.tryParseAs<AccessoryDetails[]> response.responseText
137+
else Error ($"Cannot get accessories list from {host}. {response.responseText}")
135138
}
136139

137140
let getAccessoriesLayout host (auth:AuthResult) =
138141
async {
139-
let! responce =
142+
let! response =
140143
Http.request $"%s{host}/api/accessories/layout"
141144
|> Http.withTimeout 20_000
142145
|> sendWithAuth auth
143146
return
144-
if responce.statusCode = 200 then
145-
Json.tryParseAs<RoomLayout[]> responce.responseText
146-
else Error ($"Cannot get room layout from {host}. {responce.responseText}")
147+
if response.statusCode = 200 then
148+
Json.tryParseAs<RoomLayout[]> response.responseText
149+
else Error ($"Cannot get room layout from {host}. {response.responseText}")
147150
}
148151

149152
let setAccessoryCharacteristic host (auth:AuthResult) (uniqueId:string) (characteristicType:string) (value:obj) =
@@ -152,24 +155,24 @@ let setAccessoryCharacteristic host (auth:AuthResult) (uniqueId:string) (charact
152155
characteristicType = characteristicType
153156
value = value
154157
|}
155-
let! responce =
158+
let! response =
156159
Http.request $"%s{host}/api/accessories/{uniqueId}"
157160
|> Http.method PUT
158161
|> Http.content (BodyContent.Text body)
159162
|> sendWithAuth auth
160163
return
161-
if responce.statusCode = 200 then
162-
Json.tryParseAs<AccessoryDetails> responce.responseText
163-
else Error ($"Cannot set accessory '{uniqueId}' characteristic '{characteristicType}' to '{value}'. {responce.responseText}")
164+
if response.statusCode = 200 then
165+
Json.tryParseAs<AccessoryDetails> response.responseText
166+
else Error ($"Cannot set accessory '{uniqueId}' characteristic '{characteristicType}' to '{value}'. {response.responseText}")
164167
}
165168

166169
let getAccessory host (auth:AuthResult) (uniqueId:string)=
167170
async {
168-
let! responce =
171+
let! response =
169172
Http.request $"%s{host}/api/accessories/{uniqueId}"
170173
|> sendWithAuth auth
171174
return
172-
if responce.statusCode = 200 then
173-
Json.tryParseAs<AccessoryDetails> responce.responseText
174-
else Error ($"Cannot get accessory by id '{uniqueId}'. {responce.responseText}")
175-
}
175+
if response.statusCode = 200 then
176+
Json.tryParseAs<AccessoryDetails> response.responseText
177+
else Error ($"Cannot get accessory by id '{uniqueId}'. {response.responseText}")
178+
}

src/StreamDeck.Homebridge/PiView.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ let update (msg:PiMsg) (model:PiModel) =
168168
match model.AuthInfo with
169169
| Ok auth ->
170170
let! layout= Client.getAccessoriesLayout model.ServerInfo.Host auth
171-
let layout = match layout with | Ok layout -> layout | Error _ -> [||]
171+
let layout =
172+
match layout with
173+
| Ok layout -> layout
174+
| Error err ->
175+
GTag.logException err
176+
[||]
172177
let! accessories = Client.getAccessories model.ServerInfo.Host auth
173178

174179
match accessories with
@@ -218,6 +223,7 @@ let update (msg:PiMsg) (model:PiModel) =
218223
}
219224
state, Cmd.none
220225
| ResetLoading error ->
226+
GTag.logException error
221227
{ model with IsLoading = Error error}, Cmd.none
222228
| SelectActionType actionType ->
223229
{ model with ActionType = actionType}, Cmd.none
@@ -496,4 +502,4 @@ let view model dispatch =
496502
OnClick (fun _ -> dispatch <| Logout)
497503
] [ str "Logout" ]
498504
]
499-
]
505+
]

src/StreamDeck.Homebridge/PluginAgent.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let createPluginAgent() :MailboxProcessor<PluginIn_Events> =
2525
| PluginIn_KeyUp(event, payload) ->
2626
let onError (message:string) =
2727
console.warn(message)
28+
GTag.logException message
2829
replyAgent.Post <| PluginOut_LogMessage message
2930
replyAgent.Post <| PluginOut_ShowAlert event.context
3031

@@ -82,4 +83,3 @@ let createPluginAgent() :MailboxProcessor<PluginIn_Events> =
8283
}
8384
idle()
8485
)
85-

src/StreamDeck.Homebridge/StreamDeck.Homebridge.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
7+
<Compile Include="GTag.fs" />
78
<Compile Include="Domain.fs" />
89
<Compile Include="HomebridgeClient.fs" />
910
<Compile Include="PiView.fs" />

src/com.sergeytihon.homebridge.sdPlugin/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
background-color: transparent;
1010
}
1111
</style>
12+
<!-- Global site tag (gtag.js) - Google Analytics -->
13+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-VG4T7K8X59"></script>
14+
<script>
15+
window.dataLayer = window.dataLayer || [];
16+
function gtag(){dataLayer.push(arguments);}
17+
gtag('js', new Date());
18+
19+
gtag('config', 'G-VG4T7K8X59');
20+
</script>
1221
</head>
1322

1423
<body>

0 commit comments

Comments
 (0)