Skip to content

Commit 8f4e72d

Browse files
authored
chore: Update log test scenarios. (#262)
## Summary Extending log tests suite. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds new log sampling scenarios requiring both message and severity, updates .NET test severity fallback to Information, and makes Python tests tolerate missing expected attributes. > > - **Tests**: > - **Log scenarios**: Add cases where rules require both `message` and `severityText` (empty log, message-only, severity-only) in `.../observability-dotnet/.../log-test-scenarios.json` and `.../observability-python/.../log-test-scenarios.json`. > - **.NET test helper**: `SeverityTextToLogLevel` default now returns `Information` instead of throwing for unsupported `severityText` in `CustomSamplerTests.cs`. > - **Python tests**: In `test_custom_sampler.py`, only assert `result.attributes` when `"attributes"` exists in `expected_result` and is non-null for both span and log scenarios. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5e991a0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 087ef08 commit 8f4e72d

File tree

5 files changed

+200
-6
lines changed

5 files changed

+200
-6
lines changed

sdk/@launchdarkly/observability-dotnet/src/LaunchDarkly.Observability/Otel/CommonOtelOptions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
using System.Threading.Tasks;
55
using LaunchDarkly.Observability.Logging;
66
using LaunchDarkly.Observability.Sampling;
7-
using LaunchDarkly.Sdk.Internal.Concurrent;
87
using OpenTelemetry;
98
using OpenTelemetry.Exporter;
10-
using OpenTelemetry.Logs;
119
using OpenTelemetry.Metrics;
1210
using OpenTelemetry.Resources;
1311
using OpenTelemetry.Trace;

sdk/@launchdarkly/observability-dotnet/test/LaunchDarkly.Observability.Tests/CustomSamplerTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ private LogLevel SeverityTextToLogLevel(string severityText)
241241
case null:
242242
return LogLevel.Information;
243243
default:
244-
// Unsupported in this test suite.
245-
throw new ArgumentOutOfRangeException(nameof(severityText), severityText, null);
244+
// Log records cannot be made without a level, but in some languages they can, so we
245+
// use "Information" for a missing level in the test suite.
246+
// We cannot use "None" because the open telemetry logger is hard-coded to discard "None".
247+
return LogLevel.Information;
246248
}
247249
}
248250

sdk/@launchdarkly/observability-dotnet/test/LaunchDarkly.Observability.Tests/log-test-scenarios.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,102 @@
388388
}
389389
}
390390
]
391+
},
392+
{
393+
"description": "Should not match an empty log when message and severity are defined",
394+
"samplingConfig": {
395+
"logs": [
396+
{
397+
"message": {
398+
"regexValue": "Database connection .*"
399+
},
400+
"severityText": {
401+
"matchValue": "error"
402+
},
403+
"samplingRatio": 90
404+
}
405+
]
406+
},
407+
"inputLog": {},
408+
"samplerFunctionCases": [
409+
{
410+
"type": "always",
411+
"expected_result": {
412+
"sample": true
413+
}
414+
},
415+
{
416+
"type": "never",
417+
"expected_result": {
418+
"sample": true
419+
}
420+
}
421+
]
422+
},
423+
{
424+
"description": "Should not match a log with a message when message and severity are defined",
425+
"samplingConfig": {
426+
"logs": [
427+
{
428+
"message": {
429+
"regexValue": "Database connection .*"
430+
},
431+
"severityText": {
432+
"matchValue": "error"
433+
},
434+
"samplingRatio": 90
435+
}
436+
]
437+
},
438+
"inputLog": {
439+
"message": "Database connection failed: timeout"
440+
},
441+
"samplerFunctionCases": [
442+
{
443+
"type": "always",
444+
"expected_result": {
445+
"sample": true
446+
}
447+
},
448+
{
449+
"type": "never",
450+
"expected_result": {
451+
"sample": true
452+
}
453+
}
454+
]
455+
},
456+
{
457+
"description": "Should not match a log with only severity when message and severity are defined",
458+
"samplingConfig": {
459+
"logs": [
460+
{
461+
"message": {
462+
"regexValue": "Database connection .*"
463+
},
464+
"severityText": {
465+
"matchValue": "error"
466+
},
467+
"samplingRatio": 90
468+
}
469+
]
470+
},
471+
"inputLog": {
472+
"severityText": "error"
473+
},
474+
"samplerFunctionCases": [
475+
{
476+
"type": "always",
477+
"expected_result": {
478+
"sample": true
479+
}
480+
},
481+
{
482+
"type": "never",
483+
"expected_result": {
484+
"sample": true
485+
}
486+
}
487+
]
391488
}
392489
]

sdk/@launchdarkly/observability-python/ldobserve/_otel/_sampling/log-test-scenarios.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,102 @@
388388
}
389389
}
390390
]
391+
},
392+
{
393+
"description": "Should not match an empty log when message and severity are defined",
394+
"samplingConfig": {
395+
"logs": [
396+
{
397+
"message": {
398+
"regexValue": "Database connection .*"
399+
},
400+
"severityText": {
401+
"matchValue": "error"
402+
},
403+
"samplingRatio": 90
404+
}
405+
]
406+
},
407+
"inputLog": {},
408+
"samplerFunctionCases": [
409+
{
410+
"type": "always",
411+
"expected_result": {
412+
"sample": true
413+
}
414+
},
415+
{
416+
"type": "never",
417+
"expected_result": {
418+
"sample": true
419+
}
420+
}
421+
]
422+
},
423+
{
424+
"description": "Should not match a log with a message when message and severity are defined",
425+
"samplingConfig": {
426+
"logs": [
427+
{
428+
"message": {
429+
"regexValue": "Database connection .*"
430+
},
431+
"severityText": {
432+
"matchValue": "error"
433+
},
434+
"samplingRatio": 90
435+
}
436+
]
437+
},
438+
"inputLog": {
439+
"message": "Database connection failed: timeout"
440+
},
441+
"samplerFunctionCases": [
442+
{
443+
"type": "always",
444+
"expected_result": {
445+
"sample": true
446+
}
447+
},
448+
{
449+
"type": "never",
450+
"expected_result": {
451+
"sample": true
452+
}
453+
}
454+
]
455+
},
456+
{
457+
"description": "Should not match a log with only severity when message and severity are defined",
458+
"samplingConfig": {
459+
"logs": [
460+
{
461+
"message": {
462+
"regexValue": "Database connection .*"
463+
},
464+
"severityText": {
465+
"matchValue": "error"
466+
},
467+
"samplingRatio": 90
468+
}
469+
]
470+
},
471+
"inputLog": {
472+
"severityText": "error"
473+
},
474+
"samplerFunctionCases": [
475+
{
476+
"type": "always",
477+
"expected_result": {
478+
"sample": true
479+
}
480+
},
481+
{
482+
"type": "never",
483+
"expected_result": {
484+
"sample": true
485+
}
486+
}
487+
]
391488
}
392489
]

sdk/@launchdarkly/observability-python/ldobserve/_otel/_sampling/test_custom_sampler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def run_span_scenarios():
177177
assert sampler.is_sampling_enabled() is True
178178
result = sampler.sample_span(span)
179179
assert result.sample == expected["sample"], desc
180-
if expected["attributes"] is not None:
180+
if "attributes" in expected and expected["attributes"] is not None:
181181
assert result.attributes == expected["attributes"], desc
182182
else:
183183
assert result.attributes is None or result.attributes == {}, desc
@@ -202,7 +202,7 @@ def run_log_scenarios():
202202
assert sampler.is_sampling_enabled() is True
203203
result = sampler.sample_log(log)
204204
assert result.sample == expected["sample"], desc
205-
if expected["attributes"] is not None:
205+
if "attributes" in expected and expected["attributes"] is not None:
206206
assert result.attributes == expected["attributes"], desc
207207
else:
208208
assert result.attributes is None or result.attributes == {}, desc

0 commit comments

Comments
 (0)