Logging
Nitro includes Open Telemetry logging, allowing seamless log collection and analysis directly within the app. This documentation provides guidance on setting up and utilizing logging features in Nitro for enhanced monitoring, debugging, and performance analysis of your APIs.
API Logs#

Detailed Log Inspection#

Within the Logs tab, individual log entries can be expanded to reveal additional details such as timestamps, log levels, and message content.
Trace Logs#

Logs can also be inspected within individual traces, providing detailed insights into the correlation between specific traces and their corresponding logs.
Log Retention#
Log retention in Nitro is configured as follows:
- Shared Clusters: Logs are retained for 1 day to allow for recent log review.
- Dedicated Clusters: Dynamic log retention times can be configured to meet specific needs, offering flexibility in log management.
Connect your service#
All the logging is done on a per API basis. An api represents one of your deployments. To monitor you services you need to create an API in Nitro. The api needs to be from type "Api Service" or "Api Gateway".
To install the Nitro services, run the following commands in your project's root directory:
dotnet add package ChilliCream.Nitro
dotnet add package ChilliCream.Nitro.HotChocolate
dotnet add package ChilliCream.Nitro.OpenTelemetry
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.AspNetCoreAfter installing the package, you need to configure the services in your startup class. Below is a sample implementation in C#:
public void ConfigureServices(IServiceCollection services)
{
services
.AddNitro(x =>
{
x.ApiKey = "<<your-api-key>>";
x.ApiId = "QXBpCmc5NGYwZTIzNDZhZjQ0NjBmYTljNDNhZDA2ZmRkZDA2Ng==";
x.Stage = "dev";
})
.AddOpenTelemetry();
services
.AddGraphQL()
.AddQueryType<Query>()
.AddInstrumentation();
services
.AddLogging(x => x
.AddOpenTelemetry(options =>
{
options.IncludeFormattedMessage = true;
options.IncludeScopes = true;
}));
}Using Environment Variables
Alternatively, you can set the required values using environment variables. This method allows you to call AddNitro without explicitly passing parameters.
NITRO_API_KEYmaps toApiKeyNITRO_API_IDmaps toApiIdNITRO_STAGEmaps toStage
public void ConfigureServices(IServiceCollection services)
{
services
.AddNitro()
.AddOpenTelemetry();
services
.AddGraphQL()
.AddQueryType<Query>()
.AddInstrumentation(); // Enable the graphql telemetry
services
.AddLogging(x => x
.AddOpenTelemetry(options =>
{
options.IncludeFormattedMessage = true;
options.IncludeScopes = true;
}));
}In this setup, the API key, ID, and stage are set through environment variables.
Full Example#
For a complete implementation example, visit the example repository.
Edit this page on GitHub