[RabbitMQ] derived instrumentations for base consumer types (#3559)
derived instrumentations for rabbitmq base consumer types Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: Paulo Janotti <pjanotti@splunk.com>
This commit is contained in:
parent
8b4cd93c7f
commit
57d80ba6b7
|
@ -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
|
|
@ -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
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
@ -57,8 +55,6 @@ internal static partial class InstrumentationDefinitions
|
|||
// 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"));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
@ -51,8 +49,6 @@ internal static partial class InstrumentationDefinitions
|
|||
// 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"));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -29,12 +31,6 @@ internal static partial class InstrumentationDefinitions
|
|||
};
|
||||
}
|
||||
|
||||
// TODO: Generate this list using source generators
|
||||
private static NativeCallTargetDefinition[] GetDerivedDefinitionsArray()
|
||||
=> new NativeCallTargetDefinition[]
|
||||
{
|
||||
};
|
||||
|
||||
internal struct Payload
|
||||
{
|
||||
public string DefinitionsId { get; set; }
|
||||
|
|
|
@ -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;
|
||||
|
@ -24,6 +24,7 @@ internal class InstrumentMethodAttribute : Attribute
|
|||
};
|
||||
IntegrationName = integrationName;
|
||||
Type = type;
|
||||
Kind = integrationKind;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -83,4 +84,9 @@ internal class InstrumentMethodAttribute : Attribute
|
|||
/// 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; }
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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";
|
||||
|
|
|
@ -10,19 +10,20 @@ using OpenTelemetry.AutoInstrumentation.Util;
|
|||
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
|
|
@ -10,19 +10,20 @@ using OpenTelemetry.AutoInstrumentation.Util;
|
|||
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
|
|
@ -17,6 +17,8 @@ namespace SourceGenerators;
|
|||
public class InstrumentationDefinitionsGenerator : IIncrementalGenerator
|
||||
{
|
||||
private const string InstrumentMethodAttributeName = "OpenTelemetry.AutoInstrumentation.Instrumentations.InstrumentMethodAttribute";
|
||||
private const int IntegrationKindDirect = 0;
|
||||
private const int IntegrationKindDerived = 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
|
@ -41,8 +43,11 @@ public class InstrumentationDefinitionsGenerator : IIncrementalGenerator
|
|||
return;
|
||||
}
|
||||
|
||||
var result = GenerateInstrumentationDefinitionsPartialClass(instrumentationClasses);
|
||||
context.AddSource("InstrumentationDefinitions.g.cs", SourceText.From(result, Encoding.UTF8));
|
||||
var directIntegrations = GenerateInstrumentationDefinitionsPartialClass(instrumentationClasses, IntegrationKindDirect);
|
||||
context.AddSource("InstrumentationDefinitions.g.cs", SourceText.From(directIntegrations, Encoding.UTF8));
|
||||
|
||||
var derivedIntegrations = GenerateInstrumentationDefinitionsPartialClass(instrumentationClasses, IntegrationKindDerived);
|
||||
context.AddSource("InstrumentationDefinitions.Derived.g.cs", SourceText.From(derivedIntegrations, Encoding.UTF8));
|
||||
}
|
||||
|
||||
private static TargetToGenerate CreateTargetToGenerate(AttributeData attribute)
|
||||
|
@ -60,6 +65,7 @@ public class InstrumentationDefinitionsGenerator : IIncrementalGenerator
|
|||
}
|
||||
|
||||
var signalType = int.Parse(attribute.ConstructorArguments[8].Value!.ToString());
|
||||
var integrationKind = int.Parse(attribute.ConstructorArguments[9].Value!.ToString());
|
||||
var integrationName = attribute.ConstructorArguments[7].Value!.ToString();
|
||||
var targetAssembly = attribute.ConstructorArguments[0].Value!.ToString();
|
||||
var targetType = attribute.ConstructorArguments[1].Value!.ToString();
|
||||
|
@ -76,10 +82,11 @@ public class InstrumentationDefinitionsGenerator : IIncrementalGenerator
|
|||
var targetMaximumMinor = maxVersion.Length > 1 && maxVersion[1] != "*" ? int.Parse(maxVersion[1]) : ushort.MaxValue;
|
||||
var targetMaximumPatch = maxVersion.Length > 2 && maxVersion[2] != "*" ? int.Parse(maxVersion[2]) : ushort.MaxValue;
|
||||
|
||||
return new TargetToGenerate(signalType, integrationName, targetAssembly, targetType, targetMethod, targetMinimumMajor, targetMinimumMinor, targetMinimumPatch, targetMaximumMajor, targetMaximumMinor, targetMaximumPatch, targetSignatureTypesBuilder.ToString());
|
||||
return new TargetToGenerate(signalType, integrationName, targetAssembly, targetType, targetMethod, targetMinimumMajor, targetMinimumMinor, targetMinimumPatch, targetMaximumMajor, targetMaximumMinor, targetMaximumPatch, targetSignatureTypesBuilder.ToString(), integrationKind);
|
||||
}
|
||||
|
||||
private static string GenerateInstrumentationDefinitionsPartialClass(ImmutableArray<IntegrationToGenerate?> integrationClasses)
|
||||
private static string GenerateInstrumentationDefinitionsPartialClass(
|
||||
ImmutableArray<IntegrationToGenerate?> integrationClasses, int integrationKind)
|
||||
{
|
||||
var tracesByIntegrationName = new Dictionary<string, List<(string IntegrationType, TargetToGenerate Target)>>();
|
||||
var logsByIntegrationName = new Dictionary<string, List<(string IntegrationType, TargetToGenerate Target)>>();
|
||||
|
@ -89,7 +96,7 @@ public class InstrumentationDefinitionsGenerator : IIncrementalGenerator
|
|||
|
||||
foreach (var integrationToGenerate in integrationClasses)
|
||||
{
|
||||
foreach (var targetToGenerate in integrationToGenerate!.Value.Targets)
|
||||
foreach (var targetToGenerate in integrationToGenerate!.Value.Targets.Where(t => t.IntegrationKind == integrationKind))
|
||||
{
|
||||
Dictionary<string, List<(string IntegrationType, TargetToGenerate Target)>> byName;
|
||||
switch (targetToGenerate.SignalType)
|
||||
|
@ -125,6 +132,8 @@ public class InstrumentationDefinitionsGenerator : IIncrementalGenerator
|
|||
}
|
||||
}
|
||||
|
||||
var generatedMethodName = integrationKind == IntegrationKindDirect ? "GetDefinitionsArray" : "GetDerivedDefinitionsArray";
|
||||
|
||||
var sb = new StringBuilder()
|
||||
.AppendFormat(
|
||||
@"//------------------------------------------------------------------------------
|
||||
|
@ -144,11 +153,10 @@ namespace OpenTelemetry.AutoInstrumentation;
|
|||
|
||||
internal static partial class InstrumentationDefinitions
|
||||
{{
|
||||
private static readonly string AssemblyFullName = typeof(InstrumentationDefinitions).Assembly.FullName!;
|
||||
|
||||
private static NativeCallTargetDefinition[] GetDefinitionsArray()
|
||||
private static NativeCallTargetDefinition[] {0}()
|
||||
{{
|
||||
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>({0});",
|
||||
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>({1});",
|
||||
generatedMethodName,
|
||||
instrumentationCount)
|
||||
.AppendLine();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace SourceGenerators;
|
||||
|
||||
internal readonly record struct TargetToGenerate(int SignalType, string IntegrationName, string Assembly, string Type, string Method, int MinimumMajor, int MinimumMinor, int MinimumPatch, int MaximumMajor, int MaximumMinor, int MaximumPatch, string SignatureTypes)
|
||||
internal readonly record struct TargetToGenerate(int SignalType, string IntegrationName, string Assembly, string Type, string Method, int MinimumMajor, int MinimumMinor, int MinimumPatch, int MaximumMajor, int MaximumMinor, int MaximumPatch, string SignatureTypes, int IntegrationKind)
|
||||
{
|
||||
public readonly int SignalType = SignalType;
|
||||
|
||||
|
@ -28,4 +28,5 @@ internal readonly record struct TargetToGenerate(int SignalType, string Integrat
|
|||
public readonly int MaximumPatch = MaximumPatch;
|
||||
|
||||
public readonly string SignatureTypes = SignatureTypes;
|
||||
public readonly int IntegrationKind = IntegrationKind;
|
||||
}
|
||||
|
|
|
@ -55,12 +55,13 @@ internal static class Program
|
|||
|
||||
Publish(syncConsumersModel, GetTestMessage(), syncConsumersModel.CreateBasicProperties());
|
||||
|
||||
var consumer = new EventingBasicConsumer(syncConsumersModel);
|
||||
var consumer = new TestSyncConsumer(syncConsumersModel);
|
||||
|
||||
using var mre = new ManualResetEventSlim(false);
|
||||
|
||||
consumer.Received += (_, ea) =>
|
||||
{
|
||||
Console.WriteLine("[x] Handling BasicDeliver in TestSyncConsumer.");
|
||||
ProcessReceivedMessage(ea.Body);
|
||||
mre.Set();
|
||||
};
|
||||
|
@ -88,12 +89,13 @@ internal static class Program
|
|||
using var asyncConsumersModel = asyncConsumersConnection.CreateModel();
|
||||
|
||||
Publish(asyncConsumersModel, GetTestMessage(), asyncConsumersModel.CreateBasicProperties());
|
||||
var asyncConsumer = new AsyncEventingBasicConsumer(asyncConsumersModel);
|
||||
var asyncConsumer = new TestAsyncConsumer(asyncConsumersModel);
|
||||
|
||||
using var mre = new ManualResetEventSlim(false);
|
||||
|
||||
asyncConsumer.Received += async (_, ea) =>
|
||||
{
|
||||
Console.WriteLine("[x] Handling BasicDeliver in TestAsyncConsumer.");
|
||||
ProcessReceivedMessage(ea.Body);
|
||||
await Task.Yield();
|
||||
mre.Set();
|
||||
|
@ -142,4 +144,60 @@ internal static class Program
|
|||
{
|
||||
return $"Hello World!{_messageNumber++}";
|
||||
}
|
||||
|
||||
// Custom consumer classes, with implementation (simplified) based on EventingBasicConsumer/AsyncEventingBasicConsumer
|
||||
// from the library.
|
||||
private class TestAsyncConsumer : AsyncDefaultBasicConsumer
|
||||
{
|
||||
public TestAsyncConsumer(IModel model)
|
||||
: base(model)
|
||||
{
|
||||
}
|
||||
|
||||
public event AsyncEventHandler<BasicDeliverEventArgs>? Received;
|
||||
|
||||
public override Task? HandleBasicDeliver(
|
||||
string consumerTag,
|
||||
ulong deliveryTag,
|
||||
bool redelivered,
|
||||
string exchange,
|
||||
string routingKey,
|
||||
IBasicProperties properties,
|
||||
ReadOnlyMemory<byte> body)
|
||||
{
|
||||
return Received?.Invoke(
|
||||
this,
|
||||
new BasicDeliverEventArgs(
|
||||
consumerTag,
|
||||
deliveryTag,
|
||||
redelivered,
|
||||
exchange,
|
||||
routingKey,
|
||||
properties,
|
||||
body));
|
||||
}
|
||||
}
|
||||
|
||||
private class TestSyncConsumer : DefaultBasicConsumer
|
||||
{
|
||||
public TestSyncConsumer(IModel model)
|
||||
: base(model)
|
||||
{
|
||||
}
|
||||
|
||||
public event EventHandler<BasicDeliverEventArgs>? Received;
|
||||
|
||||
public override void HandleBasicDeliver(
|
||||
string consumerTag,
|
||||
ulong deliveryTag,
|
||||
bool redelivered,
|
||||
string exchange,
|
||||
string routingKey,
|
||||
IBasicProperties properties,
|
||||
ReadOnlyMemory<byte> body)
|
||||
{
|
||||
base.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
|
||||
Received?.Invoke(this, new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue