otelcol.connector.spanlogs
otelcol.connector.spanlogs
接收来自其他 otelcol
组件的链路追踪遥测数据,并为每个 span、root 或 process 输出日志遥测数据。这使您能够自动构建链路追踪发现机制。
注意
otelcol.connector.spanlogs
是一个自定义组件,与 OpenTelemetry Collector 中的任何组件无关。它基于 Grafana Agent Static 的 traces 子系统中的automatic_logging
组件。
您可以通过为 otelcol.connector.spanlogs
组件指定不同的标签来定义多个此类组件。
用法
otelcol.connector.spanlogs "LABEL" {
output {
logs = [...]
}
}
参数
otelcol.connector.spanlogs
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
spans | bool | 为每个 span 记录一行日志。 | false | 否 |
roots | bool | 为链路追踪中的每个根 span 记录一行日志。 | false | 否 |
processes | bool | 为每个 process 记录一行日志。 | false | 否 |
events | bool | 为每个 span 事件记录一行日志。 | false | 否 |
span_attributes | list(string) | 需要记录的额外 span 属性。 | [] | 否 |
process_attributes | list(string) | 需要记录的额外 process 属性。 | [] | 否 |
event_attributes | list(string) | 需要记录的额外事件属性。 | [] | 否 |
labels | list(string) | 将被记录为标签的键列表。 | [] | 否 |
labels
中列出的值应为 span、process 或事件属性的值。
警告
将
spans
或events
设置为true
可能会导致日志量过大。
块
在 otelcol.connector.spanlogs
定义中支持以下块
层级 | 块 | 描述 | 必需 |
---|---|---|---|
overrides | overrides | 日志主体中键的覆盖配置。 | 否 |
output | output | 配置将接收到的遥测数据发送到何处。 | 是 |
overrides 块
overrides
块配置将记录在日志行主体中的键的覆盖。
支持以下属性
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
logs_instance_tag | string | 指示日志行是针对 span、root 还是 process。 | traces | 否 |
service_key | string | 资源的 service name 的日志键。 | svc | 否 |
span_name_key | string | span 名称的日志键。 | span | 否 |
status_key | string | span 状态的日志键。 | status | 否 |
duration_key | string | span 持续时间的日志键。 | dur | 否 |
trace_id_key | string | Span 的 Trace ID 的日志键。 | tid | 否 |
输出块
output
块配置一组组件,用于转发生成的遥测数据。
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
logs | list(otelcol.Consumer) | 要将日志发送到的消费者列表。 | [] | 否 |
您必须指定 output
块,但其所有参数都是可选的。默认情况下,遥测数据会被丢弃。相应地配置 logs
参数以将遥测数据发送到其他组件。
导出的字段
以下字段已导出,可供其他组件引用
名称 | 类型 | 描述 |
---|---|---|
input | otelcol.Consumer | 其他组件可用于发送遥测数据的值。 |
input
接受任何遥测信号(指标、日志或 traces)的 otelcol.Consumer
数据。
组件健康状况
仅当配置无效时,otelcol.connector.spanlogs
才会报告为不健康。
调试信息
otelcol.connector.spanlogs
不暴露任何组件特定的调试信息。
示例
以下配置将从 span 生成的日志发送到 Loki。
此外,otelcol.processor.attributes
配置了一个“提示”,以便 otelcol.exporter.loki
将 span 的“attribute1”属性提升为 Loki 标签。
otelcol.receiver.otlp "default" {
grpc {}
output {
traces = [otelcol.connector.spanlogs.default.input]
}
}
otelcol.connector.spanlogs "default" {
spans = true
roots = true
processes = true
events = true
labels = ["attribute1", "res_attribute1"]
span_attributes = ["attribute1"]
process_attributes = ["res_attribute1"]
event_attributes = ["log.severity", "log.message"]
output {
logs = [otelcol.processor.attributes.default.input]
}
}
otelcol.processor.attributes "default" {
action {
key = "loki.attribute.labels"
action = "insert"
value = "attribute1"
}
output {
logs = [otelcol.exporter.loki.default.input]
}
}
otelcol.exporter.loki "default" {
forward_to = [loki.write.local.receiver]
}
loki.write "local" {
endpoint {
url = "loki:3100"
}
}
对于这样的输入跟踪…
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": { "stringValue": "TestSvcName" }
},
{
"key": "res_attribute1",
"value": { "intValue": "78" }
},
{
"key": "unused_res_attribute1",
"value": { "stringValue": "str" }
},
{
"key": "res_account_id",
"value": { "intValue": "2245" }
}
]
},
"scopeSpans": [
{
"spans": [
{
"trace_id": "7bba9f33312b3dbb8b2c2c62bb7abe2d",
"span_id": "086e83747d0e381e",
"name": "TestSpan",
"attributes": [
{
"key": "attribute1",
"value": { "intValue": "78" }
},
{
"key": "unused_attribute1",
"value": { "intValue": "78" }
},
{
"key": "account_id",
"value": { "intValue": "2245" }
}
],
"events": [
{
"name": "log",
"attributes": [
{
"key": "log.severity",
"value": { "stringValue": "INFO" }
},
{
"key": "log.message",
"value": { "stringValue": "TestLogMessage" }
}
]
}
]
}
]
}
]
}
]
}
… 从 otelcol.connector.spanlogs
输出的日志将如下所示
{
"resourceLogs": [
{
"scopeLogs": [
{
"log_records": [
{
"body": {
"stringValue": "span=TestSpan dur=0ns attribute1=78 svc=TestSvcName res_attribute1=78 tid=7bba9f33312b3dbb8b2c2c62bb7abe2d"
},
"attributes": [
{
"key": "traces",
"value": { "stringValue": "span" }
},
{
"key": "attribute1",
"value": { "intValue": "78" }
},
{
"key": "res_attribute1",
"value": { "intValue": "78" }
}
]
},
{
"body": {
"stringValue": "span=TestSpan dur=0ns attribute1=78 svc=TestSvcName res_attribute1=78 tid=7bba9f33312b3dbb8b2c2c62bb7abe2d"
},
"attributes": [
{
"key": "traces",
"value": { "stringValue": "root" }
},
{
"key": "attribute1",
"value": { "intValue": "78" }
},
{
"key": "res_attribute1",
"value": { "intValue": "78" }
}
]
},
{
"body": {
"stringValue": "svc=TestSvcName res_attribute1=78 tid=7bba9f33312b3dbb8b2c2c62bb7abe2d"
},
"attributes": [
{
"key": "traces",
"value": { "stringValue": "process" }
},
{
"key": "res_attribute1",
"value": { "intValue": "78" }
}
]
},
{
"body": { "stringValue": "span=TestSpan dur=0ns attribute1=78 svc=TestSvcName res_attribute1=78 tid=7bba9f33312b3dbb8b2c2c62bb7abe2d log.severity=INFO log.message=TestLogMessage" },
"attributes": [
{
"key": "traces",
"value": { "stringValue": "event" }
},
{
"key": "attribute1",
"value": { "intValue": "78" }
},
{
"key": "res_attribute1",
"value": { "intValue": "78" }
},
{
"key": "log.severity",
"value": { "stringValue": "INFO" }
},
{
"key": "log.message",
"value": { "stringValue": "TestLogMessage" }
}
]
}
]
}
]
}
]
}
兼容组件
otelcol.connector.spanlogs
可以接受来自以下组件的参数
otelcol.connector.spanlogs
有可供以下组件消费的导出
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能使连接正常工作。有关更多详细信息,请参阅链接的文档。