[英]How to log to Application Insights in F# Fable?
I am developing a SAFE application in F#, and part of it is sending some logs to Application Insights in Azure. 我正在使用F#开发一个SAFE应用程序,其中一部分是将一些日志发送到Azure中的Application Insights。 Server side logging is somewhat easy :
服务器端日志记录有点简单 :
open Microsoft.ApplicationInsights
open Microsoft.ApplicationInsights.Extensibility
let getTelemetryClient() =
let key = <key>
TelemetryConfiguration.Active.InstrumentationKey <- key
TelemetryClient()
let log (message : string) =
let logger = (lazy getTelemetryClient()).Value
logger.TrackTrace message
logger.Flush()
Now I want to do something similar in the client side, in Fable. 现在我想在Fable的客户端做类似的事情。 I have an AI key and I somehow need to send the data to Azure.
我有一个AI密钥,我不知何故需要将数据发送到Azure。 The same code does not transpile to JS.
相同的代码不会转化为JS。
This can be achieved by means of dynamic programming in Fable. 这可以通过Fable中的动态编程来实现。
package.json
: package.json
添加AI JS依赖项: {
...
"devDependencies": {
...
"applicationinsights-js": "^1.0.20"
}
}
webpack.config.js
: webpack.config.js
反映出来: fsharpEntry: {
"app": [
...
"applicationinsights-js"
]
}
open Fable.Core.JsInterop
open Fable.Import.Browser
let setup() =
let key = <key>
let config = createObj [ "instrumentationKey" ==> key ]
window?appInsights?downloadAndSetup config
let log message = window?appInsights?trackTrace message
Maybe there are more adequate and/or type-safe ways, yet this works. 也许有更充分和/或类型安全的方式,但这是有效的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.