Skip to content
Merged
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
Expand Up @@ -4,10 +4,8 @@
using System.Threading.Tasks;
using LaunchDarkly.Observability.Logging;
using LaunchDarkly.Observability.Sampling;
using LaunchDarkly.Sdk.Internal.Concurrent;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ private LogLevel SeverityTextToLogLevel(string severityText)
case null:
return LogLevel.Information;
default:
// Unsupported in this test suite.
throw new ArgumentOutOfRangeException(nameof(severityText), severityText, null);
// Log records cannot be made without a level, but in some languages they can, so we
// use "Information" for a missing level in the test suite.
// We cannot use "None" because the open telemetry logger is hard-coded to discard "None".
return LogLevel.Information;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,102 @@
}
}
]
},
{
"description": "Should not match an empty log when message and severity are defined",
"samplingConfig": {
"logs": [
{
"message": {
"regexValue": "Database connection .*"
},
"severityText": {
"matchValue": "error"
},
"samplingRatio": 90
}
]
},
"inputLog": {},
"samplerFunctionCases": [
{
"type": "always",
"expected_result": {
"sample": true
}
},
{
"type": "never",
"expected_result": {
"sample": true
}
}
]
},
{
"description": "Should not match a log with a message when message and severity are defined",
"samplingConfig": {
"logs": [
{
"message": {
"regexValue": "Database connection .*"
},
"severityText": {
"matchValue": "error"
},
"samplingRatio": 90
}
]
},
"inputLog": {
"message": "Database connection failed: timeout"
},
"samplerFunctionCases": [
{
"type": "always",
"expected_result": {
"sample": true
}
},
{
"type": "never",
"expected_result": {
"sample": true
}
}
]
},
{
"description": "Should not match a log with only severity when message and severity are defined",
"samplingConfig": {
"logs": [
{
"message": {
"regexValue": "Database connection .*"
},
"severityText": {
"matchValue": "error"
},
"samplingRatio": 90
}
]
},
"inputLog": {
"severityText": "error"
},
"samplerFunctionCases": [
{
"type": "always",
"expected_result": {
"sample": true
}
},
{
"type": "never",
"expected_result": {
"sample": true
}
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,102 @@
}
}
]
},
{
"description": "Should not match an empty log when message and severity are defined",
"samplingConfig": {
"logs": [
{
"message": {
"regexValue": "Database connection .*"
},
"severityText": {
"matchValue": "error"
},
"samplingRatio": 90
}
]
},
"inputLog": {},
"samplerFunctionCases": [
{
"type": "always",
"expected_result": {
"sample": true
}
},
{
"type": "never",
"expected_result": {
"sample": true
}
}
]
},
{
"description": "Should not match a log with a message when message and severity are defined",
"samplingConfig": {
"logs": [
{
"message": {
"regexValue": "Database connection .*"
},
"severityText": {
"matchValue": "error"
},
"samplingRatio": 90
}
]
},
"inputLog": {
"message": "Database connection failed: timeout"
},
"samplerFunctionCases": [
{
"type": "always",
"expected_result": {
"sample": true
}
},
{
"type": "never",
"expected_result": {
"sample": true
}
}
]
},
{
"description": "Should not match a log with only severity when message and severity are defined",
"samplingConfig": {
"logs": [
{
"message": {
"regexValue": "Database connection .*"
},
"severityText": {
"matchValue": "error"
},
"samplingRatio": 90
}
]
},
"inputLog": {
"severityText": "error"
},
"samplerFunctionCases": [
{
"type": "always",
"expected_result": {
"sample": true
}
},
{
"type": "never",
"expected_result": {
"sample": true
}
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run_span_scenarios():
assert sampler.is_sampling_enabled() is True
result = sampler.sample_span(span)
assert result.sample == expected["sample"], desc
if expected["attributes"] is not None:
if "attributes" in expected and expected["attributes"] is not None:
assert result.attributes == expected["attributes"], desc
else:
assert result.attributes is None or result.attributes == {}, desc
Expand All @@ -202,7 +202,7 @@ def run_log_scenarios():
assert sampler.is_sampling_enabled() is True
result = sampler.sample_log(log)
assert result.sample == expected["sample"], desc
if expected["attributes"] is not None:
if "attributes" in expected and expected["attributes"] is not None:
assert result.attributes == expected["attributes"], desc
else:
assert result.attributes is None or result.attributes == {}, desc
Expand Down
Loading