Skip to content

Commit

Permalink
[RabbitMQ] derived instrumentations for base consumer types (#3559)
Browse files Browse the repository at this point in the history
derived instrumentations for rabbitmq base consumer types

Co-authored-by: Robert Pająk <[email protected]>
Co-authored-by: Paulo Janotti <[email protected]>
  • Loading branch information
3 people authored Aug 12, 2024
1 parent 8b4cd93 commit 57d80ba
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncEventingBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.EventingBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncDefaultBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.DefaultBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBaseBasicGetIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBasicPublishIntegration
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncEventingBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.EventingBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncDefaultBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.DefaultBasicConsumerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBaseBasicGetIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBasicPublishIntegration
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the InstrumentationDefinitionsGenerator tool. To safely
// modify this file, edit InstrumentMethodAttribute on the classes and
// compile project.

// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using OpenTelemetry.AutoInstrumentation.Configurations;

namespace OpenTelemetry.AutoInstrumentation;

internal static partial class InstrumentationDefinitions
{
private static NativeCallTargetDefinition[] GetDerivedDefinitionsArray()
{
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(2);
// Traces
var tracerSettings = Instrumentation.TracerSettings.Value;
if (tracerSettings.TracesEnabled)
{
// RabbitMq
if (tracerSettings.EnabledInstrumentations.Contains(TracerInstrumentation.RabbitMq))
{
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.AsyncDefaultBasicConsumer", "HandleBasicDeliver", new[] {"System.Threading.Tasks.Task", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncDefaultBasicConsumerIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.DefaultBasicConsumer", "HandleBasicDeliver", new[] {"System.Void", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.DefaultBasicConsumerIntegration"));
}
}

return nativeCallTargetDefinitions.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ namespace OpenTelemetry.AutoInstrumentation;

internal static partial class InstrumentationDefinitions
{
private static readonly string AssemblyFullName = typeof(InstrumentationDefinitions).Assembly.FullName!;

private static NativeCallTargetDefinition[] GetDefinitionsArray()
{
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(20);
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(18);
// Traces
var tracerSettings = Instrumentation.TracerSettings.Value;
if (tracerSettings.TracesEnabled)
Expand Down Expand Up @@ -57,8 +55,6 @@ private static NativeCallTargetDefinition[] GetDefinitionsArray()
// RabbitMq
if (tracerSettings.EnabledInstrumentations.Contains(TracerInstrumentation.RabbitMq))
{
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Events.AsyncEventingBasicConsumer", "HandleBasicDeliver", new[] {"System.Threading.Tasks.Task", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncEventingBasicConsumerIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Events.EventingBasicConsumer", "HandleBasicDeliver", new[] {"System.Void", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.EventingBasicConsumerIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Impl.ModelBase", "BasicGet", new[] {"RabbitMQ.Client.BasicGetResult", "System.String", "System.Boolean"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBaseBasicGetIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Framing.Impl.Model", "_Private_BasicPublish", new[] {"System.Void", "System.String", "System.String", "System.Boolean", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBasicPublishIntegration"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the InstrumentationDefinitionsGenerator tool. To safely
// modify this file, edit InstrumentMethodAttribute on the classes and
// compile project.

// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using OpenTelemetry.AutoInstrumentation.Configurations;

namespace OpenTelemetry.AutoInstrumentation;

internal static partial class InstrumentationDefinitions
{
private static NativeCallTargetDefinition[] GetDerivedDefinitionsArray()
{
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(2);
// Traces
var tracerSettings = Instrumentation.TracerSettings.Value;
if (tracerSettings.TracesEnabled)
{
// RabbitMq
if (tracerSettings.EnabledInstrumentations.Contains(TracerInstrumentation.RabbitMq))
{
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.AsyncDefaultBasicConsumer", "HandleBasicDeliver", new[] {"System.Threading.Tasks.Task", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncDefaultBasicConsumerIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.DefaultBasicConsumer", "HandleBasicDeliver", new[] {"System.Void", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.DefaultBasicConsumerIntegration"));
}
}

return nativeCallTargetDefinitions.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ namespace OpenTelemetry.AutoInstrumentation;

internal static partial class InstrumentationDefinitions
{
private static readonly string AssemblyFullName = typeof(InstrumentationDefinitions).Assembly.FullName!;

private static NativeCallTargetDefinition[] GetDefinitionsArray()
{
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(23);
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(21);
// Traces
var tracerSettings = Instrumentation.TracerSettings.Value;
if (tracerSettings.TracesEnabled)
Expand Down Expand Up @@ -51,8 +49,6 @@ private static NativeCallTargetDefinition[] GetDefinitionsArray()
// RabbitMq
if (tracerSettings.EnabledInstrumentations.Contains(TracerInstrumentation.RabbitMq))
{
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Events.AsyncEventingBasicConsumer", "HandleBasicDeliver", new[] {"System.Threading.Tasks.Task", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.AsyncEventingBasicConsumerIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Events.EventingBasicConsumer", "HandleBasicDeliver", new[] {"System.Void", "System.String", "System.UInt64", "System.Boolean", "System.String", "System.String", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.EventingBasicConsumerIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Impl.ModelBase", "BasicGet", new[] {"RabbitMQ.Client.BasicGetResult", "System.String", "System.Boolean"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBaseBasicGetIntegration"));
nativeCallTargetDefinitions.Add(new("RabbitMQ.Client", "RabbitMQ.Client.Framing.Impl.Model", "_Private_BasicPublish", new[] {"System.Void", "System.String", "System.String", "System.Boolean", "RabbitMQ.Client.IBasicProperties", "System.ReadOnlyMemory`1[System.Byte]"}, 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations.ModelBasicPublishIntegration"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace OpenTelemetry.AutoInstrumentation;

internal static partial class InstrumentationDefinitions
{
private static readonly string AssemblyFullName = typeof(InstrumentationDefinitions).Assembly.FullName!;

internal static Payload GetAllDefinitions()
{
return new Payload
Expand All @@ -29,12 +31,6 @@ internal static Payload GetDerivedDefinitions()
};
}

// TODO: Generate this list using source generators
private static NativeCallTargetDefinition[] GetDerivedDefinitionsArray()
=> new NativeCallTargetDefinition[]
{
};

internal struct Payload
{
public string DefinitionsId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OpenTelemetry.AutoInstrumentation.Instrumentations;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
internal class InstrumentMethodAttribute : Attribute
{
public InstrumentMethodAttribute(string assemblyName, string typeName, string methodName, string returnTypeName, string[] parameterTypeNames, string minimumVersion, string maximumVersion, string integrationName, InstrumentationType type)
public InstrumentMethodAttribute(string assemblyName, string typeName, string methodName, string returnTypeName, string[] parameterTypeNames, string minimumVersion, string maximumVersion, string integrationName, InstrumentationType type, IntegrationKind integrationKind = IntegrationKind.Direct)
{
AssemblyName = assemblyName;
TypeName = typeName;
Expand All @@ -24,6 +24,7 @@ public InstrumentMethodAttribute(string assemblyName, string typeName, string me
};
IntegrationName = integrationName;
Type = type;
Kind = integrationKind;
}

/// <summary>
Expand Down Expand Up @@ -83,4 +84,9 @@ public string MaximumVersion
/// Gets or sets the integration type.
/// </summary>
public InstrumentationType Type { get; set; }

/// <summary>
/// Gets or sets the integration kind.
/// </summary>
public IntegrationKind Kind { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

namespace OpenTelemetry.AutoInstrumentation.Instrumentations;

internal enum IntegrationKind
{
Direct = 0,
Derived = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal static class IntegrationConstants
public const string RabbitMqByteCodeIntegrationName = "RabbitMq";
public const string RabbitMqAssemblyName = "RabbitMQ.Client";
public const string ModelBaseTypeName = "RabbitMQ.Client.Impl.ModelBase";
public const string EventingBasicConsumerTypeName = "RabbitMQ.Client.Events.EventingBasicConsumer";
public const string AsyncEventingBasicConsumerTypeName = "RabbitMQ.Client.Events.AsyncEventingBasicConsumer";
public const string DefaultBasicConsumerTypeName = "RabbitMQ.Client.DefaultBasicConsumer";
public const string AsyncDefaultBasicConsumerTypeName = "RabbitMQ.Client.AsyncDefaultBasicConsumer";
public const string ModelGeneratedTypeName = "RabbitMQ.Client.Framing.Impl.Model";
public const string BasicGetResultTypeName = "RabbitMQ.Client.BasicGetResult";
public const string BasicPropertiesInterfaceTypeName = "RabbitMQ.Client.IBasicProperties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
namespace OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations;

/// <summary>
/// RabbitMq AsyncEventingBasicConsumer.HandleBasicDeliver integration.
/// RabbitMq AsyncDefaultBasicConsumer.HandleBasicDeliver integration.
/// </summary>
[InstrumentMethod(
assemblyName: IntegrationConstants.RabbitMqAssemblyName,
typeName: IntegrationConstants.AsyncEventingBasicConsumerTypeName,
typeName: IntegrationConstants.AsyncDefaultBasicConsumerTypeName,
methodName: IntegrationConstants.HandleBasicDeliverMethodName,
returnTypeName: ClrNames.Task,
parameterTypeNames: new[] { ClrNames.String, ClrNames.UInt64, ClrNames.Bool, ClrNames.String, ClrNames.String, IntegrationConstants.BasicPropertiesInterfaceTypeName, $"System.ReadOnlyMemory`1[{ClrNames.Byte}]" },
minimumVersion: IntegrationConstants.MinSupportedVersion,
maximumVersion: IntegrationConstants.MaxSupportedVersion,
integrationName: IntegrationConstants.RabbitMqByteCodeIntegrationName,
type: InstrumentationType.Trace)]
public static class AsyncEventingBasicConsumerIntegration
type: InstrumentationType.Trace,
integrationKind: IntegrationKind.Derived)]
public static class AsyncDefaultBasicConsumerIntegration
{
internal static CallTargetState OnMethodBegin<TTarget, TBasicProperties, TBody>(TTarget instance, string? consumerTag, ulong deliveryTag, bool redelivered, string? exchange, string? routingKey, TBasicProperties properties, TBody body)
where TBasicProperties : IBasicProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
namespace OpenTelemetry.AutoInstrumentation.Instrumentations.RabbitMq6.Integrations;

/// <summary>
/// RabbitMq EventingBasicConsumer.HandleBasicDeliver integration.
/// RabbitMq DefaultBasicConsumer.HandleBasicDeliver integration.
/// </summary>
[InstrumentMethod(
assemblyName: IntegrationConstants.RabbitMqAssemblyName,
typeName: IntegrationConstants.EventingBasicConsumerTypeName,
typeName: IntegrationConstants.DefaultBasicConsumerTypeName,
methodName: IntegrationConstants.HandleBasicDeliverMethodName,
returnTypeName: ClrNames.Void,
parameterTypeNames: new[] { ClrNames.String, ClrNames.UInt64, ClrNames.Bool, ClrNames.String, ClrNames.String, IntegrationConstants.BasicPropertiesInterfaceTypeName, $"System.ReadOnlyMemory`1[{ClrNames.Byte}]" },
minimumVersion: IntegrationConstants.MinSupportedVersion,
maximumVersion: IntegrationConstants.MaxSupportedVersion,
integrationName: IntegrationConstants.RabbitMqByteCodeIntegrationName,
type: InstrumentationType.Trace)]
public static class EventingBasicConsumerIntegration
type: InstrumentationType.Trace,
integrationKind: IntegrationKind.Derived)]
public static class DefaultBasicConsumerIntegration
{
internal static CallTargetState OnMethodBegin<TTarget, TBasicProperties, TBody>(TTarget instance, string? consumerTag, ulong deliveryTag, bool redelivered, string? exchange, string? routingKey, TBasicProperties properties, TBody body)
where TBasicProperties : IBasicProperties
Expand Down
Loading

0 comments on commit 57d80ba

Please sign in to comment.