dbt Integration
Deep dive into connecting your dbt semantic layer to Metricly. Learn about MetricFlow, manifest generation, and CI/CD automation.
Metricly uses the same MetricFlow engine that powers dbt Cloud's Semantic Layer. This means you get enterprise-grade metric consistency without the enterprise price tag. This guide covers everything you need to know about the integration.
Understanding MetricFlow
MetricFlow is dbt Labs' open-source metric layer that sits between your dbt models and your BI tools. It provides:
Consistent Metrics
Define metrics once, use them everywhere. No more conflicting definitions across tools.
Optimized SQL
MetricFlow generates efficient SQL with proper joins, aggregations, and filters.
Version Controlled
Metric definitions live in your dbt project and follow your Git workflow.
Query-Time Access
Data is queried directly from your warehouse. Nothing is stored or cached externally.
Semantic Models & Metrics
The semantic layer is built from semantic models and metrics defined in your dbt project. Here is an example structure:
Semantic Model Example
12345678910111213141516171819202122232425262728293031# models/semantic/orders.ymlsemantic_models: - name: orders description: "Order transactions" model: ref('fct_orders') defaults: agg_time_dimension: order_date entities: - name: order_id type: primary - name: customer_id type: foreign dimensions: - name: order_date type: time type_params: time_granularity: day - name: order_status type: categorical - name: country type: categorical measures: - name: order_total agg: sum expr: order_amount - name: order_count agg: count expr: order_idMetric Definition Example
123456789101112131415161718# models/semantic/metrics.ymlmetrics: - name: revenue description: "Total revenue from orders" type: simple type_params: measure: order_total filter: | {{ Dimension('order_status') }} = 'completed' - name: average_order_value description: "Average value per order" type: derived type_params: expr: revenue / order_count metrics: - revenue - order_count- Use descriptive names that business users will understand
- Add descriptions to all metrics and dimensions
- Define a default time dimension for time-series analysis
- Use filters to exclude invalid or test data
Generating the Semantic Manifest
The semantic manifest is a JSON file that contains all your metrics, dimensions, and entities. Metricly uses this file to understand your semantic layer.
Install dbt-metricflow
# Install the MetricFlow CLI
pip install dbt-metricflow
# Or with your dbt adapter
pip install dbt-metricflow[bigquery]
pip install dbt-metricflow[snowflake]
pip install dbt-metricflow[databricks]Generate the manifest
# Navigate to your dbt project
cd your-dbt-project
# Parse the project and generate the manifest
dbt parse
# The semantic manifest is created at:
# target/semantic_manifest.jsonValidate your metrics (optional)
# Test a metric query locally
mf query --metrics revenue --dimensions order_date__month
# List all available metrics
mf list metrics
# List all available dimensions
mf list dimensionsWarehouse Configuration
Metricly needs read access to your data warehouse to execute MetricFlow queries. Here are example configurations for supported warehouses:
BigQuery
# BigQuery connection settings
project_id: your-gcp-project
dataset: your_dataset
keyfile: /path/to/service-account.json
# Or use GOOGLE_APPLICATION_CREDENTIALS env varSnowflake
# Snowflake connection settings
account: your-account.region
user: your_user
password: ${SNOWFLAKE_PASSWORD}
database: YOUR_DATABASE
warehouse: YOUR_WAREHOUSE
schema: YOUR_SCHEMADatabricks
# Databricks connection settings
host: your-workspace.cloud.databricks.com
http_path: /sql/1.0/warehouses/abc123
token: ${DATABRICKS_TOKEN}
catalog: your_catalog
schema: your_schema- Create a dedicated service account for Metricly
- Grant only SELECT permissions on required schemas
- Use environment variables for sensitive credentials
- Rotate credentials regularly
CI/CD Automation
Automate manifest uploads to keep your Metricly dashboards in sync with your dbt project. Here is an example GitHub Actions workflow:
123456789101112131415161718192021222324252627282930313233343536# .github/workflows/deploy-manifest.ymlname: Deploy Semantic Manifest on: push: branches: [main] paths: - 'models/semantic/**' jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: | pip install dbt-metricflow[bigquery] - name: Generate manifest run: | dbt parse env: DBT_PROFILES_DIR: . - name: Upload to Metricly run: | curl -X POST https://metricly.xyz/api/manifest \ -H "Authorization: Bearer ${{ secrets.METRICLY_API_KEY }}" \ -H "Content-Type: application/json" \ -d @target/semantic_manifest.jsonAPI Upload
You can also upload manifests directly via the API:
# Upload manifest via API
curl -X POST https://metricly.xyz/api/manifest \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d @target/semantic_manifest.json
# Response
{
"success": true,
"metrics_count": 12,
"dimensions_count": 24,
"entities_count": 5
}Troubleshooting
Manifest not found
If dbt parse does not create a semantic_manifest.json:
- Ensure you have dbt-metricflow installed
- Check that your dbt version is 1.6 or later
- Verify you have semantic models defined in your project
Metric queries failing
If queries return errors after uploading the manifest:
- Verify warehouse credentials are correct
- Ensure the service account has access to the required schemas
- Test queries locally with
mf query - Check that model references in semantic models are valid
Missing dimensions
If some dimensions are not appearing in Metricly:
- Ensure dimensions are defined in semantic models, not just dbt models
- Check that dimension names do not conflict across semantic models
- Regenerate and re-upload the manifest
Next Steps
Dashboard Building Guide
Learn about widget types, controls, and building production dashboards.