Skip to content

Commit 5b0a3ef

Browse files
Feature product telemetry (#10)
1 parent 7626ac9 commit 5b0a3ef

File tree

26 files changed

+538
-23
lines changed

26 files changed

+538
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ datu-sqlserver/
6161
test_schema_cache.json
6262

6363
.cache/
64-
site/
64+
site/
65+
.coverage*

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ RUN apt-get update && \
99
rm -rf /var/lib/apt/lists/* && \
1010
pip install --upgrade pip
1111

12-
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
13-
RUN curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list
12+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg \
13+
&& curl https://packages.microsoft.com/config/debian/11/prod.list -o /etc/apt/sources.list.d/mssql-release.list
1414

1515
RUN apt-get update
1616
RUN env ACCEPT_EULA=Y apt-get install -y msodbcsql18
@@ -21,4 +21,4 @@ RUN uv sync --extra postgres --extra sqldb
2121
ENV PATH="/app/.venv/bin:$PATH"
2222
# Reset the entrypoint, don't invoke `uv`
2323
ENTRYPOINT []
24-
CMD ["uvicorn", "datu.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
24+
CMD ["uvicorn", "datu.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

changelog.d/+7413cd44.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enable product Telemetry

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies = [
3838
"fastmcp>=2.10.5",
3939
"mcp-use[search]>=1.3.7",
4040
"onnxruntime==1.19.2 ; sys_platform == 'darwin' and platform_machine == 'x86_64'",
41+
"posthog>=6.5.0",
4142
]
4243

4344
[project.urls]

src/datu/app_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from datu.integrations.config import IntegrationConfigs
1818
from datu.mcp.config import MCPConfig
1919
from datu.services.config import SchemaRAGConfig
20+
from datu.telemetry.config import TelemetryConfig
2021

2122

2223
class Environment(Enum):
@@ -56,6 +57,13 @@ class DatuConfig(BaseSettings):
5657
schema_sample_limit (int): The maximum number of rows to sample from the schema.
5758
schema_categorical_threshold (int): The threshold for categorical columns in the schema.
5859
enable_schema_rag (bool): Enable RAG for schema extraction.
60+
enable_anonymized_telemetry (bool): Enable anonymized telemetry. Default is True.
61+
app_environment (str): The application environment (e.g., "dev", "test", "prod"). Default is "dev".
62+
telemetry (TelemetryConfig | None): Configuration settings for telemetry.
63+
enable_mcp (bool): Whether to enable MCP integration. Default is False.
64+
mcp (MCPConfig | None): Configuration settings for MCP integration.
65+
enable_schema_rag (bool): Enable RAG for schema extraction.
66+
schema_rag (SchemaRAGConfig | None): Configuration settings for schema RAG.
5967
6068
Attributes:
6169
host (str): The host address for the application.
@@ -77,7 +85,8 @@ class DatuConfig(BaseSettings):
7785
mcp (MCPConfig | None): Configuration settings for MCP integration.
7886
enable_schema_rag (bool): Enable RAG for schema extraction.
7987
schema_rag (SchemaRAGConfig | None): Configuration settings for schema RAG.
80-
88+
enable_anonymized_telemetry (bool): Enable anonymized telemetry.
89+
telemetry (TelemetryConfig | None): Configuration settings for telemetry.
8190
8291
"""
8392

@@ -110,7 +119,8 @@ class DatuConfig(BaseSettings):
110119
description="Configuration settings for schema RAG (Retrieval-Augmented Generation).",
111120
)
112121
enable_anonymization: bool = False
113-
122+
enable_anonymized_telemetry: bool = True
123+
telemetry: TelemetryConfig | None = Field(default_factory=TelemetryConfig)
114124
model_config = SettingsConfigDict(
115125
env_prefix="datu_",
116126
env_nested_delimiter="__",

src/datu/factory/llm_client_factory.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from typing import Literal
77

88
from datu.llm_clients.openai_client import OpenAIClient
9+
from datu.telemetry.product.events import MCPClientEvent
10+
from datu.telemetry.product.posthog import get_posthog_client
911

1012

1113
def get_llm_client(provider: Literal["openai"] | None = None) -> OpenAIClient | None:
@@ -20,6 +22,15 @@ def get_llm_client(provider: Literal["openai"] | None = None) -> OpenAIClient |
2022
ValueError: If the specified provider is not supported.
2123
"""
2224
if provider == "openai":
23-
return OpenAIClient()
25+
openai_client = OpenAIClient()
26+
if openai_client.agent:
27+
posthog_client = get_posthog_client()
28+
if openai_client.mcp_client and getattr(openai_client.mcp_client, "config", None):
29+
servers = openai_client.mcp_client.config.get("mcpServers", {})
30+
server_names = list(servers.keys()) if servers else []
31+
else:
32+
server_names = []
33+
posthog_client.capture(MCPClientEvent(server_names=server_names))
34+
return openai_client
2435
else:
2536
raise ValueError("Invalid LLM provider specified in configuration.")

src/datu/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from datu.app_config import get_logger, settings
1414
from datu.routers import chat, metadata, transformations
1515
from datu.schema_extractor.schema_cache import load_schema_cache
16+
from datu.telemetry.product.events import OpenAIEvent
17+
from datu.telemetry.product.posthog import get_posthog_client
1618

1719
logger = get_logger(__name__)
1820

@@ -56,6 +58,8 @@ def start_app() -> None:
5658
It also sets the logging level based on the configuration settings.
5759
"""
5860
logger.info("Starting the FastAPI application...")
61+
posthog_client = get_posthog_client()
62+
posthog_client.capture(OpenAIEvent())
5963
uvicorn.run(app, host=settings.host, port=settings.port)
6064

6165

src/datu/telemetry/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Telemetry configuration settings."""
2+
3+
from pydantic_settings import BaseSettings, SettingsConfigDict
4+
5+
6+
class TelemetryConfig(BaseSettings):
7+
"""Telemetry configuration settings."""
8+
9+
api_key: str = "phc_m74dfR9nLpm2nipvkL2swyFDtNuQNC9o2FL2CSbh6Je"
10+
package_name: str = "datu-core"
11+
12+
model_config = SettingsConfigDict(
13+
env_prefix="telemetry_",
14+
env_nested_delimiter="__",
15+
)
16+
17+
18+
def get_telemetry_settings() -> TelemetryConfig:
19+
return TelemetryConfig()

src/datu/telemetry/product/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)