从 OTEL 收集器发送日志
如果您已经有了自己的 OpenTelemetry Collector 并希望将日志导出到 Quickwit,您需要在 config.yaml
中配置一个新的 OLTP gRPC exporter:
- macOS/Windows
- Linux
otel-collector-config.yaml
receivers:
otlp:
protocols:
grpc:
http:
processors:
batch:
exporters:
otlp/quickwit:
endpoint: host.docker.internal:7281
tls:
insecure: true
# By default, logs are sent to the otel-logs-v0_7.
# You can customize the index ID By setting this header.
# headers:
# qw-otel-logs-index: otel-logs-v0_7
service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [otlp/quickwit]
otel-collector-config.yaml
receivers:
otlp:
protocols:
grpc:
http:
processors:
batch:
exporters:
otlp/quickwit:
endpoint: 127.0.0.1:7281
tls:
insecure: true
# By default, logs are sent to the otel-logs-v0_7.
# You can customize the index ID By setting this header.
# headers:
# qw-otel-logs-index: otel-logs-v0_7
service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [otlp/quickwit]
测试您的 OTEL 配置
- 安装 并启动一个 Quickwit server:
./quickwit run
- 使用之前的配置启动一个 collector:
- macOS/Windows
- Linux
docker run -v ${PWD}/otel-collector-config.yaml:/etc/otelcol/config.yaml -p 4317:4317 -p 4318:4318 -p 7281:7281 otel/opentelemetry-collector
docker run -v ${PWD}/otel-collector-config.yaml:/etc/otelcol/config.yaml --network=host -p 4317:4317 -p 4318:4318 -p 7281:7281 otel/opentelemetry-collector
- 使用 cURL 向您的 collector 发送一条日志:
curl -XPOST "http://localhost:4318/v1/logs" -H "Content-Type: application/json" \
--data-binary @- << EOF
{
"resource_logs": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "test-with-curl"
}
}
]
},
"scope_logs": [
{
"scope": {
"name": "manual-test"
},
"log_records": [
{
"time_unix_nano": "1678974011000000000",
"observed_time_unix_nano": "1678974011000000000",
"name": "test",
"severity_text": "INFO"
}
]
}
]
}
]
}
EOF
您应该会在 Quickwit 服务器上看到类似以下的日志:
2023-03-16T13:44:09.369Z INFO quickwit_indexing::actors::indexer: new-split split_id="01GVNAKT5TQW0T2QGA245XCMTJ" partition_id=6444214793425557444
这意味着 Quickwit 已经收到了日志并创建了一个新的分片。在搜索日志之前,请等待分片被发布。