After two days of experimentation, I finally succeeded based on version 7.15.1 (opentelemetry otlp forwarded to apm server), and data can be written to Elasticsearch.
But I tested the 7.12.0 version again. According to the above document, I deployed the opentelemetry collector, and the data was also sent to the apm server, but the service was not found on kibana. I checked the log of the apm server and it received The message that the collector forwarded to it, but it was not stored in Elasticsearch.
Generally speaking, things have made some progress, and I am probably familiar with the series relationship between opentelemetry and elastic.
vim /etc/otel-contrib-collector/config.yaml
receivers:
otlp:
protocols:
grpc:
exporters:
logging:
logLevel: debug
elastic:
apm_server_url: http://192.168.51.134:8200
processors:
batch:
service:
pipelines:
traces:
receivers: [otlp]
exporters: [elastic, logging]
processors: [batch]
AspNetCore/appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Debug",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"UseExporter": "Otlp",
"UseLogging": true,
"Otlp": {
"ServiceName": "otlp-test-aspnet-core",
},
"AspNetCoreInstrumentation": {
"RecordException": "true"
}
}
The following is the log of apm server, I can already see the information from curl.
localtesting_7.12.0_apm-server | {"log.level":"info","@timestamp":"2021-12-04T07:55:55.611Z","log.logger":"request","log.origin":{"file.name":"middleware/log_middleware.go","file.line":63},"message":"request ok","url.original":"/","http.request.method":"GET","user_agent.original":"curl/7.64.0","source.address":"127.0.0.1","http.request.body.bytes":0,"http.request.id":"65591513-69f7-45d7-9df4-72877ec7b4f6","event.duration":97654,"http.response.status_code":200,"ecs.version":"1.6.0"}
localtesting_7.12.0_apm-server | {"log.level":"info","@timestamp":"2021-12-04T07:56:05.682Z","log.logger":"request","log.origin":{"file.name":"middleware/log_middleware.go","file.line":63},"message":"request ok","url.original":"/","http.request.method":"GET","user_agent.original":"curl/7.64.0","source.address":"127.0.0.1","http.request.body.bytes":0,"http.request.id":"21136b88-c176-4f52-832b-12e12cccc5b4","event.duration":119043,"http.response.status_code":200,"ecs.version":"1.6.0"}
localtesting_7.12.0_apm-server | {"log.level":"info","@timestamp":"2021-12-04T07:56:11.383Z","log.logger":"request","log.origin":{"file.name":"middleware/log_middleware.go","file.line":63},"message":"request accepted","url.original":"/intake/v2/events","http.request.method":"POST","user_agent.original":"elasticapm-go/1.11.0 go/go1.15.8","source.address":"pipe","http.request.id":"97ee33d8-8d16-4a31-93d5-032fd3ae4088","event.duration":10000515512,"http.response.status_code":202,"ecs.version":"1.6.0"}
localtesting_7.12.0_apm-server | {"log.level":"info","@timestamp":"2021-12-04T07:56:15.758Z","log.logger":"request","log.origin":{"file.name":"middleware/log_middleware.go","file.line":63},"message":"request ok","url.original":"/","http.request.method":"GET","user_agent.original":"curl/7.64.0","source.address":"127.0.0.1","http.request.body.bytes":0,"http.request.id":"7c8b6dbb-02c2-44c4-acbf-bf42c9c4f137","event.duration":118150,"http.response.status_code":200,"ecs.version":"1.6.0"}
localtesting_7.12.0_apm-server | {"log.level":"info","@timestamp":"2021-12-04T07:56:25.865Z","log.logger":"request","log.origin":{"file.name":"middleware/log_middleware.go","file.line":63},"message":"request ok","url.original":"/","http.request.method":"GET","user_agent.original":"curl/7.64.0","source.address":"127.0.0.1","http.request.body.bytes":0,"http.request.id":"b0e4b851-2cca-44a1-942d-27c52d64a63e","event.duration":112893,"http.response.status_code":200,"ecs.version":"1.6.0"}