Skip to content

Commit

Permalink
add more tests as per comments
Browse files Browse the repository at this point in the history
Signed-off-by: emdneto <[email protected]>
  • Loading branch information
emdneto committed Dec 16, 2024
1 parent f7bcf51 commit 6799afc
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions opentelemetry-instrumentation/tests/test_semconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from opentelemetry.trace.status import StatusCode


def semconv_stability_mode(mode):
def stability_mode(mode):
def decorator(test_case):
@patch.dict(os.environ, {OTEL_SEMCONV_STABILITY_OPT_IN: mode})
def wrapper(*args, **kwargs):
Expand All @@ -40,25 +40,31 @@ def wrapper(*args, **kwargs):


class TestOpenTelemetrySemConvStability(TestCase):
@semconv_stability_mode("")
@stability_mode("")
def test_default_mode(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP
),
_StabilityMode.DEFAULT,
)
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.DATABASE
),
_StabilityMode.DEFAULT,
)

@semconv_stability_mode("http")
def test_http_mode(self):
@stability_mode("http")
def test_http_stable_mode(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP
),
_StabilityMode.HTTP,
)

@semconv_stability_mode("http/dup")
@stability_mode("http/dup")
def test_http_dup_mode(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
Expand All @@ -67,16 +73,16 @@ def test_http_dup_mode(self):
_StabilityMode.HTTP_DUP,
)

@semconv_stability_mode("database")
def test_database_mode(self):
@stability_mode("database")
def test_database_stable_mode(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.DATABASE
),
_StabilityMode.DATABASE,
)

@semconv_stability_mode("database/dup")
@stability_mode("database/dup")
def test_database_dup_mode(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
Expand All @@ -85,22 +91,52 @@ def test_database_dup_mode(self):
_StabilityMode.DATABASE_DUP,
)

@semconv_stability_mode("database,http")
def test_multiple_stability_modes(self):
@stability_mode("database,http")
def test_multiple_stability_database_http_modes(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.DATABASE
),
_StabilityMode.DATABASE,
)
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP
),
_StabilityMode.HTTP,
)

@stability_mode("database,http/dup")
def test_multiple_stability_database_http_dup_modes(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.DATABASE
),
_StabilityMode.DATABASE,
)
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP
),
_StabilityMode.HTTP_DUP,
)

@stability_mode("database/dup,http")
def test_multiple_stability_database_dup_http_stable_modes(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.DATABASE
),
_StabilityMode.DATABASE_DUP,
)
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP
),
_StabilityMode.HTTP,
)

@semconv_stability_mode("database,database/dup,http,http/dup")
@stability_mode("database,database/dup,http,http/dup")
def test_stability_mode_dup_precedence(self):
self.assertEqual(
_OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
Expand Down

0 comments on commit 6799afc

Please sign in to comment.