Skip to content

Fix #2771: Add backward compatibility for misspelled telemetry import #2772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions src/crewai/telemtry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Backward compatibility module for crewai.telemtry to handle typo in import statements.

This module allows older code that imports from `crewai.telemtry` (misspelled)
to continue working by re-exporting the Telemetry class from the correctly
spelled `crewai.telemetry` module.
"""
import warnings

from crewai.telemetry import Telemetry

warnings.warn(
"Importing from 'crewai.telemtry' is deprecated due to spelling issues. "
"Please use 'from crewai.telemetry import Telemetry' instead.",
DeprecationWarning,
stacklevel=2
)

__all__ = ["Telemetry"]
49 changes: 49 additions & 0 deletions tests/backward_compatibility_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sys
import unittest
import warnings


class BackwardCompatibilityTest(unittest.TestCase):
def setUp(self):
if "crewai.telemtry" in sys.modules:
del sys.modules["crewai.telemtry"]
warnings.resetwarnings()

def test_deprecation_warning(self):
"""Test that importing from the misspelled module raises a deprecation warning."""
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DeprecationWarning)

import importlib

import crewai.telemtry
importlib.reload(crewai.telemtry)

self.assertGreaterEqual(len(w), 1)
warning_messages = [str(warning.message) for warning in w]
warning_categories = [warning.category for warning in w]

has_deprecation_warning = False
for msg, cat in zip(warning_messages, warning_categories):
if (issubclass(cat, DeprecationWarning) and
"crewai.telemtry" in msg and
"crewai.telemetry" in msg):
has_deprecation_warning = True
break

self.assertTrue(has_deprecation_warning,
f"No matching deprecation warning found. Warnings: {warning_messages}")

def test_telemtry_typo_compatibility(self):
"""Test that the backward compatibility for the telemtry typo works."""
from crewai.telemetry import Telemetry
from crewai.telemtry import Telemetry as MisspelledTelemetry

self.assertIs(MisspelledTelemetry, Telemetry)

def test_functionality_preservation(self):
"""Test that the re-exported Telemetry class preserves all functionality."""
from crewai.telemetry import Telemetry
from crewai.telemtry import Telemetry as MisspelledTelemetry

self.assertEqual(dir(MisspelledTelemetry), dir(Telemetry))
Loading