Skip to content

Commit

Permalink
use same logic to convert JToken to string
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Jun 18, 2024
1 parent b89c7fc commit 42e857e
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,25 @@ static string FlattenJsonArray(JToken json)
return string.Empty;
}

static string JTokenToString(JToken token)
{
return token switch
{
null => null,
_ => token.Type switch
{
JTokenType.Null or JTokenType.None or JTokenType.Undefined => null,
JTokenType.String => token.Value<string>(),
_ => token.ToString(Formatting.None) // serialize back into json
}
};
}

// json["runtime_metrics_enabled"]?.Value<bool>().Should().Be(expectedConfig.RuntimeMetricsEnabled);
// json["debug"]?.Value<bool>().Should().Be(expectedConfig.DebugLogsEnabled);
json["log_injection_enabled"]?.Value<bool>().Should().Be(expectedConfig.LogInjectionEnabled);
json["sample_rate"]?.Value<double?>().Should().Be(expectedConfig.TraceSampleRate);
json["remote_sampling_rules"]?.ToString(Formatting.None).Should().Be(expectedConfig.TraceSamplingRules);
JTokenToString(json["remote_sampling_rules"]).Should().Be(expectedConfig.TraceSamplingRules);
// json["span_sampling_rules"]?.Value<string>().Should().Be(expectedConfig.SpanSamplingRules);
// json["data_streams_enabled"]?.Value<bool>().Should().Be(expectedConfig.DataStreamsEnabled);
FlattenJsonArray(json["header_tags"]).Should().Be(expectedConfig.TraceHeaderTags ?? string.Empty);
Expand Down Expand Up @@ -255,7 +269,7 @@ private void AssertConfigurationChanged(ConcurrentStack<object> events, Config c
// (ConfigurationKeys.DebugEnabled, config.DebugLogsEnabled),
(ConfigurationKeys.LogsInjectionEnabled, config.LogInjectionEnabled),
(ConfigurationKeys.GlobalSamplingRate, config.TraceSampleRate),
(ConfigurationKeys.CustomSamplingRules, config.TraceSamplingRules == null ? null : JToken.Parse(config.TraceSamplingRules).ToString()),
(ConfigurationKeys.CustomSamplingRules, config.TraceSamplingRules == null ? null : JToken.Parse(config.TraceSamplingRules).ToString(Formatting.None)),
// (ConfigurationKeys.SpanSamplingRules, config.SpanSamplingRules),
// (ConfigurationKeys.DataStreamsMonitoring.Enabled, config.DataStreamsEnabled),
(ConfigurationKeys.HeaderTags, config.TraceHeaderTags == null ? null : JToken.Parse(config.TraceHeaderTags).ToString()),
Expand Down

0 comments on commit 42e857e

Please sign in to comment.