TL; DR 数据
这个 @hyperledger/aries-remote-logs 软件包提供了简单的发送方式 信条 (克里多)日志到远程 罗基 服务器.
使用量
此软件包允许将 Credo 日志的副本发送到远程的 Loki 服务器 。 这对于在日志不易访问的环境中调试问题有用,但需要日志来提供 三级 支助.
由于可核查的证书和数字身份的敏感性一般,日志不会自动发送. 相反,必须启用这一功能。 没错 高度建议 该特性在生产环境中默认被禁用,并且只有在最终用户需要时才启用,甚至会在短时间内自动被禁用.
考虑因素
当远程记录启用时 RemoteLogger 将自动生成会话ID。 此ID随后被设定为发送到远程服务器的所有日志上的标签 。 这允许通过会话ID过滤日志. 这在调试单个用户特有的问题时有用.
当终端用户启用远程日志时, 将会向他们展示会话ID 。 身份证应记录在案并提供给支助小组。 支援小组然后可以使用这个ID来识别正确的日志. 此会话ID也有助于最小化日志与终端用户的芯片连接.

用以下代码获取会话ID:
// ...
const { agent } = useAgent()
const logger = agent?.config.logger as RemoteLogger
console.log(`Session ID: ${logger.sessionId}`)
配置
这个 RemoteLogger 配置了一组选项。 这些选项将传递给 RemoteLogger 课。 备选方案如下:
| 选项 | 类型 | 说明 |
|---|---|---|
lokiUrl | string | Loki服务器的完整 URL . |
lokiLabels | Record<string, string> | 一组标签将应用于发送到Loki服务器的所有日志. |
autoDisableRemoteLoggingIntervalInMinutes | number | 自动禁用远程日志前的等待分钟数 . |
下面的图像显示了典型的Grafana日志查询的外观. 查询由 application 财务报告和审定财务报表 job 标签。 这个 sessionId 标签用于过滤特定调试会话的日志.

示例使用
设置 RemoteLogger 把它传给克里多 Agent 如下所示:
import { RemoteLogger, RemoteLoggerOptions } from '@hyperledger/aries-remote-logs'
// ...
const autoDisableRemoteLoggingIntervalInMinutes = 90 // important
const lokiUrl = 'https://logs.example.com:3100/loki/api/v1/push'
const logOptions: RemoteLoggerOptions = {
lokiUrl,
lokiLabels: {
application: 'bifold-wallet',
job: 'react-native-logs',
},
autoDisableRemoteLoggingIntervalInMinutes,
}
const logger = new RemoteLogger(logOptions)
logger.startEventListeners()
const credoConfigOpts = {
config: {
label: 'Bifold Wallet',
walletConfig: {
id: 'some-wallet-id',
key: 'some-secret-key',
},
logger,
mediatorPickupStrategy: MediatorPickupStrategy.Implicit,
autoUpdateStorageOnStartup: true,
autoAcceptConnections: true,
},
dependencies: agentDependencies,
modules: getAgentModules({
indyNetworks: ledgers,
mediatorInvitationUrl: Config.MEDIATOR_URL,
}),
}
const agent = new Agent(credoConfigOpts)
// ...
通过发送下列事件启用并禁用远程记录 :
import { DeviceEventEmitter } from 'react-native'
import { RemoteLoggerEventTypes } from '@hyperledger/aries-remote-logs'
// ...
// enable remote logging, this will send the logs to the remote server
// and will automatically disable remote logging after the specified
// interval.
DeviceEventEmitter.emit(RemoteLoggerEventTypes.ENABLE_REMOTE_LOGGING, true)
// ...
包括一揽子计划
地铁
地铁无法处理"同心通". 因此,您需要指定 @hyperledger/aries-remote-logs 位置位于 metro.config.js 申请文件。 检查下面的例子, 或者查看这个 完整实例 更多信息.
// ...
fs.realpathSync(path.join(__dirname, 'node_modules', '@hyperledger/aries-remote-logs')),
// ...
雅伦
亚伦挣扎要包括 react-native 本地文件系统对等依赖。 要修复, 请添加任何 react-native 此软件包的依赖性 peerDependencies 内 package.json 给自己的 package.json命令 yarn add react-native-logs@^5.0.1 这样做.
发展
这个包船带有一个可以用来运行当地Grafana Loki堆栈的多克编组文件. 要启动容器,运行以下命令:
docker compose up -d
Loki 服务器将在 http://localhost:3100。格拉法纳服务器将在 http://localhost:3000。Grafana 的默认用户名和密码是 admin 并指定密码,可以更改,在 docker-compose.yaml 文件 :
environment:
GF_SECURITY_ADMIN_PASSWORD: secret
一旦堆栈开始运行,您已经登录到Grafana,您可能需要从主登陆页上添加一个Loki数据源. 您需要设置的唯一值是 Loki 运行的 URL 。 根据堆放器,值是: http://loki:3100