gpt4 book ai didi

logging - 如何在 F# Fable 中登录 Application Insights?

转载 作者:行者123 更新时间:2023-12-02 12:07:17 26 4
gpt4 key购买 nike

我正在开发一个SAFE F# 中的应用程序,其中一部分是将一些日志发送到 Azure 中的 Application Insights。服务器端日志记录有点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()

现在我想在《寓言》的客户端做类似的事情。我有一个 AI key ,我需要以某种方式将数据发送到 Azure。相同的代码不会转换为 JS。

最佳答案

这可以通过 dynamic programming 来实现《寓言》中。

  1. package.json中添加AI JS依赖:
{
...
"devDependencies": {
...
"applicationinsights-js": "^1.0.20"
}
}
  • webpack.config.js 中反射(reflect)它:
  • 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

    也许有更充分和/或类型安全的方法,但这可行。

    关于logging - 如何在 F# Fable 中登录 Application Insights?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56145536/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com