Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions tracer/build/supported_calltargets.g.json
Original file line number Diff line number Diff line change
Expand Up @@ -13568,6 +13568,152 @@
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
"TargetTypeName": "OpenTelemetry.Baggage",
"TargetMethodName": "ClearBaggage",
"TargetReturnType": "OpenTelemetry.Baggage",
"TargetParameterTypes": [
"OpenTelemetry.Baggage"
],
"MinimumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry.OTelBaggage_ClearBaggageIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
"TargetTypeName": "OpenTelemetry.Baggage",
"TargetMethodName": "get_Current",
"TargetReturnType": "OpenTelemetry.Baggage",
"TargetParameterTypes": [],
"MinimumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry.OTelBaggage_GetCurrentIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
"TargetTypeName": "OpenTelemetry.Baggage",
"TargetMethodName": "RemoveBaggage",
"TargetReturnType": "OpenTelemetry.Baggage",
"TargetParameterTypes": [
"System.String",
"OpenTelemetry.Baggage"
],
"MinimumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry.OTelBaggage_RemoveBaggageIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
"TargetTypeName": "OpenTelemetry.Baggage",
"TargetMethodName": "set_Current",
"TargetReturnType": "System.Void",
"TargetParameterTypes": [
"OpenTelemetry.Baggage"
],
"MinimumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry.OTelBaggage_SetCurrentIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
"TargetTypeName": "OpenTelemetry.Baggage",
"TargetMethodName": "SetBaggage",
"TargetReturnType": "OpenTelemetry.Baggage",
"TargetParameterTypes": [
"System.String",
"System.String",
"OpenTelemetry.Baggage"
],
"MinimumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry.OTelBaggage_SetBaggageIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
"TargetTypeName": "OpenTelemetry.Baggage",
"TargetMethodName": "SetBaggage",
"TargetReturnType": "OpenTelemetry.Baggage",
"TargetParameterTypes": [
"System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.String,System.String]]",
"OpenTelemetry.Baggage"
],
"MinimumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item2": 0,
"Item3": 0
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry.OTelBaggage_SetBaggageItemsIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenTelemetry",
"AssemblyName": "OpenTelemetry.Api",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <copyright file="IApiBaggage.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#nullable enable

using System.Collections.Generic;

namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry
{
/// <summary>
/// OpenTelemetry.Baggage interface for duck-typing
/// </summary>
internal interface IApiBaggage
{
object Create(Dictionary<string, string?>? baggageItems);

IReadOnlyDictionary<string, string?> GetBaggage();

string? GetBaggage(string name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// <copyright file="OTelBaggage_ClearBaggageIntegration.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#nullable enable

using System;
using System.ComponentModel;
using Datadog.Trace;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.Configuration;
using Datadog.Trace.DuckTyping;

namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry
{
/// <summary>
/// Msmq calltarget instrumentation
/// </summary>
[InstrumentMethod(
AssemblyName = "OpenTelemetry.Api",
TypeName = "OpenTelemetry.Baggage",
MethodName = "ClearBaggage",
ReturnTypeName = "OpenTelemetry.Baggage",
ParameterTypeNames = new[] { "OpenTelemetry.Baggage" },
MinimumVersion = "1.0.0",
MaximumVersion = "1.0.0",
IntegrationName = IntegrationName)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public class OTelBaggage_ClearBaggageIntegration
{
internal const string IntegrationName = nameof(Configuration.IntegrationId.OpenTelemetry);
internal const IntegrationId IntegrationId = Configuration.IntegrationId.OpenTelemetry;

/// <summary>
/// OnMethodEnd callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Type of the return value</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="returnValue">Return value</param>
/// <param name="exception">Exception instance in case the original code threw an exception.</param>
/// <param name="state">Calltarget state value</param>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
internal static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
{
if (Tracer.Instance.CurrentTraceSettings.Settings.IsIntegrationEnabled(IntegrationId))
{
// The OpenTelemetry Baggage model creates immutable baggage instances, so users cannot hold a reference to a Baggage object and mutate it multiple times
// On the other hand, the Datadog Baggage model is mutable, allowing the user to get the Datadog.Trace.Baggage.Current once and continue to mutate that reference.
// To ensure that updates from OpenTelemetry are reflected in the Datadog Baggage model, we must clear then add the new baggage items.
Baggage.Current.Clear();
}

return new CallTargetReturn<TReturn>(returnValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// <copyright file="OTelBaggage_GetCurrentIntegration.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#nullable enable

using System;
using System.ComponentModel;
using System.Linq;
using Datadog.Trace;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.Configuration;
using Datadog.Trace.DuckTyping;

namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry
{
/// <summary>
/// Msmq calltarget instrumentation
/// </summary>
[InstrumentMethod(
AssemblyName = "OpenTelemetry.Api",
TypeName = "OpenTelemetry.Baggage",
MethodName = "get_Current",
ReturnTypeName = "OpenTelemetry.Baggage",
ParameterTypeNames = new string[0],
MinimumVersion = "1.0.0",
MaximumVersion = "1.0.0",
IntegrationName = IntegrationName)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public class OTelBaggage_GetCurrentIntegration
{
internal const string IntegrationName = nameof(Configuration.IntegrationId.OpenTelemetry);
internal const IntegrationId IntegrationId = Configuration.IntegrationId.OpenTelemetry;

/// <summary>
/// OnMethodEnd callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Type of the return value</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="returnValue">Return value</param>
/// <param name="exception">Exception instance in case the original code threw an exception.</param>
/// <param name="state">Calltarget state value</param>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
internal static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
{
if (Tracer.Instance.CurrentTraceSettings.Settings.IsIntegrationEnabled(IntegrationId)
&& returnValue.TryDuckCast<IApiBaggage>(out var apiBaggage))
{
return new CallTargetReturn<TReturn>((TReturn)apiBaggage.Create(Baggage.Current.ToDictionary(kvp => kvp.Key, kvp => kvp.Value))!);
}

return new CallTargetReturn<TReturn>(returnValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// <copyright file="OTelBaggage_RemoveBaggageIntegration.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#nullable enable

using System;
using System.ComponentModel;
using Datadog.Trace;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.Configuration;
using Datadog.Trace.DuckTyping;

namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.OpenTelemetry
{
/// <summary>
/// Msmq calltarget instrumentation
/// </summary>
[InstrumentMethod(
AssemblyName = "OpenTelemetry.Api",
TypeName = "OpenTelemetry.Baggage",
MethodName = "RemoveBaggage",
ReturnTypeName = "OpenTelemetry.Baggage",
ParameterTypeNames = new[] { ClrNames.String, "OpenTelemetry.Baggage" },
MinimumVersion = "1.0.0",
MaximumVersion = "1.0.0",
IntegrationName = IntegrationName)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public class OTelBaggage_RemoveBaggageIntegration
{
internal const string IntegrationName = nameof(Configuration.IntegrationId.OpenTelemetry);
internal const IntegrationId IntegrationId = Configuration.IntegrationId.OpenTelemetry;

/// <summary>
/// OnMethodEnd callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Type of the return value</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="returnValue">Return value</param>
/// <param name="exception">Exception instance in case the original code threw an exception.</param>
/// <param name="state">Calltarget state value</param>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
internal static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
{
if (Tracer.Instance.CurrentTraceSettings.Settings.IsIntegrationEnabled(IntegrationId)
&& returnValue.TryDuckCast<IApiBaggage>(out var apiBaggage))
{
// The OpenTelemetry Baggage model creates immutable baggage instances, so users cannot hold a reference to a Baggage object and mutate it multiple times
// On the other hand, the Datadog Baggage model is mutable, allowing the user to get the Datadog.Trace.Baggage.Current once and continue to mutate that reference.
// To ensure that updates from OpenTelemetry are reflected in the Datadog Baggage model, we must clear then add the new baggage items.
Baggage.Current.Clear();
var newBaggage = new Baggage(apiBaggage.GetBaggage());
newBaggage.MergeInto(Baggage.Current);
}

return new CallTargetReturn<TReturn>(returnValue);
}
}
}
Loading
Loading