AElf.OpenTelemetry 8.2.1

dotnet add package AElf.OpenTelemetry --version 8.2.1                
NuGet\Install-Package AElf.OpenTelemetry -Version 8.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AElf.OpenTelemetry" Version="8.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AElf.OpenTelemetry --version 8.2.1                
#r "nuget: AElf.OpenTelemetry, 8.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AElf.OpenTelemetry as a Cake Addin
#addin nuget:?package=AElf.OpenTelemetry&version=8.2.1

// Install AElf.OpenTelemetry as a Cake Tool
#tool nuget:?package=AElf.OpenTelemetry&version=8.2.1                

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:

  1. Orleans Observability
  2. AspNetCore Observability
  3. HttpClient Observability

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
8.2.1 454 10/26/2024
8.2.0 1,247 7/29/2024
8.0.6 274 10/26/2024
8.0.5 2,082 7/29/2024
1.0.1 114 7/18/2024
1.0.0 2,429 7/16/2024