Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4fb8883
feat: add runtime statistics tracking for providers
kooksee Mar 19, 2026
6b23196
feat: 添加 Provider 超时和慢调用警告功能,更新文档和示例
kooksee Mar 19, 2026
532f846
feat: 添加默认 provider 超时和慢调用阈值,更新相关文档和测试
kooksee Mar 19, 2026
813c725
feat: 添加最近注入错误的 API 和前端展示功能,更新相关文档和测试
kooksee Mar 20, 2026
99b4e12
feat: 优化模板和文档中的代码格式,提升可读性
kooksee Mar 20, 2026
6e474b1
feat: 增强错误记录功能,添加提供者执行阶段和根因信息
kooksee Mar 20, 2026
d635a4b
feat: 添加错误提示信息和增强错误记录功能,优化错误处理逻辑
kooksee Mar 20, 2026
532fea7
feat: 增强错误处理,添加错误类型和提示信息,优化错误记录功能
kooksee Mar 20, 2026
473fdcb
feat: 添加机器诊断模式支持,优化日志输出和错误记录功能
kooksee Mar 20, 2026
fb8d00a
feat: 添加依赖追踪日志功能,优化依赖解析和注入过程中的日志记录
kooksee Mar 20, 2026
f1aa75e
feat: 更新事件速查表格格式,优化可读性
kooksee Mar 20, 2026
744c713
feat: 增强依赖提供功能,添加详细的追踪日志记录
kooksee Mar 20, 2026
7154f08
feat: 添加诊断文件记录功能,优化错误和追踪事件的日志记录
kooksee Mar 20, 2026
1eb96ed
qian'du
kooksee Mar 23, 2026
c3bca64
feat: 添加 Provider 详细信息弹窗,优化依赖节点信息展示
kooksee Mar 23, 2026
6f7fa8f
feat(trace): add tracing functionality with span management and event…
kooksee Mar 23, 2026
144fbaa
feat(trace): 更新追踪功能,优化注入和解析过程中的日志记录
kooksee Mar 23, 2026
4703203
feat(trace): 增强追踪功能,添加缩进模式选择和提供者信息展示
kooksee Mar 23, 2026
f504e2c
feat(depth): 优化深度输入功能,支持自定义输入和增减按钮
kooksee Mar 23, 2026
f602608
feat(diagnostic): 移除诊断文件记录功能,优化调用链 Trace 模态框
kooksee Mar 23, 2026
f626430
feat(trace): 添加深度输入功能,优化调用链 Trace 诊断入口
kooksee Mar 23, 2026
5d3fcb5
feat(trace): 优化调用链 Trace 视图,简化深度输入和增强错误信息展示
kooksee Mar 24, 2026
3cafc6f
feat(api): 优化包和类型详情处理,增强错误处理和分页功能
kooksee Mar 24, 2026
a425689
feat(trace): 优化链路数据处理,支持树形结构排序和过滤功能
kooksee Mar 24, 2026
12a5e3c
feat(diag): 移除不必要的诊断记录转换函数,简化代码结构
kooksee Mar 24, 2026
38accf2
feat(trace): 增强文件落盘机制,支持从环境变量配置回退到诊断文件
kooksee Mar 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
# Dependency directories (remove the comment below to include it)
vendor
.env
.vscode/
.local/
153 changes: 123 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ Inspired by [uber-go/dig](https://github.com/uber-go/dig), with support for adva

## ✨ Features

| Feature | Description |
|---------|-------------|
| 🔄 **Cycle Detection** | Auto-detect dependency cycles |
| 📦 **Multiple Injection** | Support func, struct, map, list |
| 🏷️ **Namespace** | Dependency isolation via map key |
| 🎯 **Multi-Output** | Struct can provide multiple dependencies |
| 🪆 **Nested Support** | Support nested struct injection |
| 🔧 **Non-Invasive** | Zero intrusion to original objects |
| 🛡️ **Safe API** | `TryProvide`/`TryInject` won't panic |
| 🌐 **Visualization** | HTTP module for dependency graph |
| Feature | Description |
| ------------------------ | ---------------------------------------- |
| 🔄 **Cycle Detection** | Auto-detect dependency cycles |
| 📦 **Multiple Injection** | Support func, struct, map, list |
| 🏷️ **Namespace** | Dependency isolation via map key |
| 🎯 **Multi-Output** | Struct can provide multiple dependencies |
| 🪆 **Nested Support** | Support nested struct injection |
| 🔧 **Non-Invasive** | Zero intrusion to original objects |
| 🛡️ **Safe API** | `TryProvide`/`TryInject` won't panic |
| 🌐 **Visualization** | HTTP module for dependency graph |

## 📦 Installation

Expand Down Expand Up @@ -115,6 +115,99 @@ err := dix.TryInject(di, func(svc *Service) {
})
```

### Startup Timeout / Slow Provider Warning

Control long-running providers during startup:

- Default provider timeout: `15s`
- Disable provider timeout explicitly: `dix.WithProviderTimeout(0)`
- Default slow provider warning threshold: `2s`
- Disable slow provider warning: `dix.WithSlowProviderThreshold(0)`

```go
di := dix.New(
// Default `ProviderTimeout` is `15s`
// Use `dix.WithProviderTimeout(0)` to disable provider timeout
// Default `SlowProviderThreshold` is `2s`
// Use `dix.WithSlowProviderThreshold(0)` to disable slow-provider warnings
dix.WithProviderTimeout(2*time.Second), // override default (default: 15s, 0 = disabled)
dix.WithSlowProviderThreshold(300*time.Millisecond), // override default (default: 2s, 0 = disabled)
)
```

### DI Trace Logging (Optional)

Enable step-by-step dependency resolution/injection/provider execution logs:

- Env var: `DIX_TRACE_DI`
- Default: disabled
- Enable values: `1`, `true`, `on`, `yes`, `enable`, `trace`, `debug`

```bash
export DIX_TRACE_DI=true
```

When enabled, dix prints `di_trace ...` events with structured key-values (provider, input/output types, query kind, parent chain, timeout, etc.).

> Note: if `DIX_LLM_DIAG_MODE=machine`, human-readable text logs are suppressed by design, including `di_trace` lines.

### Diagnostic File Collection (Optional)

You can collect detailed diagnostics into a searchable JSONL file:

- Env var: `DIX_DIAG_FILE`
- Example: `export DIX_DIAG_FILE=.local/dix-diag.jsonl`

Behavior rules:

- If `DIX_DIAG_FILE` is **not configured**, dix keeps the original behavior (no diagnostic file output).
- If `DIX_DIAG_FILE` is configured, dix appends diagnostic records to file (`trace` / `error` / `llm`).
- Console verbosity still follows existing controls (`DIX_TRACE_DI`, `DIX_LLM_DIAG_MODE`).

Tip:

- Keep console output concise for users.
- Keep detailed records in file for search/LLM/offline troubleshooting.

### In-Memory Trace Query (`dixtrace`, Optional)

Starting from this version, dix also emits unified trace events into an in-memory trace store (`dixtrace`), which can be queried via HTTP API (`/api/trace`).

- Default: enabled (in-memory ring buffer)
- Optional file sink env var: `DIX_TRACE_FILE`
- Example: `export DIX_TRACE_FILE=.local/dix-trace.jsonl`
- Compatibility fallback: when `DIX_TRACE_FILE` is not set and `DIX_DIAG_FILE` is set, trace file sink will reuse `DIX_DIAG_FILE` in append mode.

`/api/trace` is optimized for online troubleshooting (filter by `operation/status/event/component/provider/output_type`).
If you need separate trace-only file persistence, set `DIX_TRACE_FILE` explicitly.

Quick event dictionary:

| Event | Meaning |
| ---------------------------------------------- | -------------------------------------------------------------------------- |
| `di_trace inject.start` | Begin an injection request (`component`, `param_type`) |
| `di_trace inject.route` | Injection route selected (`function` or `struct`) |
| `di_trace provide.start` | Begin a provider registration request (`component`) |
| `di_trace provide.signature` | Provider function signature analyzed (`input_count`, `output_count`) |
| `di_trace provide.register.output.done` | Provider output type registered successfully |
| `di_trace provide.register.failed` | Provider registration failed (`reason` or `error`) |
| `di_trace resolve.value.search_provider.start` | Start searching providers for a dependency type |
| `di_trace resolve.value.found` | Dependency value resolved successfully |
| `di_trace resolve.value.not_found` | Dependency resolution failed (`reason` included) |
| `di_trace provider.execute.dispatch` | Provider selected for execution (`provider`, `output_type`, `input_types`) |
| `di_trace provider.input.resolve.start` | Resolve one provider input type |
| `di_trace provider.input.resolve.found` | Provider input resolved |
| `di_trace provider.input.resolve.failed` | Provider input resolution failed |
| `di_trace provider.call.start` | Start executing provider (`timeout`) |
| `di_trace provider.call.done` | Provider execution completed |
| `di_trace provider.call.failed` | Provider execution failed (`timed_out`, `error`) |
| `di_trace provider.call.return_error` | Provider returned non-nil `error` |
| `di_trace inject.func.resolve_input.start` | Resolve function injection argument |
| `di_trace inject.func.resolve_input.failed` | Function argument resolution failed |
| `di_trace inject.struct.field.resolve.start` | Resolve one struct field injection |
| `di_trace inject.struct.field.resolve.done` | Struct field injected successfully |
| `di_trace inject.struct.field.resolve.failed` | Struct field injection failed |

## 🎯 Injection Patterns

### Struct Injection
Expand Down Expand Up @@ -242,29 +335,29 @@ task build

## 📚 Examples

| Example | Description |
|---------|-------------|
| [struct-in](./example/struct-in/) | Struct input injection |
| [struct-out](./example/struct-out/) | Struct multi-output |
| [func](./example/func/) | Function injection |
| [map](./example/map/) | Map/namespace injection |
| [map-nil](./example/map-nil/) | Map with nil handling |
| [list](./example/list/) | List injection |
| [list-nil](./example/list-nil/) | List with nil handling |
| [lazy](./example/lazy/) | Lazy injection |
| [cycle](./example/cycle/) | Cycle detection example |
| [handler](./example/handler/) | Handler pattern |
| [inject_method](./example/inject_method/) | Method injection |
| [test-return-error](./example/test-return-error/) | Error handling |
| [http](./example/http/) | HTTP visualization |
| Example | Description |
| ------------------------------------------------- | ----------------------- |
| [struct-in](./example/struct-in/) | Struct input injection |
| [struct-out](./example/struct-out/) | Struct multi-output |
| [func](./example/func/) | Function injection |
| [map](./example/map/) | Map/namespace injection |
| [map-nil](./example/map-nil/) | Map with nil handling |
| [list](./example/list/) | List injection |
| [list-nil](./example/list-nil/) | List with nil handling |
| [lazy](./example/lazy/) | Lazy injection |
| [cycle](./example/cycle/) | Cycle detection example |
| [handler](./example/handler/) | Handler pattern |
| [inject_method](./example/inject_method/) | Method injection |
| [test-return-error](./example/test-return-error/) | Error handling |
| [http](./example/http/) | HTTP visualization |

## 📖 Documentation

| Document | Description |
|----------|-------------|
| [Design Document](./docs/design.md) | Architecture and detailed design |
| [Audit Report](./docs/audit.md) | Project audit, evaluation and comparison |
| [dixhttp README](./dixhttp/README.md) | HTTP visualization module documentation |
| Document | Description |
| ------------------------------------- | ---------------------------------------- |
| [Design Document](./docs/design.md) | Architecture and detailed design |
| [Audit Report](./docs/audit.md) | Project audit, evaluation and comparison |
| [dixhttp README](./dixhttp/README.md) | HTTP visualization module documentation |

## 📄 License

Expand Down
Loading
Loading