Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="EnumExtensionsGenerator.cs" company="Datadog">
// <copyright file="EnumExtensionsGenerator.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>
Expand Down Expand Up @@ -57,6 +57,13 @@ private static void Execute(in EnumToGenerate enumToGenerate, SourceProductionCo
StringBuilder sb = new StringBuilder();
var result = Sources.GenerateExtensionClass(sb, in enumToGenerate);
context.AddSource(enumToGenerate.ExtensionsName + "_EnumExtensions.g.cs", SourceText.From(result, Encoding.UTF8));

// If this is the IntegrationId enum, also generate IntegrationNameToKeys
if (enumToGenerate.FullyQualifiedName == "Datadog.Trace.Configuration.IntegrationId")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels so hacky, but I love it 😂

{
var integrationKeysResult = Sources.GenerateIntegrationNameToKeys(sb, in enumToGenerate);
context.AddSource("IntegrationNameToKeys.g.cs", SourceText.From(integrationKeysResult, Encoding.UTF8));
}
}

private static Result<(EnumToGenerate Enum, bool IsValid)> GetTypeToGenerate(
Expand Down
304 changes: 230 additions & 74 deletions tracer/src/Datadog.Trace.SourceGenerators/EnumExtensions/Sources.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Datadog.Trace.Configuration.ConfigurationSources.Telemetry;

namespace Datadog.Trace.Configuration.Telemetry;
Expand All @@ -19,36 +20,39 @@ internal readonly struct ConfigurationBuilder(IConfigurationSource source, IConf

public HasKeys WithKeys(string key) => new(_source, _telemetry, key);

public HasKeys WithIntegrationKey(string integrationName) => new(
_source,
_telemetry,
string.Format(IntegrationSettings.IntegrationEnabledKey, integrationName.ToUpperInvariant()),
[
string.Format(IntegrationSettings.IntegrationEnabledKey, integrationName),
$"DD_{integrationName}_ENABLED"
]);

public HasKeys WithIntegrationAnalyticsKey(string integrationName) => new(
_source,
_telemetry,
public HasKeys WithIntegrationKey(string integrationName)
{
var integrationEnabledKeys = IntegrationNameToKeys.GetIntegrationEnabledKeys(integrationName);
return new(
_source,
_telemetry,
integrationEnabledKeys.Key,
integrationEnabledKeys.Value);
}

public HasKeys WithIntegrationAnalyticsKey(string integrationName)
{
#pragma warning disable 618 // App analytics is deprecated, but still used
string.Format(IntegrationSettings.AnalyticsEnabledKey, integrationName.ToUpperInvariant()),
[
string.Format(IntegrationSettings.AnalyticsEnabledKey, integrationName),
var integrationAnalyticsEnabledKeys = IntegrationNameToKeys.GetIntegrationAnalyticsEnabledKeys(integrationName);
#pragma warning restore 618
$"DD_{integrationName}_ANALYTICS_ENABLED"
]);
return new(
_source,
_telemetry,
integrationAnalyticsEnabledKeys.Key,
integrationAnalyticsEnabledKeys.Value);
}

public HasKeys WithIntegrationAnalyticsSampleRateKey(string integrationName) => new(
_source,
_telemetry,
public HasKeys WithIntegrationAnalyticsSampleRateKey(string integrationName)
{
#pragma warning disable 618 // App analytics is deprecated, but still used
string.Format(IntegrationSettings.AnalyticsSampleRateKey, integrationName.ToUpperInvariant()),
[
string.Format(IntegrationSettings.AnalyticsSampleRateKey, integrationName),
var integrationAnalyticsSampleRateKeys = IntegrationNameToKeys.GetIntegrationAnalyticsSampleRateKeys(integrationName);
#pragma warning restore 618
$"DD_{integrationName}_ANALYTICS_SAMPLE_RATE"
]);
return new(
_source,
_telemetry,
integrationAnalyticsSampleRateKeys.Key,
integrationAnalyticsSampleRateKeys.Value);
}

internal readonly struct HasKeys(IConfigurationSource source, IConfigurationTelemetry telemetry, string key, string[]? providedAliases = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static IntegrationSettings[] GetIntegrationSettings(IConfigurationSource
{
var integrations = new IntegrationSettings[IntegrationRegistry.Names.Length];

for (int i = 0; i < integrations.Length; i++)
for (var i = 0; i < integrations.Length; i++)
{
var name = IntegrationRegistry.Names[i];

Expand Down
Loading
Loading