### Installing AElf OpenTelemetry Module - Shell Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This command adds the AElf.OpenTelemetry NuGet package to your project. It is the first step in integrating the OpenTelemetry module into your .NET application. ```sh dotnet add package AElf.OpenTelemetry ``` -------------------------------- ### Creating Custom OpenTelemetry Span with ActivitySource - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code demonstrates how to create a custom trace span using `System.Diagnostics.ActivitySource`, obtained via `IInstrumentationProvider`. It shows how to start a new activity (`myActivity`) for a specific operation (`IsOffensive`) within a grain method, allowing for detailed tracing of custom code paths. ```csharp 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 logger, IInstrumentationProvider instrumentationProvider) { _logger = logger; _activitySource = instrumentationProvider.ActivitySource; } public Task 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)); } } ``` -------------------------------- ### Configuring Orleans ClientBuilder for Activity Propagation - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code snippet shows how to configure the Orleans ClientBuilder to enable activity propagation. This ensures that tracing contexts are correctly passed from the client initiating a grain call into the Orleans cluster. ```csharp hostBuilder.UseOrleansClient((context, clientBuilder) => { clientBuilder.AddActivityPropagation(); }); ``` -------------------------------- ### Registering OpenTelemetry Module in ABP - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code demonstrates how to add the OpenTelemetry module as a dependency in your main ABP module class using the `[DependsOn]` attribute. This registers the module and enables automatic instrumentation. ```csharp using AElf.OpenTelemetry; [DependsOn( typeof(OpenTelemetryModule) )] public class MyTemplateModule : AbpModule ``` -------------------------------- ### Configuring OpenTelemetry Service Details - JSON Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This JSON snippet shows the configuration structure for the OpenTelemetry module in an appsettings.json file. It allows you to define the service name, version, and the endpoint for the OpenTelemetry collector. ```json { "OpenTelemetry": { "ServiceName": "YourServiceName", "ServiceVersion": "YourServiceVersion", "CollectorEndpoint": "http://localhost:4315" } } ``` -------------------------------- ### Configuring Orleans SiloBuilder for Activity Propagation - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code snippet shows how to configure the Orleans SiloBuilder to enable activity propagation. This ensures that tracing contexts are correctly passed between different grains and services within the Orleans silo. ```csharp hostBuilder.UseOrleans((context, siloBuilder) => { siloBuilder.AddActivityPropagation(); }); ``` -------------------------------- ### Applying AggregateExecutionTime Attribute to ABP Class - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code shows how to use the `[AggregateExecutionTime]` attribute on an ABP application service or controller class. It will measure the execution time of virtual methods within the class, requiring methods to be virtual for the attribute to function correctly in this context. ```csharp [AggregateExecutionTime] public class AuthorAppService : ApplicationService ``` -------------------------------- ### Applying AggregateExecutionTime Attribute to Method - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code demonstrates applying the `[AggregateExecutionTime]` attribute at the method level. When applied to a specific method, it measures only the execution time of that particular method and reports it as a metric. ```csharp [AggregateExecutionTime] public Task IsOffensive(string message) ``` -------------------------------- ### Applying AggregateExecutionTime Attribute to Class - C# Source: https://github.com/aelfproject/aelf.opentelemetry/blob/master/README.md This C# code demonstrates applying the `[AggregateExecutionTime]` attribute at the class level. When applied to a class, the attribute measures the execution time of all public methods within that class and reports it as a metric. ```csharp using AElf.OpenTelemetry.ExecutionTime; [AggregateExecutionTime] public class MessageValidatorGrain : Grain ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.