AElf.OpenTelemetry
8.0.5
See the version list below for details.
dotnet add package AElf.OpenTelemetry --version 8.0.5
NuGet\Install-Package AElf.OpenTelemetry -Version 8.0.5
<PackageReference Include="AElf.OpenTelemetry" Version="8.0.5" />
paket add AElf.OpenTelemetry --version 8.0.5
#r "nuget: AElf.OpenTelemetry, 8.0.5"
// Install AElf.OpenTelemetry as a Cake Addin #addin nuget:?package=AElf.OpenTelemetry&version=8.0.5 // Install AElf.OpenTelemetry as a Cake Tool #tool nuget:?package=AElf.OpenTelemetry&version=8.0.5
AElf OpenTelemetry
An OpenTelemetry module for use in ABP and Orleans framework.
About The Project
This project is a module for ABP and Orleans framework to use OpenTelemetry. It provides a simple and fast way to integrate OpenTelemetry in ABP and Orleans framework.
The module will provide instrumentation for both ASP and Orleans out of the box:
Getting Started
Installation
Run the following command in your project to install this module:
dotnet add package AElf.OpenTelemetry
Configuration
To configure your opentelemetry service name, version and collector's endpoint, you need to add the following to your appsettings.json file:
{
"OpenTelemetry": {
"ServiceName": "YourServiceName",
"ServiceVersion": "YourServiceVersion",
"CollectorEndpoint": "http://localhost:4315"
}
}
Setup
Add the following dependency to your project's Module class:
using AElf.OpenTelemetry;
[DependsOn(
typeof(OpenTelemetryModule)
)]
public class MyTemplateModule : AbpModule
This will automatically register the OpenTelemetry module and setup your project for instrumentation.
Orleans
For Orleans, you need to add the following to your SiloBuilder:
hostBuilder.UseOrleans((context, siloBuilder) =>
{
siloBuilder.AddActivityPropagation();
});
Do the same for the Clientbuilder:
hostBuilder.UseOrleansClient((context, clientBuilder) =>
{
clientBuilder.AddActivityPropagation();
});
This will automatically propagate the respective activities of the Orleans grain calls.
Examples
Here are some examples of how to use this module.
AggregateExecutionTime
AggregateExecutionTime is an attribute that can be used to measure the execution time of a class's method. It can be used in both ABP and Orleans framework, either on the class or method level.
Class level:
using AElf.OpenTelemetry.ExecutionTime;
[AggregateExecutionTime]
public class MessageValidatorGrain : Grain
Method level:
[AggregateExecutionTime]
public Task<bool> IsOffensive(string message)
The attribute can also be used in ABP's services or controllers.
[AggregateExecutionTime]
public class AuthorAppService : ApplicationService
This will automatically measure the execution time of the method of the class and send the data to the OpenTelemetry collector.
Do note that for Controllers and Application Services in ABP, please make sure that the method you would like metrics for is a virtual method for the attribute to work.
Instrumentation
For custom instrumentation, you can use the IInstrumentationProvider
interface to create custom spans and metrics. Get the instrumentation provider from the DI container and use it to create spans and metrics.
public class MessageValidatorGrain : Grain, IMessageValidator
{
private readonly ILogger _logger;
private readonly ActivitySource _activitySource;
private static readonly string[] OffensiveWords = new string[] {"offensive", "bad", "rude"};
public MessageValidatorGrain(ILogger<MessageValidatorGrain> logger, IInstrumentationProvider instrumentationProvider)
{
_logger = logger;
_activitySource = instrumentationProvider.ActivitySource;
}
public Task<bool> IsOffensive(string message)
{
// This will start a custom trace for the IsOffensive method
using var myActivity = _activitySource.StartActivity($"{nameof(MessageValidatorGrain)}.IsOffensive");
_logger.LogInformation("""
IsOffensive message received: message = "{Message}"
""",
message);
return Task.FromResult(OffensiveWords.Any(message.Contains));
}
}
Contributing
If you encounter a bug or have a feature request, please use the Issue Tracker. The project is also open to contributions, so feel free to fork the project and open pull requests.
License
Distributed under the MIT License. See License for more information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Orleans.Core.Abstractions (>= 7.2.6)
- OpenTelemetry.AutoInstrumentation (>= 1.7.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.9.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.9.0)
- OpenTelemetry.Instrumentation.Http (>= 1.9.0)
- Volo.Abp.Core (>= 8.0.5)
-
net8.0
- Microsoft.Orleans.Core.Abstractions (>= 7.2.6)
- OpenTelemetry.AutoInstrumentation (>= 1.7.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.9.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.9.0)
- OpenTelemetry.Instrumentation.Http (>= 1.9.0)
- Volo.Abp.Core (>= 8.0.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AElf.OpenTelemetry:
Package | Downloads |
---|---|
AeFinder.Grains
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.