{"id":21388,"library":"glean-sdk","title":"Glean SDK","description":"Glean is a modern telemetry system by Mozilla for collecting, storing, and sending application metrics and pings. It provides a type-safe, cross-platform SDK with a metric API, automatic batching, and built-in pings. Current version is 67.2.0, with a regular release cadence aligned with Mozilla's release cycle.","status":"active","version":"67.2.0","language":"python","source_language":"en","source_url":"https://github.com/mozilla/glean","tags":["telemetry","metrics","mozilla","glean"],"install":[{"cmd":"pip install glean-sdk","lang":"bash","label":"install"}],"dependencies":[{"reason":"Required for datetime parsing","package":"python-dateutil","optional":false}],"imports":[{"note":"Import directly from 'glean' for the main API","wrong":"from glean_sdk import Glean","symbol":"Glean","correct":"from glean import Glean"},{"wrong":"from glean.metrics import MetricsPing","symbol":"MetricsPing","correct":"from glean import MetricsPing"},{"wrong":null,"symbol":"BooleanMetricType","correct":"from glean.metrics import BooleanMetricType"}],"quickstart":{"code":"import os\nimport glean\nfrom glean import Glean, Configuration, MetricsPing\nfrom glean.metrics import BooleanMetricType\n\n# Initialize Glean with a custom server endpoint\nserver_endpoint = os.environ.get('GLEAN_SERVER_ENDPOINT', 'https://example.com')\napp_id = 'my-app'\nGlean.initialize(\n    application_id=app_id,\n    application_version='1.0.0',\n    upload_enabled=True,\n    configuration=Configuration(\n        server_endpoint=server_endpoint\n    )\n)\n# Define a boolean metric\nmy_metric = BooleanMetricType(1, 'test.bool')\nprint('Glean initialized successfully')","lang":"python","description":"Minimal example initializing Glean with a configurable server endpoint and a boolean metric."},"warnings":[{"fix":"Replace all `from glean_sdk import ...` with `from glean import ...`.","message":"Starting from version 50.0.0, the import path changed from `glean_sdk` to `glean`. Old code using `import glean_sdk` will break. Update imports to `from glean import ...`.","severity":"breaking","affected_versions":">=50.0.0"},{"fix":"Remove MetricsPing usage; pings are now scheduled automatically. Use `Glean.initialize(...)` without explicitly scheduling pings.","message":"The `MetricsPing` class was removed in version 60.0.0 in favor of automatic ping scheduling. Code importing `MetricsPing` will break.","severity":"breaking","affected_versions":">=60.0.0"},{"fix":"Pass `data_dir` inside `Configuration` object.","message":"The `Glean.initialize()` parameter `data_dir` is deprecated since version 55.0.0. Use `Configuration.data_dir` instead.","severity":"deprecated","affected_versions":">=55.0.0"},{"fix":"Initialize Glean at application startup, guarded by a flag or on first launch.","message":"Glean must be initialized only once. Calling `Glean.initialize()` multiple times raises an error or does nothing silently. Ensure initialization happens early and only once.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure metric strings follow the '[a-z][a-z0-9-]{0,}[.][a-z][a-z0-9-]{0,}' pattern.","message":"Metric identifiers must be kebab-case (e.g., 'category.name'). Using underscores or invalid characters will cause errors during metric registration.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'from glean import ...' instead of 'from glean_sdk import ...'.","cause":"Old import path using glean_sdk instead of glean.","error":"glean_sdk is not defined"},{"fix":"Guard initialization with a flag or ensure single call at startup.","cause":"Calling Glean.initialize() more than once in the same process.","error":"Glean has already been initialized"},{"fix":"Use valid identifier format like 'test.bool'.","cause":"Metric identifier must be in kebab-case (e.g., 'my.metric').","error":"Invalid metric identifier: 'my_metric'"},{"fix":"Remove MetricsPing; ping scheduling is automatic.","cause":"MetricsPing was removed in version 60+.","error":"ImportError: cannot import name 'MetricsPing' from 'glean'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}