Skip to content

Commit d7349fe

Browse files
committedFeb 13, 2025
some debug code to build in the CI
1 parent ed0bdfb commit d7349fe

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed
 

‎tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/SchemaExtractor.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
using System.Collections.Generic;
99
using System.Globalization;
1010
using System.IO;
11+
using System.Text;
1112
using Datadog.Trace.Configuration;
1213
using Datadog.Trace.DuckTyping;
14+
using Datadog.Trace.Iast.Aspects.System.Text;
1315
using Datadog.Trace.Logging;
1416
using Datadog.Trace.Util;
1517
using Datadog.Trace.Vendors.Microsoft.OpenApi.Any;
@@ -83,6 +85,7 @@ internal static void EnrichActiveSpanWith(MessageDescriptorProxy? descriptor, st
8385

8486
activeSpan.SetTag(Tags.SchemaDefinition, schema.JsonDefinition);
8587
activeSpan.SetTag(Tags.SchemaId, schema.Hash.ToString(CultureInfo.InvariantCulture));
88+
activeSpan.SetTag("schema.hash_data", schema.HashData);
8689
activeSpan.SetTag(Tags.SchemaWeight, weight.ToString(CultureInfo.InvariantCulture));
8790
}
8891

@@ -107,12 +110,15 @@ private Extractor(IDictionary<string, OpenApiSchema> componentsSchemas)
107110
_schemas = componentsSchemas;
108111
}
109112

113+
public StringBuilder HashData { get; set; } = new();
114+
110115
public static Schema ExtractSchemas(MessageDescriptorProxy descriptor)
111116
{
112117
var components = new OpenApiComponents();
113-
var hash = new Extractor(components.Schemas).FillSchemasWith(descriptor); // fill the component's schemas
118+
var ext = new Extractor(components.Schemas);
119+
var hash = ext.FillSchemasWith(descriptor); // fill the component's schemas
114120
var doc = new OpenApiDocument { Components = components };
115-
return new Schema(doc, hash);
121+
return new Schema(doc, hash, ext.HashData.ToString());
116122
}
117123

118124
/// <summary>
@@ -228,6 +234,8 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
228234
FillSchemasWith(field.MessageType, depth + 1); // Recursively add nested schemas (conditions apply)
229235
reference = new OpenApiReference { Id = field.MessageType.Name, Type = ReferenceType.Schema };
230236
_computedHash = FnvHash64.GenerateHash(reference.Id, FnvHash64.Version.V1A, _computedHash);
237+
HashData.Append("|");
238+
HashData.Append(reference.Id);
231239
break;
232240
case 11:
233241
type = "string";
@@ -256,6 +264,8 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
256264
var enumVal = e.DuckCast<IDescriptorProxy>()!;
257265
enumValues.Add(new OpenApiString(enumVal.Name));
258266
_computedHash = FnvHash64.GenerateHash(enumVal.Name, FnvHash64.Version.V1A, _computedHash);
267+
HashData.Append("|");
268+
HashData.Append(enumVal.Name);
259269
}
260270

261271
break;
@@ -270,6 +280,12 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
270280
_computedHash = FnvHash64.GenerateHash(field.FieldNumber.ToString(CultureInfo.InvariantCulture), FnvHash64.Version.V1A, _computedHash);
271281
_computedHash = FnvHash64.GenerateHash(field.FieldType.ToString(CultureInfo.InvariantCulture), FnvHash64.Version.V1A, _computedHash);
272282
_computedHash = FnvHash64.GenerateHash(depth.ToString(CultureInfo.InvariantCulture), FnvHash64.Version.V1A, _computedHash);
283+
HashData.Append("|");
284+
HashData.Append(field.FieldNumber.ToString(CultureInfo.InvariantCulture));
285+
HashData.Append("|");
286+
HashData.Append(field.FieldType.ToString(CultureInfo.InvariantCulture));
287+
HashData.Append("|");
288+
HashData.Append(depth.ToString(CultureInfo.InvariantCulture));
273289

274290
var property = new OpenApiSchema
275291
{
@@ -297,7 +313,7 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
297313

298314
private class Schema
299315
{
300-
public Schema(OpenApiDocument openApiDoc, ulong hash)
316+
public Schema(OpenApiDocument openApiDoc, ulong hash, string hashData)
301317
{
302318
using var writer = new StringWriter();
303319
try
@@ -313,10 +329,13 @@ public Schema(OpenApiDocument openApiDoc, ulong hash)
313329
}
314330

315331
Hash = hash;
332+
HashData = hashData;
316333
}
317334

318335
internal string JsonDefinition { get; }
319336

320337
internal ulong Hash { get; }
338+
339+
internal string HashData { get; }
321340
}
322341
}

0 commit comments

Comments
 (0)