
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
elando.ELK.TraceLogging
Advanced tools
Trace logging in to microservices with custom Http Header
This package provides an easy configuration to trace HTTP requests using Serilog. Please follow the steps below to set it up.
In order to use this package, you need to configure Serilog to work with Elasticsearch. You can do this by calling AddElasticLogging()
in SerilogConfigurationExtensions.cs
. Additionally, make sure to provide the following configuration parameters:
elasticUri
indexPrefix
minLoggingLevel
UseDirect Host Configuration about Serilog (with Elastic). You can do this by calling builder.Host.AddLogger()
in HostExtension.cs
. Additionally, make sure to provide the following configuration parameters:
builder.Configuration
LogEventLevel logLevel = LogEventLevel.Information
{
"TraceIdKey": "Your-Custom_Key-Name",
"ElasticUri": "your.elastic.uri/",
"LoggerPrefix": "Your-Custom_Prefix",
"GlobalLogingFilter": "Your-Custom_Loging-Filter" // Optional
}
Each middleware in this package requires access to the HTTP context. To provide access, add the HttpContextAccessor
to your DI container using:
builder.Services.AddHttpContextAccessor();
Configure HTTP request/response logging using the following code:
builder.Services.AddHttpLogging(logging =>
{
logging.RequestHeaders.Add(builder.Configuration.GetHeaderName());
});
Not needed for application inside the kube8. Add the TraceIdentifierMiddleware as the first middleware in your application to include a new trace header with a unique GUID:
app.UseMiddleware<HttpTraceMiddleware>();
Use UseHttpLogging() as the second middleware in your application to log the HTTP requests and responses:
app.UseHttpLogging();
Not needed for application inside the kube8. If you need to trace:
Add the TraceIdentifierInterceptor to your services:
services.AddSingleton<HttpTraceInterceptor>();
Configure each gRPC client with the TraceIdentifierInterceptor:
services.AddGrpcClient<gRPCClient>(options => ...)
.AddInterceptor<HttpTraceInterceptor>();
Note that HTTP requests are not implemented yet and require further development.
Use LoggerTraceExtensions based on 'Microsoft.Extensions.Logging.ILogger'.
var traceId = this.HttpContext.GetTraceId();
_logger.LogModelWithDepthOne(request, traceId);
The traceId argument enables tracing of the log in an application & across microservice architecture.
var traceId = this.HttpContext.GetTraceId();
_logger.LogModelWithDepthOne(model, traceId, nameof(model.Phone));
var traceId = this.HttpContext.GetTraceId();
// New code
IEnumerable<TypeModel> copy = model.DeepCopy();
copy.RedactSensitiveData(nameof(TypeModel.Address), nameof(TypeModel.Phone));
_logger.LogModelWithDepthOne(copy, traceId);
FAQs
Trace logging in to microservices with custom Http Header
We found that elando.elk.tracelogging demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.