Treblle with .NET Core
Requirements
- .NET: 6.0+
- ASP.NET Core: 6.0+
- C#: 10.0+
Supported Platforms:
- Windows, macOS, Linux
- Docker containers
- Azure, AWS, Google Cloud
- Any hosting platform supporting .NET 8+
Supported API Types:
- REST APIs with Controllers
- Minimal APIs
- Web APIs
- Mixed controller/minimal API applications
Installation
You can install Treblle .NET Core via NuGet . Simply run the following command:
dotnet add package Treblle.Net.CoreGet Your Credentials
Get your SDK Token and API Key from the Treblle Dashboard .
Configuration
Treblle v2.0 now supports automatic endpoint discovery, so you no more need to manually add `[Treblle]` attributes.
Choose from these configuration options:
Option A: Environment Variables (Recommended for Production)
export TREBLLE_SDK_TOKEN=your_sdk_token
export TREBLLE_API_KEY=your_api_keyThen use zero-configuration setup:
using Treblle.Net.Core;
// Register Treblle Services
builder.Services.AddTreblle();
// Build your application
var app = builder.Build();
// Enable the Treblle Middleware
app.UseTreblle();Note
Where to place this code:
- Program.cs (new minimal hosting model): Add `builder.Services.AddTreblle()` before `builder.Build()` and `app.UseTreblle()` after `var app = builder.Build()`
- Startup.cs (legacy): Add `services.AddTreblle()` in `ConfigureServices()` and `app.UseTreblle()` in `Configure()`
- Web API templates: Place after authentication/authorization middleware but before routing
Using .env Files with DotNetEnv
For development environments, you can use `.env` files:
dotnet add package DotNetEnvCreate a `.env` file in your project root:
TREBLLE_SDK_TOKEN=your_sdk_token
TREBLLE_API_KEY=your_api_keyThen load the environment variables:
using Treblle.Net.Core;
using DotNetEnv;
// Load environment variables from .env file
Env.Load();
// Register Treblle Services
builder.Services.AddTreblle();
var app = builder.Build();
app.UseTreblle();Option B: appsettings.json
{
"Treblle": {
"SdkToken": "your_sdk_token",
"ApiKey": "your_api_key"
}
}using Treblle.Net.Core;
builder.Services.AddTreblle();
var app = builder.Build();
app.UseTreblle();Option C: Manual Configuration
using Treblle.Net.Core;
builder.Services.AddTreblle("your_sdk_token", "your_api_key");
var app = builder.Build();
app.UseTreblle();That’s it! Treblle will now automatically track all your API endpoints.
Advanced Configuration
Option
Default and Description
ExcludedPaths
null - Exclude specific paths or endpoints from Treblle
DebugMode
false - Enable detailed logging for troubleshooting
DisableMasking
false - Disable data masking if not needed
Example with all options:
using Treblle.Net.Core;
builder.Services.AddTreblle(options =>
{
options.ExcludedPaths = new[] { "/health", "/admin/*", "/swagger/*" };
options.DebugMode = true;
options.DisableMasking = false;
});
var app = builder.Build();
app.UseTreblle();Tip
If you have problems of any kind, feel free to reach out via email support@treblle.com and we’ll do our best to help you out.