Skip to content

Commit 1b1b46c

Browse files
authored
Merge branch 'main' into yunkim/crewai-flow
2 parents 811e6e6 + 70df147 commit 1b1b46c

File tree

598 files changed

+24593
-6758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

598 files changed

+24593
-6758
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ disable_warnings = couldnt-parse
88
[paths]
99
source =
1010
./
11-
/home/circleci/project/
1211
/root/project/
12+
/home/bits/project

.cursor/rules/dd-trace-py.mdc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
---
7+
description: dd-trace-py repository structure
8+
globs:
9+
alwaysApply: false
10+
---
11+
# AI Guidelines dd-trace-py
12+
13+
## The Golden Rule
14+
When unsure about implementation details, ALWAYS ask the developer.
15+
16+
## Project Context
17+
`dd-trace-py` is the official Datadog library for tracing and monitoring Python applications. It provides developers with deep visibility into their application's performance by enabling distributed tracing, continuous profiling, and error tracking.
18+
19+
The library offers automatic instrumentation for a wide variety of popular Python frameworks and libraries, such as Django, Flask, Celery, and SQLAlchemy. This allows for quick setup and immediate insights with minimal code changes. For more specific use cases, `dd-trace-py` also provides a comprehensive manual instrumentation API.
20+
21+
Key features include:
22+
- **Distributed Tracing:** Trace requests across service boundaries to understand the full lifecycle of a request in a microservices architecture.
23+
- **Continuous Profiling:** Analyze code-level performance in production to identify and optimize CPU and memory-intensive operations.
24+
- **Error Tracking:** Capture and aggregate unhandled exceptions and errors, linking them to specific traces for easier debugging.
25+
- **Application Security Monitoring (ASM):** Detect and protect against threats and vulnerabilities within your application.
26+
27+
## Critical Architecture Decisions
28+
29+
### Automatic Instrumentation via Monkey-Patching
30+
`dd-trace-py` heavily relies on monkey-patching for its automatic instrumentation. This allows the library to trace a wide range of standard libraries and frameworks without requiring any code changes from the user. This is a powerful feature that makes the library easy to adopt, but it's also a critical piece of architecture to be aware of when debugging or extending the tracer.
31+
32+
### Performance First
33+
The tracer is designed to run in high-throughput production environments. This means performance is a primary concern. Key decisions to achieve this include:
34+
1. **Core components written in C/Cython:** For performance-critical code paths.
35+
2. **Low-overhead sampling:** To reduce the performance impact of tracing.
36+
3. **Efficient serialization:** Using `msgpack` to communicate with the Datadog Agent.
37+
38+
### Extensible Integrations
39+
The library is designed to be easily extensible with new "integrations" for libraries that are not yet supported. The integration system provides a clear pattern for adding new instrumentation.
40+
41+
### Configuration via Environment Variables
42+
To make it easy to configure the tracer in various environments (local development, CI, production containers, etc.), the primary method of configuration is through environment variables.
43+
44+
## Code Style and Patterns
45+
46+
### Anchor comments
47+
48+
Add specially formatted comments throughout the codebase, where appropriate, for yourself as inline knowledge that can be easily `grep`ped for.
49+
50+
### Guidelines:
51+
52+
- Use `AIDEV-NOTE:`, `AIDEV-TODO:`, or `AIDEV-QUESTION:` (all-caps prefix) for comments aimed at AI and developers.
53+
- **Important:** Before scanning files, always first try to **grep for existing anchors** `AIDEV-*` in relevant subdirectories.
54+
- **Update relevant anchors** when modifying associated code.
55+
- **Do not remove `AIDEV-NOTE`s** without explicit human instruction.
56+
- Make sure to add relevant anchor comments, whenever a file or piece of code is:
57+
* too complex, or
58+
* very important, or
59+
* confusing, or
60+
* could have a bug
61+
62+
## Domain Glossary
63+
64+
- **Trace**: A representation of a single request or transaction as it moves through a system. It's composed of one or more spans.
65+
- **Span**: The basic building block of a trace. It represents a single unit of work (e.g., a function call, a database query). Spans have a start and end time, a name, a service, a resource, and can contain metadata (tags).
66+
- **Name (`span.name`)**: A string that represents the name of the operation being measured. It should be a general, human-readable identifier for the type of operation, such as `http.request`, `sqlalchemy.query`, or a function name like `auth.login`. This is typically more general than the `resource` name.
67+
- **Service**: A logical grouping of traces that perform the same function. For example, a web application or a database.
68+
- **Resource**: The specific operation being performed within a service that a span represents. For example, a web endpoint (`/users/{id}`) or a database query (`SELECT * FROM users`).
69+
- **Instrumentation**: The process of adding code to an application to generate traces. This can be done automatically by the library (`ddtrace-run`) or manually using the tracer API.
70+
- **Integration**: A component of `dd-trace-py` that provides automatic instrumentation for a specific library or framework (e.g., Django, `requests`, `psycopg2`).
71+
- **Tracer**: The object that creates and manages spans. It's the main entry point for manual instrumentation.
72+
- **Profiler**: A component that collects data on CPU and memory usage at the code level, helping to identify performance bottlenecks.
73+
- **`ddtrace-run`**: A command-line utility that automatically instruments a Python application by monkey-patching supported libraries at runtime.
74+
- **Tag**: A key-value pair of metadata that can be added to a span to provide additional context for filtering, grouping, or analysis.
75+
76+
## What AI Must NEVER Do
77+
78+
1. **Never change public API contracts** - Breaks real applications
79+
2. **Never commit secrets** - Use environment variables
80+
3. **Never assume business logic** - Always ask
81+
4. **Never remove AIDEV- comments** - They're there for a reason

.cursor/rules/repo-structure.mdc

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
---
7+
description: dd-trace-py repository structure
8+
globs:
9+
alwaysApply: false
10+
---
11+
# Repository Structure
12+
13+
# dd-trace-py Repository Structure
14+
15+
```
16+
dd-trace-py/
17+
├── ddtrace/
18+
│ ├── __init__.py # Package initializer
19+
│ ├── _trace/ # Core tracer implementation (private)
20+
│ │ ├── __init__.py
21+
│ │ ├── context.py # Span context propagation
22+
│ │ ├── provider.py # Tracer provider abstraction
23+
│ │ ├── span.py # Span object definition and lifecycle
24+
│ │ ├── tracer.py # Main Tracer class implementation
25+
│ │ ├── utils.py # Helper functions for tracing internals
26+
│ │ ├── _limits.py # Span/tag size limits and validation
27+
│ │ └── processor/ # Trace processing pipeline
28+
│ │
29+
│ ├── contrib/ # Official integrations (100+ libraries)
30+
│ │ ├── flask/ # Flask framework integration
31+
│ │ ├── django/ # Django framework integration
32+
│ │ ├── sqlalchemy/ # SQLAlchemy ORM integration
33+
│ │ ├── requests/ # HTTP client instrumentation
34+
│ │ ├── psycopg/ # PostgreSQL adapter integration
35+
│ │ ├── aiobotocore/ # Async AWS SDK tracing
36+
│ │ ├── langchain/ # LLM framework integration
37+
│ └── ├── … # Many more (see “Integration Registry" for full list)
38+
│ │ ├── internal/ # Shared utilities for integrations
39+
│ │ │ ├── asgi.py # ASGI framework utilities
40+
│ │ │ ├── wsgi.py # WSGI framework utilities
41+
│ │ │ └── utils.py # Common integration helpers
42+
│ │ └── integration_registry/ # Integration discovery and management
43+
│ │
44+
│ ├── appsec/ # Application Security features
45+
│ │ ├── __init__.py # AppSec public API
46+
│ │ ├── _iast/ # Interactive Application Security Testing
47+
│ │ ├── _ddwaf/ # Datadog Web Application Firewall
48+
│ │ ├── _exploit_prevention/ # Runtime exploit prevention
49+
│ │ └── trace_utils.py # AppSec trace enrichment
50+
│ │
51+
│ ├── internal/ # Core implementation utilities (private)
52+
│ │ ├── ci_visibility/ # Continuous Integration visibility
53+
│ │ ├── datastreams/ # Data Streams Monitoring
54+
│ │ ├── telemetry/ # Internal telemetry collection
55+
│ │ ├── coverage/ # Code coverage tracking
56+
│ │ ├── remoteconfig/ # Remote configuration management
57+
│ │ ├── _encoding.pyx # Cython encoding optimizations
58+
│ │ └── utils/ # Shared internal utilities
59+
│ │
60+
│ ├── llmobs/ # Large Language Model observability
61+
│ │ ├── __init__.py # LLM observability public API
62+
│ │ ├── _context.py # LLM-specific context management
63+
│ │ ├── _integrations/ # LLM framework integrations
64+
│ │ └── _evaluators/ # LLM evaluation metrics
65+
│ │
66+
│ ├── profiling/ # Continuous profiling
67+
│ │ ├── __init__.py # Profiling public API
68+
│ │ ├── collector/ # Native & Python collectors
69+
│ │ ├── exporter/ # Profile data export
70+
│ │ └── bootstrap/ # Profiling initialization
71+
│ │
72+
│ ├── debugging/ # Dynamic debugging and remote config
73+
│ │ ├── __init__.py # Debugging public API
74+
│ │ ├── _probe/ # Debug probe management
75+
│ │ ├── _signal/ # Signal handling for debugging
76+
│ │ └── _products/ # Product-specific debugging
77+
│ │
78+
│ ├── errortracking/ # Error tracking functionality
79+
│ │ ├── __init__.py # Error tracking public API
80+
│ │ └── _handled_exceptions/ # Exception capture and reporting
81+
│ │
82+
│ ├── ext/ # Extension constants and tag definitions
83+
│ │ ├── __init__.py
84+
│ │ ├── aws.py # AWS service constants
85+
│ │ ├── http.py # HTTP status and header constants
86+
│ │ └── sql.py # SQL operation constants
87+
│ │
88+
│ ├── opentelemetry/ # OpenTelemetry compatibility layer
89+
│ ├── opentracer/ # OpenTracing compatibility layer
90+
│ ├── propagation/ # Trace context propagation protocols
91+
│ ├── settings/ # Configuration management
92+
│ ├── sourcecode/ # Source code integration
93+
│ ├── bootstrap/ # Package initialization and CLI bootstrap
94+
│ └── vendor/ # Vendored third-party dependencies
95+
96+
├── tests/ # Comprehensive test suite
97+
│ ├── contrib/ # Integration tests (mirrors ddtrace/contrib/)
98+
│ ├── appsec/ # Application Security tests
99+
│ ├── debugging/ # Dynamic debugging tests
100+
│ ├── internal/ # Internal component tests
101+
│ ├── tracer/ # Core tracer functionality tests
102+
│ ├── snapshots/ # Test output snapshots for regression testing
103+
│ └── conftest.py # PyTest configuration and shared fixtures
104+
105+
├── benchmarks/ # Performance benchmarks and regression detection
106+
│ ├── base/ # Base benchmark framework
107+
│ ├── bm/ # Benchmark utilities and fixtures
108+
│ ├── django_simple/ # Django framework benchmarks
109+
│ ├── flask_simple/ # Flask framework benchmarks
110+
│ ├── startup/ # Import and startup time benchmarks
111+
│ └── threading/ # Multi-threading performance tests
112+
113+
├── scripts/ # Development and maintenance utilities
114+
│ ├── ci_visibility/ # CI pipeline automation scripts
115+
│ ├── iast/ # IAST development tools
116+
│ ├── integration_registry/ # Integration management scripts
117+
│ └── profiles/ # Profiling analysis tools
118+
119+
├── docs/ # Documentation
120+
│ ├── contributing.rst # Main contributing guide
121+
│ ├── contributing-testing.rst # Testing setup and procedures
122+
│ ├── api.rst # API reference documentation
123+
│ └── basic_usage.rst # Getting started guide
124+
125+
├── src/ # Native code sources
126+
│ └── native/ # C/C++ native extensions for performance
127+
128+
├── lib-injection/ # Library injection for serverless and containers
129+
├── docker/ # Docker build configurations
130+
├── hooks/ # Git hooks for code quality
131+
├── ci/ # CI configuration and utilities
132+
├── releasenotes/ # Release notes management
133+
├── templates/ # Code generation templates
134+
135+
├── setup.py # Package build configuration
136+
├── pyproject.toml # Modern Python project configuration
137+
├── riotfile.py # Multi-version testing with Riot
138+
├── hatch.toml # Hatch build system configuration
139+
├── docker-compose.yml # Development environment setup
140+
└── conftest.py # Global PyTest configuration
141+
```
142+
143+
## Internal Implementation Details
144+
145+
**`internal/` folders:** Contains private methods and functionality used by the library itself. Code that is not part of the public API and not intended for direct use by customers.
146+
147+
## Key Components
148+
149+
### Core Library (`ddtrace/`)
150+
- **Main Package**: Contains the primary tracing functionality and public APIs
151+
- **Contrib**: 100+ integrations with popular Python libraries (Django, Flask, Redis, etc.)
152+
- **AppSec**: Application security features including IAST and WAF protection
153+
- **Profiling**: Continuous profiling capabilities for CPU, memory, and I/O
154+
- **Internal**: Implementation details not part of the public API
155+
156+
### Testing (`tests/`)
157+
- **Comprehensive Test Suite**: Unit tests, integration tests, and end-to-end tests
158+
- **Snapshots**: Regression testing using captured test outputs
159+
- **Contrib Tests**: Specific tests for each third-party integration
160+
161+
### Development Tools
162+
- **Benchmarks**: Performance testing and regression detection
163+
- **Scripts**: Development utilities and automation tools
164+
- **Hooks**: Git hooks for code quality enforcement
165+
- **Docker**: Containerized development and testing environments
166+
167+
### Build & Distribution
168+
- **Native Code**: C/C++ extensions for performance-critical components
169+
- **Multiple Build Systems**: Support for setuptools, hatch, and modern Python packaging
170+
- **Release Management**: Automated release notes and versioning
171+
172+
### Documentation & Contributing
173+
- **Extensive Docs**: API documentation, usage guides, and contributing guidelines
174+
- **Templates**: Code generation templates for new integrations
175+
- **CI/CD**: Comprehensive testing and deployment pipelines

0 commit comments

Comments
 (0)