Skip to content

Commit 3b1131b

Browse files
committed
Source generator for ConfigurationsKeys2 (temporary) to replace ConfigurationsKeys.cs later
1 parent 3b80d29 commit 3b1131b

File tree

80 files changed

+8921
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+8921
-0
lines changed

tracer/src/Datadog.Trace.SourceGenerators/Configuration/ConfigurationKeysGenerator.cs

Lines changed: 556 additions & 0 deletions
Large diffs are not rendered by default.

tracer/src/Datadog.Trace.SourceGenerators/Helpers/TrackingNames.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,17 @@ internal class TrackingNames
3131
public const string AssemblyCallTargetDefinitionSource = nameof(AssemblyCallTargetDefinitionSource);
3232
public const string AdoNetCallTargetDefinitionSource = nameof(AdoNetCallTargetDefinitionSource);
3333
public const string AdoNetSignatures = nameof(AdoNetSignatures);
34+
35+
// Configuration key matcher
36+
public const string ConfigurationKeysParseConfiguration = nameof(ConfigurationKeysParseConfiguration);
37+
public const string ConfigurationKeyMatcherDiagnostics = nameof(ConfigurationKeyMatcherDiagnostics);
38+
public const string ConfigurationKeyMatcherValidData = nameof(ConfigurationKeyMatcherValidData);
39+
public const string ConfigurationKeysAdditionalText = nameof(ConfigurationKeysAdditionalText);
40+
41+
// Configuration key generator
42+
public const string ConfigurationKeysGenParseConfiguration = nameof(ConfigurationKeysGenParseConfiguration);
43+
public const string ConfigurationKeysGenContentExtracted = nameof(ConfigurationKeysGenContentExtracted);
44+
public const string ConfigurationKeysGenMatcherValidData = nameof(ConfigurationKeysGenMatcherValidData);
45+
public const string ConfigurationKeysGenAdditionalText = nameof(ConfigurationKeysGenAdditionalText);
46+
public const string ConfigurationKeysGenYamlAdditionalText = nameof(ConfigurationKeysGenYamlAdditionalText);
3447
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// <copyright file="YamlReader.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Datadog.Trace.SourceGenerators.Helpers
10+
{
11+
/// <summary>
12+
/// Simple YAML parser for reading documentation strings from YAML files.
13+
/// Supports basic YAML features needed for configuration documentation.
14+
/// </summary>
15+
internal static class YamlReader
16+
{
17+
/// <summary>
18+
/// Parses a YAML file containing configuration key documentation.
19+
/// Expects format: KEY: | followed by multi-line documentation
20+
/// </summary>
21+
public static Dictionary<string, string> ParseDocumentation(string yamlContent)
22+
{
23+
var result = new Dictionary<string, string>();
24+
var lines = yamlContent.Replace("\r\n", "\n").Split('\n');
25+
26+
string? currentKey = null;
27+
var currentDoc = new StringBuilder();
28+
var inMultiLine = false;
29+
var baseIndent = 0;
30+
31+
for (int i = 0; i < lines.Length; i++)
32+
{
33+
var line = lines[i];
34+
35+
// Skip empty lines and comments when not in multi-line
36+
if (!inMultiLine && (string.IsNullOrWhiteSpace(line) || line.TrimStart().StartsWith("#")))
37+
{
38+
continue;
39+
}
40+
41+
// Check for new key (starts at column 0, contains colon)
42+
if (!inMultiLine && line.Length > 0 && line[0] != ' ' && line.Contains(":"))
43+
{
44+
// Save previous key if exists
45+
if (currentKey != null)
46+
{
47+
result[currentKey] = currentDoc.ToString().TrimEnd();
48+
currentDoc.Clear();
49+
}
50+
51+
var colonIndex = line.IndexOf(':');
52+
currentKey = line.Substring(0, colonIndex).Trim();
53+
54+
// Check if it's a multi-line string (|)
55+
var afterColon = line.Substring(colonIndex + 1).Trim();
56+
if (afterColon == "|" || afterColon == ">")
57+
{
58+
inMultiLine = true;
59+
baseIndent = -1; // Will be set on first content line
60+
}
61+
else if (!string.IsNullOrEmpty(afterColon))
62+
{
63+
// Single line value
64+
currentDoc.Append(afterColon);
65+
result[currentKey] = currentDoc.ToString();
66+
currentDoc.Clear();
67+
currentKey = null;
68+
}
69+
70+
continue;
71+
}
72+
73+
// Handle multi-line content
74+
if (inMultiLine && currentKey != null)
75+
{
76+
// Check if we've reached the next key (no indentation)
77+
if (line.Length > 0 && line[0] != ' ' && line.Contains(":"))
78+
{
79+
// Save current key and process this line as new key
80+
result[currentKey] = currentDoc.ToString().TrimEnd();
81+
currentDoc.Clear();
82+
inMultiLine = false;
83+
84+
var colonIndex = line.IndexOf(':');
85+
currentKey = line.Substring(0, colonIndex).Trim();
86+
var afterColon = line.Substring(colonIndex + 1).Trim();
87+
if (afterColon == "|" || afterColon == ">")
88+
{
89+
inMultiLine = true;
90+
baseIndent = -1;
91+
}
92+
93+
continue;
94+
}
95+
96+
// Determine base indentation from first content line
97+
if (baseIndent == -1 && line.Length > 0 && line[0] == ' ')
98+
{
99+
baseIndent = 0;
100+
while (baseIndent < line.Length && line[baseIndent] == ' ')
101+
{
102+
baseIndent++;
103+
}
104+
}
105+
106+
// Add content line (remove base indentation)
107+
if (line.Length > 0)
108+
{
109+
var contentStart = 0;
110+
while (contentStart < line.Length && contentStart < baseIndent && line[contentStart] == ' ')
111+
{
112+
contentStart++;
113+
}
114+
115+
if (currentDoc.Length > 0)
116+
{
117+
currentDoc.AppendLine();
118+
}
119+
120+
currentDoc.Append(line.Substring(contentStart));
121+
}
122+
else
123+
{
124+
// Empty line in multi-line content
125+
if (currentDoc.Length > 0)
126+
{
127+
currentDoc.AppendLine();
128+
}
129+
}
130+
}
131+
}
132+
133+
// Save last key
134+
if (currentKey != null)
135+
{
136+
result[currentKey] = currentDoc.ToString().TrimEnd();
137+
}
138+
139+
return result;
140+
}
141+
}
142+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// <copyright company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
// <auto-generated/>
6+
7+
#nullable enable
8+
9+
// This file is auto-generated from supported-configurations.json and supported-configurations-docs.yaml
10+
// Do not edit this file directly. The source generator will regenerate it on build.
11+
// NOTE: If you remove keys/products from the JSON, run 'dotnet clean' to remove old generated files.
12+
13+
namespace Datadog.Trace.Configuration;
14+
15+
internal static partial class ConfigurationKeys2
16+
{
17+
internal static class AppSec
18+
{
19+
public const string ApiSecurityEnabled = "DD_API_SECURITY_ENABLED";
20+
public const string ApiSecurityEndpointCollectionEnabled = "DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED";
21+
public const string ApiSecurityEndpointCollectionMessageLimit = "DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT";
22+
public const string ApiSecurityParseResponseBody = "DD_API_SECURITY_PARSE_RESPONSE_BODY";
23+
public const string ApiSecuritySampleDelay = "DD_API_SECURITY_SAMPLE_DELAY";
24+
public const string AutoUserInstrumentationMode = "DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE";
25+
public const string AutomatedUserEventsTracking = "DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING";
26+
27+
/// <summary>
28+
/// Configuration key for enabling or disabling the AppSec.
29+
/// Default is value is false (disabled).
30+
/// </summary>
31+
public const string Enabled = "DD_APPSEC_ENABLED";
32+
33+
/// <summary>
34+
/// Comma separated keys indicating the optional custom headers the user wants to send.
35+
/// Default is value is null.
36+
/// </summary>
37+
public const string ExtraHeaders = "DD_APPSEC_EXTRA_HEADERS";
38+
public const string HttpBlockedTemplateHtml = "DD_APPSEC_HTTP_BLOCKED_TEMPLATE_HTML";
39+
public const string HttpBlockedTemplateJson = "DD_APPSEC_HTTP_BLOCKED_TEMPLATE_JSON";
40+
41+
/// <summary>
42+
/// Configuration key indicating the optional name of the custom header to take into account for the ip address.
43+
/// Default is value is null (do not override).
44+
/// </summary>
45+
public const string Ipheader = "DD_APPSEC_IPHEADER";
46+
public const string KeepTraces = "DD_APPSEC_KEEP_TRACES";
47+
public const string MaxStackTraceDepth = "DD_APPSEC_MAX_STACK_TRACE_DEPTH";
48+
public const string MaxStackTraceDepthTopPercent = "DD_APPSEC_MAX_STACK_TRACE_DEPTH_TOP_PERCENT";
49+
public const string MaxStackTraces = "DD_APPSEC_MAX_STACK_TRACES";
50+
public const string ObfuscationParameterKeyRegexp = "DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP";
51+
public const string ObfuscationParameterValueRegexp = "DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP";
52+
public const string RaspEnabled = "DD_APPSEC_RASP_ENABLED";
53+
54+
/// <summary>
55+
/// Override the default rules file provided. Must be a path to a valid JSON rules file.
56+
/// Default is value is null (do not override).
57+
/// </summary>
58+
public const string Rules = "DD_APPSEC_RULES";
59+
public const string ScaEnabled = "DD_APPSEC_SCA_ENABLED";
60+
public const string StackTraceEnabled = "DD_APPSEC_STACK_TRACE_ENABLED";
61+
public const string TraceRateLimit = "DD_APPSEC_TRACE_RATE_LIMIT";
62+
public const string WafDebug = "DD_APPSEC_WAF_DEBUG";
63+
public const string WafTimeout = "DD_APPSEC_WAF_TIMEOUT";
64+
public const string ExperimentalAppsecUseUnsafeEncoder = "DD_EXPERIMENTAL_APPSEC_USE_UNSAFE_ENCODER";
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// <copyright company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
// <auto-generated/>
6+
7+
#nullable enable
8+
9+
// This file is auto-generated from supported-configurations.json and supported-configurations-docs.yaml
10+
// Do not edit this file directly. The source generator will regenerate it on build.
11+
// NOTE: If you remove keys/products from the JSON, run 'dotnet clean' to remove old generated files.
12+
13+
namespace Datadog.Trace.Configuration;
14+
15+
internal static partial class ConfigurationKeys2
16+
{
17+
internal static class AzureAppService
18+
{
19+
public const string AasDotnetExtensionVersion = "DD_AAS_DOTNET_EXTENSION_VERSION";
20+
21+
/// <summary>
22+
/// Used to force the loader to start dogstatsd (in case automatic instrumentation is disabled)
23+
/// </summary>
24+
public const string AasEnableCustomMetrics = "DD_AAS_ENABLE_CUSTOM_METRICS";
25+
26+
/// <summary>
27+
/// Used to force the loader to start the trace agent (in case automatic instrumentation is disabled)
28+
/// </summary>
29+
public const string AasEnableCustomTracing = "DD_AAS_ENABLE_CUSTOM_TRACING";
30+
public const string s = "DD_AZURE_APP_SERVICES";
31+
}
32+
}

0 commit comments

Comments
 (0)