alfkonee / elastic-apm-extensions

Multiple .NET libraries instrumentations for Elastic APM Agent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Elastic APM extensions for multiple .NET libraries.

Features

MassTransit

Extension MassTransit
Version 1 Version 7

Usage

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        })
        .UseElasticApm(
            // Add additional diagnostic subscribers e.g. AspNetCore, Http, etc
            new MassTransitDiagnosticsSubscriber());

The following events from the MassTransit DiagnosticSource are instrumented:

  • Transport.Send
  • Transport.Receive

Options

By default the Elastic APM send/receive label will be as follow:

This can be changed when creating the MassTransitDiagnosticsSubscriber by providing a different label.

new MassTransitDiagnosticsSubscriber(o => 
  o.ReceiveLabel = context => context.Host.AbsolutePath)

or if you return null, the default label will be used.

new MassTransitDiagnosticsSubscriber(o => 
  o.ReceiveLabel = context => 
    if (context is RabbitMqReceiveContext rabbitMqContext)
      ? rabbitMqContext.Exchange
      : default;)

The same can be used also for SendLabel

HotChocolate

Extension HotChocolate
Version 1 Version 11
Version 2 Version 12

Usage

HotChocolate by default is not emitting diagnostic events, but has the infrastructure to instrument each request.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add your services

        // Add HotChocolate GraphQL Server
        services
            .AddGraphQLServer()
            .AddQueryType<Query>()
            .AddObservability(); // Register instrumentation for Elastic APM
    }
}

Options

Elastic APM Transaction can be enriched by registering a delegate on configure parameter. In this way you can add custom data to the transaction.

services
    .AddGraphQLServer()
    .AddObservability(o => 
        o.Enrich = (transaction, operationDetails) =>
        {
            transaction.SetLabel("GraphQLResult", operationDetails.HasFailed);
            transaction.SetLabel("Department", Environment.GetEnvironmentVariable("DEPARTMENT"));
        });

Community

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the Swiss Life OSS Code of Conduct.

About

Multiple .NET libraries instrumentations for Elastic APM Agent

License:MIT License


Languages

Language:C# 80.9%Language:PowerShell 13.7%Language:Shell 5.5%