Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
24 changes: 24 additions & 0 deletions tracer/build/supported_calltargets.g.json
Original file line number Diff line number Diff line change
Expand Up @@ -14082,6 +14082,30 @@
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenFeature",
"AssemblyName": "Datadog.FeatureFlags.OpenFeature",
"TargetTypeName": "Datadog.FeatureFlags.OpenFeature.FeatureFlagsSdk",
"TargetMethodName": "InitializeAsync",
"TargetReturnType": "System.Threading.Tasks.Task",
"TargetParameterTypes": [
"System.Threading.CancellationToken"
],
"MinimumVersion": {
"Item1": 2,
"Item2": 0,
"Item3": 0
},
"MaximumVersion": {
"Item1": 2,
"Item2": 65535,
"Item3": 65535
},
"InstrumentationTypeName": "Datadog.Trace.ClrProfiler.AutoInstrumentation.ManualInstrumentation.OpenFeature.OpenFeatureSdkInitializeAsyncIntegration",
"IntegrationKind": 0,
"IsAdoNetIntegration": false,
"InstrumentationCategory": 1
},
{
"IntegrationName": "OpenFeature",
"AssemblyName": "Datadog.FeatureFlags.OpenFeature",
Expand Down
12 changes: 12 additions & 0 deletions tracer/src/Datadog.FeatureFlags.OpenFeature/DatadogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ private void SignalGeneralUpdate()
catch { }
}

/// <summary>
/// Starts flag configuration delivery and waits for the first configuration, so that a ready
/// provider can actually resolve flags. It returns normally when the wait times out instead of
/// throwing: slow delivery is transient, and initialization commonly runs at startup, where an
/// exception would take the application down.
/// </summary>
/// <param name="context"> Evaluation context </param>
/// <param name="cancellationToken"> Async cancellation token </param>
/// <returns> A task that completes when initialization is complete </returns>
public override Task InitializeAsync(EvaluationContext context, CancellationToken cancellationToken = default)
=> FeatureFlagsSdk.InitializeAsync(cancellationToken);

/// <summary> Gets provider metadata </summary>
/// <returns> Returns provider metadata </returns>
public override Metadata? GetMetadata() => _metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Datadog.Trace.FeatureFlags;
using OpenFeature.Constant;
using OpenFeature.Model;
Expand All @@ -32,6 +34,16 @@ internal static class FeatureFlagsSdk
[MethodImpl(MethodImplOptions.NoInlining)]
internal static bool IsSpanEnrichmentEnabled() => false;

/// <summary>
/// Activates flag configuration delivery and waits for the first configuration to arrive.
/// Delivery only starts here, because requesting configuration is billable and installing the
/// tracer alone must not do it.
/// </summary>
/// <param name="cancellationToken"> Cancellation token supplied by OpenFeature </param>
/// <returns> A task that completes once configuration has arrived, or the initialization timeout has elapsed </returns>
[MethodImpl(MethodImplOptions.NoInlining)]
public static Task InitializeAsync(CancellationToken cancellationToken) => Task.CompletedTask;

/// <summary> Installs an event handler to be fired when a new config has been received </summary>
/// <param name="onNewConfig"> Action to be called when the event is fired </param>
[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// <copyright file="OpenFeatureSdkInitializeAsyncIntegration.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.Threading;
using System.Threading.Tasks;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.Configuration;

namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.ManualInstrumentation.OpenFeature;

/// <summary>
/// System.Threading.Tasks.Task Datadog.FeatureFlags.OpenFeature.FeatureFlagsSdk::InitializeAsync(System.Threading.CancellationToken) calltarget instrumentation
/// </summary>
[InstrumentMethod(
AssemblyName = "Datadog.FeatureFlags.OpenFeature",
TypeName = "Datadog.FeatureFlags.OpenFeature.FeatureFlagsSdk",
MethodName = "InitializeAsync",
ReturnTypeName = ClrNames.Task,
ParameterTypeNames = [ClrNames.CancellationToken],
MinimumVersion = "2.0.0",
MaximumVersion = "2.*.*",
IntegrationName = nameof(IntegrationId.OpenFeature))]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class OpenFeatureSdkInitializeAsyncIntegration
{
internal static CallTargetState OnMethodBegin<TTarget>(ref CancellationToken cancellationToken)
=> new CallTargetState(scope: null, state: cancellationToken);

internal static CallTargetReturn<Task> OnMethodEnd<TTarget>(Task returnValue, Exception? exception, in CallTargetState state)
{
if (exception is not null)
{
return new CallTargetReturn<Task>(returnValue);
}

// Delivery only starts here, because requesting configuration is billable, and the tracer
// must not start until application code adopts the provider.
if (TracerManager.Instance.FeatureFlags is { } featureFlags)
{
var cancellationToken = state.State is CancellationToken token ? token : default;
return new CallTargetReturn<Task>(featureFlags.InitializeAsync(cancellationToken));
}

return new CallTargetReturn<Task>(returnValue);
}
}
16 changes: 11 additions & 5 deletions tracer/src/Datadog.Trace/Configuration/TracerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Datadog.Trace.Configuration.ConfigurationSources.Telemetry;
using Datadog.Trace.Configuration.Telemetry;
using Datadog.Trace.DataStreamsMonitoring.TransactionTracking;
using Datadog.Trace.FeatureFlags;
using Datadog.Trace.Logging;
using Datadog.Trace.Logging.DirectSubmission;
using Datadog.Trace.PlatformHelpers;
Expand Down Expand Up @@ -762,8 +763,13 @@ not null when string.Equals(value, "otlp", StringComparison.OrdinalIgnoreCase) =
DisabledAdoNetCommandTypes.UnionWith(userSplit);
}

IsFlaggingProviderEnabled = config.WithKeys(ConfigurationKeys.FeatureFlags.FlaggingProviderEnabled)
.AsBool(false);
#pragma warning disable 618 // superseded, but still honoured so existing adopters keep their source
var flaggingProviderEnabled = config.WithKeys(ConfigurationKeys.FeatureFlags.FlaggingProviderEnabled).AsBool();
#pragma warning restore 618
var featureFlagsEnabled = config.WithKeys(ConfigurationKeys.FeatureFlags.FeatureFlagsEnabled).AsBool();
var configuredSource = config.WithKeys(ConfigurationKeys.FeatureFlags.FeatureFlagsConfigurationSource).AsString();
Comment thread
pavlokhrebto marked this conversation as resolved.
Outdated

FeatureFlags = new FeatureFlagsSettings(source, telemetry);

IsSpanEnrichmentEnabled = config.WithKeys(ConfigurationKeys.FeatureFlags.SpanEnrichmentEnabled)
.AsBool(false);
Expand Down Expand Up @@ -1491,12 +1497,12 @@ not null when string.Equals(value, "otlp", StringComparison.OrdinalIgnoreCase) =
internal HashSet<string> DisabledAdoNetCommandTypes { get; }

/// <summary>
/// Gets a value indicating whether remote Feature Flags Provider is enabled
/// Gets the Feature Flags configuration, including which delivery source is selected.
/// </summary>
internal bool IsFlaggingProviderEnabled { get; }
internal FeatureFlagsSettings FeatureFlags { get; }

/// <summary>
/// Gets a value indicating whether APM span enrichment is enabled; see <see cref="IsFlaggingProviderEnabled"/>.
/// Gets a value indicating whether APM span enrichment is enabled; see <see cref="FeatureFlags"/>.
/// </summary>
internal bool IsSpanEnrichmentEnabled { get; }

Expand Down
Loading
Loading