Skip to content

Automate browser based workflows with AI

Remove ddtrace dependency from OSS (#4049)

Stanislav Novosad62a7bd28862b
diff --git a/pyproject.toml b/pyproject.toml
index 61bccaa7b..71736bf62 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -23,7 +23,6 @@ dependencies = [
"greenlet==3.0.3 ; python_version >= '3.11' and python_version < '3.12'",
"pillow>=10.1.0,<11",
"starlette-context>=0.3.6,<0.4",
- "ddtrace>=2.3.2,<3",
"pydantic>=2.5.2,<3",
"pydantic-settings>=2.1.0,<3",
"fastapi>=0.115.4,<0.116",
@@ -70,6 +69,7 @@ dependencies = [
[dependency-groups]
cloud = [
+ "ddtrace>=2.3.2,<3",
"stripe>=9.7.0,<10",
"temporalio>=1.6.0,<2",
"dramatiq[asyncio]>=1.18.0,<2",
diff --git a/skyvern/__init__.py b/skyvern/__init__.py
index 1dcde7d37..c889066a7 100644
--- a/skyvern/__init__.py
+++ b/skyvern/__init__.py
@@ -2,31 +2,36 @@ import re
import typing
from typing import Any
-from ddtrace import tracer
-from ddtrace.ext import http
-from ddtrace.trace import TraceFilter, Span
-
from skyvern.forge.sdk.forge_log import setup_logger
from skyvern.utils import setup_windows_event_loop_policy
if typing.TYPE_CHECKING:
from skyvern.library import Skyvern # noqa: E402
+try:
+ from ddtrace import tracer
+ from ddtrace.ext import http
+ from ddtrace.trace import TraceFilter, Span
+
+ class FilterHeartbeat(TraceFilter):
+ _HB_URL = re.compile(r"http://.*/heartbeat$")
-class FilterHeartbeat(TraceFilter):
- _HB_URL = re.compile(r"http://.*/heartbeat$")
+ def process_trace(self, trace: list[Span]) -> list[Span] | None:
+ for span in trace:
+ url = span.get_tag(http.URL)
+ if span.parent_id is None and url is not None and self._HB_URL.match(url):
+ # drop the full trace chunk
+ return None
+ return trace
- def process_trace(self, trace: list[Span]) -> list[Span] | None:
- for span in trace:
- url = span.get_tag(http.URL)
- if span.parent_id is None and url is not None and self._HB_URL.match(url):
- # drop the full trace chunk
- return None
- return trace
+ _DDTRACE_AVAILABLE = True
+except ImportError:
+ _DDTRACE_AVAILABLE = False
setup_windows_event_loop_policy()
-tracer.configure(trace_processors=[FilterHeartbeat()])
+if _DDTRACE_AVAILABLE:
+ tracer.configure(trace_processors=[FilterHeartbeat()])
setup_logger()
# noinspection PyUnresolvedReferences
diff --git a/skyvern/forge/sdk/services/org_auth_service.py b/skyvern/forge/sdk/services/org_auth_service.py
index 1142d69f2..68a10ef14 100644
--- a/skyvern/forge/sdk/services/org_auth_service.py
+++ b/skyvern/forge/sdk/services/org_auth_service.py
@@ -5,7 +5,6 @@ from typing import Annotated
import structlog
from asyncache import cached
from cachetools import TTLCache
-from ddtrace import tracer
from fastapi import Header, HTTPException, status
from jose import jwt
from jose.exceptions import JWTError
@@ -18,6 +17,13 @@ from skyvern.forge.sdk.db.client import AgentDB
from skyvern.forge.sdk.models import TokenPayload
from skyvern.forge.sdk.schemas.organizations import Organization, OrganizationAuthToken, OrganizationAuthTokenType
+try:
+ from ddtrace import tracer
+
+ _DDTRACE_AVAILABLE = True
+except ImportError:
+ _DDTRACE_AVAILABLE = False
+
LOG = structlog.get_logger()
AUTHENTICATION_TTL = 60 * 60 # one hour
@@ -60,12 +66,12 @@ async def get_current_org(
curr_ctx.organization_id = organization.organization_id
curr_ctx.organization_name = organization.organization_name
- # Tag datadog span immediately
- span = tracer.current_span()
- if span:
- span.set_tag("organization_id", organization.organization_id)
- if organization.organization_name:
- span.set_tag("organization_name", organization.organization_name)
+ if _DDTRACE_AVAILABLE:
+ span = tracer.current_span()
+ if span:
+ span.set_tag("organization_id", organization.organization_id)
+ if organization.organization_name:
+ span.set_tag("organization_name", organization.organization_name)
except Exception:
pass
diff --git a/uv.lock b/uv.lock
index 1549f0e50..b22a7f071 100644
--- a/uv.lock
+++ b/uv.lock
@@ -4764,7 +4764,6 @@ dependencies = [
{ name = "azure-storage-blob" },
{ name = "cachetools" },
{ name = "curlparser" },
- { name = "ddtrace" },
{ name = "email-validator" },
{ name = "fastapi" },
{ name = "fastmcp" },
@@ -4814,6 +4813,7 @@ dependencies = [
[package.dev-dependencies]
cloud = [
+ { name = "ddtrace" },
{ name = "dramatiq" },
{ name = "redis" },
{ name = "stripe" },
@@ -4855,7 +4855,6 @@ requires-dist = [
{ name = "azure-storage-blob", specifier = ">=12.26.0" },
{ name = "cachetools", specifier = ">=5.3.2,<6" },
{ name = "curlparser", specifier = ">=0.1.0,<0.2" },
- { name = "ddtrace", specifier = ">=2.3.2,<3" },
{ name = "email-validator", specifier = ">=2.2.0,<3" },
{ name = "fastapi", specifier = ">=0.115.4,<0.116" },
{ name = "fastmcp", specifier = ">=2.10.1,<3" },
@@ -4905,6 +4904,7 @@ requires-dist = [
[package.metadata.requires-dev]
cloud = [
+ { name = "ddtrace", specifier = ">=2.3.2,<3" },
{ name = "dramatiq", extras = ["asyncio"], specifier = ">=1.18.0,<2" },
{ name = "redis", specifier = ">=5.0.3,<6" },
{ name = "stripe", specifier = ">=9.7.0,<10" },