Hi,
Thanks to @GregKalapos I finally managed to listen to Http ougoing calls in an Asp .net core Background service and report them in APM.
But now I still have a point :
where can I found my correlated logs (with Serilog) in APM Kibana UI ?
Here is my appsettings.json
"Serilog": {
"Using": [],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Information",
"Elastic": "Verbose"
}
},
"WriteTo": [
{
"Name": "Console"
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithProcessId",
"WithThreadId"
],
"Properties": {
"ApplicationName": "myMicroservice"
}
},
"ElasticApm": {
"ServerUrls": "http://apm:8200"
}
My Serilog logger instance creator
return new LoggerConfiguration()
.ReadFrom.Configuration(config)
.Enrich.WithElasticApmCorrelationInfo()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://elasticsearch:9200/"))
{
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
EmitEventFailureHandling.WriteToFailureSink |
EmitEventFailureHandling.RaiseCallback,
CustomFormatter = new EcsTextFormatter()
})
.WriteTo.OpenTracing()
.CreateLogger();
I'm using the nuget packages
Elastic.Apm.NetCoreAll v1.6.1
Elastic.Apm.SerilogEnricher v1.5.1
Elastic.CommonSchema.Serilog v1.5.1
My docker-compose.yml file
version: '3.4'
services:
myMicroservice:
image: ${DOCKER_REGISTRY-}myMicroservice
container_name: myMicroservice
build:
context: .
dockerfile: src/myMicroservice/src/Dockerfile
depends_on:
- elasticsearch
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
container_name: elasticsearch
environment:
- discovery.type=single-node
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms4g -Xmx4g"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
volumes:
- ./volumes/elasticsearch:/usr/share/elasticsearch/data
apm:
image: docker.elastic.co/apm/apm-server:7.9.2
container_name: apm
command: >
apm-server -e
-E apm-server.rum.enabled=true
-E setup.kibana.host=kibana:5601
-E setup.template.settings.index.number_of_replicas=0
-E apm-server.kibana.enabled=true
-E apm-server.kibana.host=kibana:5601
-E output.elasticsearch.hosts=["elasticsearch:9200"]
ports:
- "8200:8200"
expose:
- "8200"
links:
- elasticsearch
depends_on:
- elasticsearch
- kibana
kibana:
image: docker.elastic.co/kibana/kibana:7.9.2
container_name: kibana
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
ports:
- "5601:5601"
depends_on:
- elasticsearch
My async Task called in a Background service ExecuteAsync method
public async Task Test()
{
await Agent.Tracer
.CaptureTransaction("TransactionTest", ApiConstants.TypeRequest, async (t) =>
{
_logger.LogInformation($"First Test log");
await t.CaptureSpan("GetTestSpan1", "ElasticSearch", async span =>
{
_logger.LogInformation($"Test log 1");
_logger.LogWarning($"Test log 1");
_logger.LogError($"Test log 1");
_logger.LogCritical($"Test log 1");
await Task.FromResult(true);
});
await t.CaptureSpan("GetTestSpan2", "ElasticSearch", async span =>
{
_logger.LogInformation($"Test log 2");
_logger.LogWarning($"Test log 2");
_logger.LogError($"Test log 2");
_logger.LogCritical($"Test log 2");
await Task.FromResult(true);
});
await t.CaptureSpan("GetTestSpan3", "ElasticSearch", async span =>
{
_logger.LogInformation($"Test log 3");
_logger.LogWarning($"Test log 3");
_logger.LogError($"Test log 3");
_logger.LogCritical($"Test log 3");
await Task.FromResult(true);
});
});
}
And finally the output in APM
But where ever I click I'm not able to see any of my logs, where am I supposed to see them ? I guessed on clicking on the span within a transaction I could see them, could someone help on that ?
And finally the full Microservice + APM logs in verbose mode
APM missing correlated logs