{"id":19329734,"url":"https://github.com/outerbounds/metaflow-measure","last_synced_at":"2026-06-12T06:32:00.591Z","repository":{"id":239528199,"uuid":"799778425","full_name":"outerbounds/metaflow-measure","owner":"outerbounds","description":"Measure metrics in Metaflow and send them to Datadog and other backends","archived":false,"fork":false,"pushed_at":"2024-05-21T22:35:02.000Z","size":44,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-24T06:46:39.487Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/outerbounds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-13T04:48:16.000Z","updated_at":"2025-02-14T17:47:40.000Z","dependencies_parsed_at":"2024-05-21T23:35:17.972Z","dependency_job_id":"364f375b-8607-4cfd-9523-9f646eec07d4","html_url":"https://github.com/outerbounds/metaflow-measure","commit_stats":null,"previous_names":["outerbounds/metaflow-measure"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/outerbounds/metaflow-measure","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fmetaflow-measure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fmetaflow-measure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fmetaflow-measure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fmetaflow-measure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/outerbounds","download_url":"https://codeload.github.com/outerbounds/metaflow-measure/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fmetaflow-measure/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34232790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T02:29:43.788Z","updated_at":"2026-06-12T06:32:00.577Z","avatar_url":"https://github.com/outerbounds.png","language":"Python","funding_links":[],"categories":["Observability \u0026 Monitoring"],"sub_categories":[],"readme":"\n# Metrics and Measurements in Metaflow steps\n\nThis extension introduces a `measure` API that allows you to send custom\nmetrics and measure execution times in your Metaflow steps.\n\n## Key features\n\n - Very simple instrumentation API: Measure your code with a few\n   lines of Python.\n\n - Separation between the instrumentation API and the metrics\n   backends: Instrument your code with the `measure` API,\n   record metrics locally during development, and enable a\n   production backend like Datadog during deployment-time.\n\n - Works locally and on `@kubernetes` and `@batch` with no\n   changes in the code.\n\n - Native integration with Metaflow: Metrics are tagged\n   with Metaflow run ID, step names, `@project` branches\n   etc. so you can drill into details.\n\n - Works at scale: Uses aggregators like `dogstatsd` to\n   avoid overloading backend APIs.\n\n - No extra dependencies: `@datadog` installs the\n   `dogstatsd` on the fly, so it works in any execution\n   environment.\n\n## Installation\n\nIn your development environment, install\n```\npip install metaflow-measure\n```\nNote that you don't need to make the package available in\ncontainer images you use to execute tasks remotely. Metaflow\npackages the extension automatically for remote execution.\n\n## API\n\nThe `measure` module exposes [`statsd`-style measurement\nfunctions](https://docs.datadoghq.com/metrics/custom_metrics/dogstatsd_metrics_submission/):\n`gauge`, `increment`, and `decrement`.\n\nOptionally, all `measure` functions take a keyword argument\n`tags` which takes a list of custom tags (strings) to be\nassociated with the measurement.\n\n### Basic Metrics\n\n```python\nfrom metaflow.plugins import measure\n\n# record a gauge metric\nmeasure.gauge('mymetric', value)\n\n# increment a metric\nmeasure.increment('mymetric', value)\n\n# decrement a metric\nmeasure.decrement('mymetric', value)\n```\n\n### Distributions\n\nIn addition, `measure` provides `distribution` which allows\nyou to measure distributions of values (e.g. p50, p95 etc) relying\non server-side aggregation for accuracy.\n\n```python\nfrom metaflow.plugins import measure\n\n# record a distribution metric\nmeasure.distribution('mydistribution', value)\n\n```\n\nFor convenience, the API provides a context manager that\nallows you to measure the execution time of a code block easily.\n\n```python\nfrom metaflow.plugins import measure\n\nwith measure.TimeDistribution('mytiming'):\n   some_time_consuming_function()\n```\n\n# Supported Backends\n\nCurrently, the following backends are supported\n\n## `@datadog`\n\nAdd `@datadog` in your steps to send measurements to Datadog.\nTypically, you would instrument your code with `measure` and\nthen enable Datadog on the fly with\n\n```\npython measureflow.py run --with datadog:api_key=$API_KEY\n```\n\n### Authentication\n\nYou can provide the `api_key` in the decorator\n```\n@datadog(api_key=MY_KEY)\n```\nor on the command line\n```\n--with datadog:api_key=$API_KEY\n```\nor set the environment variable `DD_API_KEY` via `@secrets` or\n`@environment`.\n\n### Tags\n\nThe `@datadog` decorator adds various Metaflow-related tags\nto all metrics, prefixed with `metaflow_`. You can disable\nthis with\n```\n@datadog(include_metaflow_tags=False)\n```\nand/or set custom tags to be associated with all measurements as\n```\n@datadog(tags=['mytag'])\n```\n\n### Debugging\n\nTo debug connectivity issues in Datadog, set\n```\n@datadog(verbose=True, debug_daemon=True)\n```\n\n## Example\n\nRun the following flow to see the extension in action.\n\n```python\nimport os, time\n\nfrom metaflow import FlowSpec, step, datadog\nfrom metaflow.plugins import measure\n\nclass MeasureFlow(FlowSpec):\n\n    @datadog\n    @step\n    def start(self):\n        for i in range(10):\n            measure.increment('mftest.test_metric')\n            time.sleep(1)\n        with measure.TimeDistribution('mftest.slow_operation', tags=['custom_tag']):\n            time.sleep(10)\n        self.next(self.end)\n\n    @step\n    def end(self):\n        # this metric is not sent anywhere by default,\n        # unless you add @datadog or another backend\n        measure.gauge('mftest.my_gauge', 42)\n\nif __name__ == '__main__':\n    MeasureFlow()\n```\n\nIf you run this flow as\n```\nexport DD_API_KEY=my_datadog_key\npython measureflow.py run\n```\nonly the measurements from the `start` step will be sent to Datadog,\nthanks to the `@datadog` decorator. The `end` step executes with `measure`\ncalls, but they are not sent anywhere as no backend has been configured\nfor the step.\n\nTo test sending all metrics to Datadog, add `@datadog` to the `end` step\nor run the flow as\n```\npython measureflow.py run --with datadog\n```\n\nTest the code in the cloud\n```\npython measureflow.py run --with kubernetes --with datadog:api_key=$DD_API_KEY\n```\n(or `--with batch`)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fouterbounds%2Fmetaflow-measure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fouterbounds%2Fmetaflow-measure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fouterbounds%2Fmetaflow-measure/lists"}