Skip to content

Commit 3f3aa83

Browse files
vandonrchojomok
authored andcommitted
restore Protobuf instrumentation for schema tracking (#6826)
## Summary of changes revert the revert of #6792 The missingMethodExceptions were most likely caused by a trimmed app ([see discussion](https://dd.slack.com/archives/C07TBLYDQHX/p1741907211362359)). We had some defense against this for _instrumented_ types, but not for duck-typed types, and this is where the issue laid. This was taken care of in #6807 for the generic case, and also after [talking with DSM](https://dd.slack.com/archives/C069TJPTFPG/p1743500681812779), they agree that we should try to instrument only user-defined protobufs, so I excluded the microsoft protobufs (that were causing the issue). Thus, this PR should be fine to merge as-is, even though it's best to merge it after #6807 for maximum safety. ## Reason for change ## Implementation details ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. -->
1 parent e571c99 commit 3f3aa83

File tree

12 files changed

+311
-187
lines changed

12 files changed

+311
-187
lines changed

tracer/build/supported_calltargets.g.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12582,6 +12582,102 @@
1258212582
"IsAdoNetIntegration": false,
1258312583
"InstrumentationCategory": 1
1258412584
},
12585+
{
12586+
"IntegrationName": "Protobuf",
12587+
"AssemblyName": "Google.Protobuf",
12588+
"TargetTypeName": "Google.Protobuf.IBufferMessage",
12589+
"TargetMethodName": "InternalMergeFrom",
12590+
"TargetReturnType": "System.Void",
12591+
"TargetParameterTypes": [
12592+
"Google.Protobuf.ParseContext&"
12593+
],
12594+
"MinimumVersion": {
12595+
"Item1": 3,
12596+
"Item2": 15,
12597+
"Item3": 0
12598+
},
12599+
"MaximumVersion": {
12600+
"Item1": 3,
12601+
"Item2": 65535,
12602+
"Item3": 65535
12603+
},
12604+
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalMergeFromIntegration",
12605+
"IntegrationKind": 2,
12606+
"IsAdoNetIntegration": false,
12607+
"InstrumentationCategory": 1
12608+
},
12609+
{
12610+
"IntegrationName": "Protobuf",
12611+
"AssemblyName": "Google.Protobuf",
12612+
"TargetTypeName": "Google.Protobuf.IBufferMessage",
12613+
"TargetMethodName": "InternalWriteTo",
12614+
"TargetReturnType": "System.Void",
12615+
"TargetParameterTypes": [
12616+
"Google.Protobuf.WriteContext&"
12617+
],
12618+
"MinimumVersion": {
12619+
"Item1": 3,
12620+
"Item2": 15,
12621+
"Item3": 0
12622+
},
12623+
"MaximumVersion": {
12624+
"Item1": 3,
12625+
"Item2": 65535,
12626+
"Item3": 65535
12627+
},
12628+
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalWriteToIntegration",
12629+
"IntegrationKind": 2,
12630+
"IsAdoNetIntegration": false,
12631+
"InstrumentationCategory": 1
12632+
},
12633+
{
12634+
"IntegrationName": "Protobuf",
12635+
"AssemblyName": "Google.Protobuf",
12636+
"TargetTypeName": "Google.Protobuf.IMessage",
12637+
"TargetMethodName": "MergeFrom",
12638+
"TargetReturnType": "System.Void",
12639+
"TargetParameterTypes": [
12640+
"Google.Protobuf.CodedInputStream"
12641+
],
12642+
"MinimumVersion": {
12643+
"Item1": 3,
12644+
"Item2": 0,
12645+
"Item3": 0
12646+
},
12647+
"MaximumVersion": {
12648+
"Item1": 3,
12649+
"Item2": 65535,
12650+
"Item3": 65535
12651+
},
12652+
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageMergeFromIntegration",
12653+
"IntegrationKind": 2,
12654+
"IsAdoNetIntegration": false,
12655+
"InstrumentationCategory": 1
12656+
},
12657+
{
12658+
"IntegrationName": "Protobuf",
12659+
"AssemblyName": "Google.Protobuf",
12660+
"TargetTypeName": "Google.Protobuf.IMessage",
12661+
"TargetMethodName": "WriteTo",
12662+
"TargetReturnType": "System.Void",
12663+
"TargetParameterTypes": [
12664+
"Google.Protobuf.CodedOutputStream"
12665+
],
12666+
"MinimumVersion": {
12667+
"Item1": 3,
12668+
"Item2": 0,
12669+
"Item3": 0
12670+
},
12671+
"MaximumVersion": {
12672+
"Item1": 3,
12673+
"Item2": 65535,
12674+
"Item3": 65535
12675+
},
12676+
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageWriteToIntegration",
12677+
"IntegrationKind": 2,
12678+
"IsAdoNetIntegration": false,
12679+
"InstrumentationCategory": 1
12680+
},
1258512681
{
1258612682
"IntegrationName": "RabbitMQ",
1258712683
"AssemblyName": "RabbitMQ.Client",

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/BufferMessageInternalMergeFromIntegration.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf;
1515
/// <summary>
1616
/// System.Void Google.Protobuf.IBufferMessage::InternalMergeFrom(Google.Protobuf.ParseContext) calltarget instrumentation
1717
/// </summary>
18-
// FIXME: Commenting out due to throwing errors.
19-
// [InstrumentMethod(
20-
// AssemblyName = "Google.Protobuf",
21-
// TypeName = "Google.Protobuf.IBufferMessage",
22-
// MethodName = "InternalMergeFrom",
23-
// ParameterTypeNames = ["Google.Protobuf.ParseContext&"],
24-
// ReturnTypeName = ClrNames.Void,
25-
// MinimumVersion = "3.15.0",
26-
// MaximumVersion = "3.*.*",
27-
// IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
28-
// CallTargetIntegrationKind = CallTargetKind.Interface)]
18+
[InstrumentMethod(
19+
AssemblyName = "Google.Protobuf",
20+
TypeName = "Google.Protobuf.IBufferMessage",
21+
MethodName = "InternalMergeFrom",
22+
ParameterTypeNames = ["Google.Protobuf.ParseContext&"],
23+
ReturnTypeName = ClrNames.Void,
24+
MinimumVersion = "3.15.0",
25+
MaximumVersion = "3.*.*",
26+
IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
27+
CallTargetIntegrationKind = CallTargetKind.Interface)]
2928
[Browsable(false)]
3029
[EditorBrowsable(EditorBrowsableState.Never)]
3130
public class BufferMessageInternalMergeFromIntegration

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/BufferMessageInternalWriteToIntegration.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf;
1515
/// <summary>
1616
/// System.Void Google.Protobuf.IBufferMessage::InternalWriteTo(Google.Protobuf.WriteContext) calltarget instrumentation
1717
/// </summary>
18-
// FIXME: Commenting out due to throwing errors.
19-
// [InstrumentMethod(
20-
// AssemblyName = "Google.Protobuf",
21-
// TypeName = "Google.Protobuf.IBufferMessage",
22-
// MethodName = "InternalWriteTo",
23-
// ReturnTypeName = ClrNames.Void,
24-
// ParameterTypeNames = ["Google.Protobuf.WriteContext&"],
25-
// MinimumVersion = "3.15.0",
26-
// MaximumVersion = "3.*.*",
27-
// IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
28-
// CallTargetIntegrationKind = CallTargetKind.Interface)]
18+
[InstrumentMethod(
19+
AssemblyName = "Google.Protobuf",
20+
TypeName = "Google.Protobuf.IBufferMessage",
21+
MethodName = "InternalWriteTo",
22+
ReturnTypeName = ClrNames.Void,
23+
ParameterTypeNames = ["Google.Protobuf.WriteContext&"],
24+
MinimumVersion = "3.15.0",
25+
MaximumVersion = "3.*.*",
26+
IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
27+
CallTargetIntegrationKind = CallTargetKind.Interface)]
2928
[Browsable(false)]
3029
[EditorBrowsable(EditorBrowsableState.Never)]
3130
public class BufferMessageInternalWriteToIntegration

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/Helper.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf;
1111

1212
internal static class Helper
1313
{
14+
/// <summary>
15+
/// Disable the instrumentation when we detect a protobuf message that is 100% not defined by the customer
16+
/// (currently we disable it only for Google protobuf itself and Microsoft types)
17+
/// </summary>
1418
/// <typeparam name="TMessage">needs to be the raw type (not a DuckType)</typeparam>
1519
public static void DisableInstrumentationIfInternalProtobufType<TMessage>()
1620
{
1721
var typeName = typeof(TMessage).FullName;
18-
if (typeName != null && typeName.StartsWith("Google.Protobuf.", StringComparison.OrdinalIgnoreCase))
19-
{
22+
if (typeName != null &&
2023
// Google uses protobuf internally in the protobuf library, we don't want to capture those.
24+
(typeName.StartsWith("Google.Protobuf.", StringComparison.OrdinalIgnoreCase)
25+
// Microsoft has some protobuf definitions in https://github.com/microsoft/durabletask-protobuf for instance
26+
|| typeName.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase)))
27+
{
2128
// We disable the integrations once and for all here.
2229
IntegrationOptions<MessageWriteToIntegration, TMessage>.DisableIntegration();
2330
IntegrationOptions<MessageMergeFromIntegration, TMessage>.DisableIntegration();

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/MessageMergeFromIntegration.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf;
1515
/// <summary>
1616
/// System.Void Google.Protobuf.IMessage::MergeFrom(Google.Protobuf.CodedInputStream) calltarget instrumentation
1717
/// </summary>
18-
// FIXME: Commenting out due to throwing errors.
19-
// [InstrumentMethod(
20-
// AssemblyName = "Google.Protobuf",
21-
// TypeName = "Google.Protobuf.IMessage",
22-
// MethodName = "MergeFrom",
23-
// ReturnTypeName = ClrNames.Void,
24-
// ParameterTypeNames = ["Google.Protobuf.CodedInputStream"],
25-
// MinimumVersion = "3.0.0",
26-
// MaximumVersion = "3.*.*",
27-
// IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
28-
// CallTargetIntegrationKind = CallTargetKind.Interface)]
18+
[InstrumentMethod(
19+
AssemblyName = "Google.Protobuf",
20+
TypeName = "Google.Protobuf.IMessage",
21+
MethodName = "MergeFrom",
22+
ReturnTypeName = ClrNames.Void,
23+
ParameterTypeNames = ["Google.Protobuf.CodedInputStream"],
24+
MinimumVersion = "3.0.0",
25+
MaximumVersion = "3.*.*",
26+
IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
27+
CallTargetIntegrationKind = CallTargetKind.Interface)]
2928
[Browsable(false)]
3029
[EditorBrowsable(EditorBrowsableState.Never)]
3130
public class MessageMergeFromIntegration

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/MessageWriteToIntegration.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf;
1515
/// <summary>
1616
/// System.Void Google.Protobuf.IMessage::WriteTo(Google.Protobuf.CodedOutputStream) calltarget instrumentation
1717
/// </summary>
18-
// FIXME: Commenting out due to throwing errors.
19-
// [InstrumentMethod(
20-
// AssemblyName = "Google.Protobuf",
21-
// TypeName = "Google.Protobuf.IMessage",
22-
// MethodName = "WriteTo",
23-
// ReturnTypeName = ClrNames.Void,
24-
// ParameterTypeNames = ["Google.Protobuf.CodedOutputStream"],
25-
// MinimumVersion = "3.0.0",
26-
// MaximumVersion = "3.*.*",
27-
// IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
28-
// CallTargetIntegrationKind = CallTargetKind.Interface)]
18+
[InstrumentMethod(
19+
AssemblyName = "Google.Protobuf",
20+
TypeName = "Google.Protobuf.IMessage",
21+
MethodName = "WriteTo",
22+
ReturnTypeName = ClrNames.Void,
23+
ParameterTypeNames = ["Google.Protobuf.CodedOutputStream"],
24+
MinimumVersion = "3.0.0",
25+
MaximumVersion = "3.*.*",
26+
IntegrationName = nameof(Configuration.IntegrationId.Protobuf),
27+
CallTargetIntegrationKind = CallTargetKind.Interface)]
2928
[Browsable(false)]
3029
[EditorBrowsable(EditorBrowsableState.Never)]
3130
public class MessageWriteToIntegration

tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ internal static bool IsInstrumentedAssembly(string assemblyName)
464464
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
465465
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
466466
=> Datadog.Trace.Configuration.IntegrationId.Process,
467+
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalMergeFromIntegration"
468+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalWriteToIntegration"
469+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageMergeFromIntegration"
470+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageWriteToIntegration"
471+
=> Datadog.Trace.Configuration.IntegrationId.Protobuf,
467472
"Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncIntegration"
468473
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncAsyncIntegration"
469474
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverIntegration"

tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ internal static bool IsInstrumentedAssembly(string assemblyName)
494494
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
495495
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
496496
=> Datadog.Trace.Configuration.IntegrationId.Process,
497+
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalMergeFromIntegration"
498+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalWriteToIntegration"
499+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageMergeFromIntegration"
500+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageWriteToIntegration"
501+
=> Datadog.Trace.Configuration.IntegrationId.Protobuf,
497502
"Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncIntegration"
498503
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncAsyncIntegration"
499504
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverIntegration"

tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ internal static bool IsInstrumentedAssembly(string assemblyName)
489489
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
490490
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
491491
=> Datadog.Trace.Configuration.IntegrationId.Process,
492+
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalMergeFromIntegration"
493+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalWriteToIntegration"
494+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageMergeFromIntegration"
495+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageWriteToIntegration"
496+
=> Datadog.Trace.Configuration.IntegrationId.Protobuf,
492497
"Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncIntegration"
493498
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncAsyncIntegration"
494499
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverIntegration"

tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ internal static bool IsInstrumentedAssembly(string assemblyName)
489489
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
490490
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Process.ProcessStartIntegration"
491491
=> Datadog.Trace.Configuration.IntegrationId.Process,
492+
"Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalMergeFromIntegration"
493+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.BufferMessageInternalWriteToIntegration"
494+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageMergeFromIntegration"
495+
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Protobuf.MessageWriteToIntegration"
496+
=> Datadog.Trace.Configuration.IntegrationId.Protobuf,
492497
"Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncIntegration"
493498
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverAsyncAsyncIntegration"
494499
or "Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.BasicDeliverIntegration"

0 commit comments

Comments
 (0)