Skip to content

Commit

Permalink
some debug code to build in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vandonr committed Feb 13, 2025
1 parent ed0bdfb commit d7349fe
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using Datadog.Trace.Configuration;
using Datadog.Trace.DuckTyping;
using Datadog.Trace.Iast.Aspects.System.Text;
using Datadog.Trace.Logging;
using Datadog.Trace.Util;
using Datadog.Trace.Vendors.Microsoft.OpenApi.Any;
Expand Down Expand Up @@ -83,6 +85,7 @@ internal static void EnrichActiveSpanWith(MessageDescriptorProxy? descriptor, st

activeSpan.SetTag(Tags.SchemaDefinition, schema.JsonDefinition);
activeSpan.SetTag(Tags.SchemaId, schema.Hash.ToString(CultureInfo.InvariantCulture));
activeSpan.SetTag("schema.hash_data", schema.HashData);
activeSpan.SetTag(Tags.SchemaWeight, weight.ToString(CultureInfo.InvariantCulture));
}

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

public StringBuilder HashData { get; set; } = new();

public static Schema ExtractSchemas(MessageDescriptorProxy descriptor)
{
var components = new OpenApiComponents();
var hash = new Extractor(components.Schemas).FillSchemasWith(descriptor); // fill the component's schemas
var ext = new Extractor(components.Schemas);
var hash = ext.FillSchemasWith(descriptor); // fill the component's schemas
var doc = new OpenApiDocument { Components = components };
return new Schema(doc, hash);
return new Schema(doc, hash, ext.HashData.ToString());
}

/// <summary>
Expand Down Expand Up @@ -228,6 +234,8 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
FillSchemasWith(field.MessageType, depth + 1); // Recursively add nested schemas (conditions apply)
reference = new OpenApiReference { Id = field.MessageType.Name, Type = ReferenceType.Schema };
_computedHash = FnvHash64.GenerateHash(reference.Id, FnvHash64.Version.V1A, _computedHash);
HashData.Append("|");
HashData.Append(reference.Id);
break;
case 11:
type = "string";
Expand Down Expand Up @@ -256,6 +264,8 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
var enumVal = e.DuckCast<IDescriptorProxy>()!;
enumValues.Add(new OpenApiString(enumVal.Name));
_computedHash = FnvHash64.GenerateHash(enumVal.Name, FnvHash64.Version.V1A, _computedHash);
HashData.Append("|");
HashData.Append(enumVal.Name);
}

break;
Expand All @@ -270,6 +280,12 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d
_computedHash = FnvHash64.GenerateHash(field.FieldNumber.ToString(CultureInfo.InvariantCulture), FnvHash64.Version.V1A, _computedHash);
_computedHash = FnvHash64.GenerateHash(field.FieldType.ToString(CultureInfo.InvariantCulture), FnvHash64.Version.V1A, _computedHash);
_computedHash = FnvHash64.GenerateHash(depth.ToString(CultureInfo.InvariantCulture), FnvHash64.Version.V1A, _computedHash);
HashData.Append("|");
HashData.Append(field.FieldNumber.ToString(CultureInfo.InvariantCulture));
HashData.Append("|");
HashData.Append(field.FieldType.ToString(CultureInfo.InvariantCulture));
HashData.Append("|");
HashData.Append(depth.ToString(CultureInfo.InvariantCulture));

var property = new OpenApiSchema
{
Expand Down Expand Up @@ -297,7 +313,7 @@ private Dictionary<string, OpenApiSchema> ExtractFields(MessageDescriptorProxy d

private class Schema
{
public Schema(OpenApiDocument openApiDoc, ulong hash)
public Schema(OpenApiDocument openApiDoc, ulong hash, string hashData)
{
using var writer = new StringWriter();
try
Expand All @@ -313,10 +329,13 @@ public Schema(OpenApiDocument openApiDoc, ulong hash)
}

Hash = hash;
HashData = hashData;
}

internal string JsonDefinition { get; }

internal ulong Hash { get; }

internal string HashData { get; }
}
}

0 comments on commit d7349fe

Please sign in to comment.