在现有的数据 API 生成器配置文件中添加或更新 OpenTelemetry 和 Azure Application Insights 设置。
runtime.telemetry如果该节不存在,则会创建它。 未指定的选项使现有值保持不变。
注释
遥测设置不可配置 dab configure。 用于 dab add-telemetry 所有 runtime.telemetry 更改。
有关概念指南和端到端演练,请参阅使用 OpenTelemetry 和活动跟踪和使用 Azure Application Insights。
Syntax
dab add-telemetry [options]
快速浏览
| 选项 | 总结 |
|---|---|
-c, --config |
配置文件路径。 默认 dab-config.json。 |
OpenTelemetry 部分
| 选项 | 总结 |
|---|---|
--otel-enabled |
启用或禁用 OpenTelemetry。 |
--otel-endpoint |
OpenTelemetry 收集器终结点 URL。 |
--otel-protocol |
导出协议。 允许的值:grpc、httpprotobuf。 |
--otel-service-name |
所有遥测的服务名称标记。 |
--otel-headers |
要发送到 OpenTelemetry 收集器的额外标头。 |
Azure Application Insights 部分
| 选项 | 总结 |
|---|---|
--app-insights-enabled |
启用或禁用 Azure Application Insights。 |
--app-insights-conn-string |
Application Insights 连接字符串。 |
-c, --config
配置文件的路径。 默认值为 dab-config.json 除非 dab-config.<DAB_ENVIRONMENT>.json 存在,否则为 DAB_ENVIRONMENT 环境变量。
示例
--otel-enabled
启用或禁用 OpenTelemetry 导出程序。 接受的值:true、false。
示例
生成的配置
{
"runtime": {
"telemetry": {
"open-telemetry": {
"enabled": true
}
}
}
}
--otel-endpoint
OpenTelemetry 收集器或后端的 URL。 对于 gRPC,请使用 http://<host>:<port>。 对于 HTTP,包括完整路径,例如 http://<host>:<port>/v1/traces。
示例
生成的配置
{
"runtime": {
"telemetry": {
"open-telemetry": {
"enabled": true,
"endpoint": "http://localhost:4317"
}
}
}
}
--otel-protocol
OpenTelemetry 导出程序导出协议。 允许的值:grpc、httpprotobuf。 默认为 grpc。
示例
dab add-telemetry \
--otel-enabled true \
--otel-endpoint "http://localhost:4318" \
--otel-protocol "httpprotobuf"
生成的配置
{
"runtime": {
"telemetry": {
"open-telemetry": {
"enabled": true,
"endpoint": "http://localhost:4318",
"exporter-protocol": "httpprotobuf"
}
}
}
}
--otel-service-name
附加到所有跟踪和指标的服务名称标记。 在遥测后端中显示为服务标识符。 默认为 dab。
示例
生成的配置
{
"runtime": {
"telemetry": {
"open-telemetry": {
"enabled": true,
"service-name": "my-dab-api"
}
}
}
}
--otel-headers
将遥测数据导出到收集器时要包含的额外 HTTP 标头。 使用逗号分隔 key=value 的列表。 对需要 API 密钥或授权标头的经过身份验证的收集器终结点使用此选项。
示例
dab add-telemetry \
--otel-enabled true \
--otel-endpoint "https://collector.example.com:4317" \
--otel-headers "api-key=my-secret-key"
--app-insights-enabled
启用或禁用 Azure Application Insights 遥测。 接受的值:true、false。
示例
生成的配置
{
"runtime": {
"telemetry": {
"application-insights": {
"enabled": true
}
}
}
}
--app-insights-conn-string
Azure Application Insights 资源的连接字符串。 使用环境变量引用以避免将机密提交到源代码管理。
警告
切勿直接在配置文件中对连接字符串进行硬编码。 使用 @env('<variable-name>') 或机密管理器。
示例
dab add-telemetry \
--app-insights-enabled true \
--app-insights-conn-string "@env('APP_INSIGHTS_CONN_STRING')"
生成的配置
{
"runtime": {
"telemetry": {
"application-insights": {
"enabled": true,
"connection-string": "@env('APP_INSIGHTS_CONN_STRING')"
}
}
}
}
完整示例:OpenTelemetry 和 Application Insights
以下示例在单个命令中同时启用 OpenTelemetry 和 Application Insights。
dab add-telemetry \
--otel-enabled true \
--otel-endpoint "http://localhost:4317" \
--otel-protocol "grpc" \
--otel-service-name "my-dab-api" \
--app-insights-enabled true \
--app-insights-conn-string "@env('APP_INSIGHTS_CONN_STRING')"
生成的配置
{
"runtime": {
"telemetry": {
"open-telemetry": {
"enabled": true,
"endpoint": "http://localhost:4317",
"service-name": "my-dab-api",
"exporter-protocol": "grpc"
},
"application-insights": {
"enabled": true,
"connection-string": "@env('APP_INSIGHTS_CONN_STRING')"
}
}
}
}