Elastic APM extensions for multiple .NET libraries.
Extension | MassTransit |
---|---|
Version 1 | Version 7 |
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
By default the Elastic APM send/receive label will be as follow:
- "Send {label}" where label is
SendContext.DestinationAddress.AbsolutePath
- "Receive {label}" where label is
ReceiveContext.InputAddress.AbsolutePath
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
Extension | HotChocolate |
---|---|
Version 1 | Version 11 |
Version 2 | Version 12 |
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
}
}
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"));
});
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.