ecsctx 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. ecsctx-0.4.1/.github/workflows/ci.yml +35 -0
  2. ecsctx-0.4.1/.github/workflows/release.yml +121 -0
  3. ecsctx-0.4.1/.gitignore +33 -0
  4. ecsctx-0.4.1/.serena/.gitignore +2 -0
  5. ecsctx-0.4.1/.serena/project.yml +135 -0
  6. ecsctx-0.4.1/CHANGELOG.md +36 -0
  7. ecsctx-0.4.1/CLAUDE.md +22 -0
  8. ecsctx-0.4.1/LICENSE +21 -0
  9. ecsctx-0.4.1/PKG-INFO +1553 -0
  10. ecsctx-0.4.1/README.md +1517 -0
  11. ecsctx-0.4.1/ecsctx/CLAUDE.md +26 -0
  12. ecsctx-0.4.1/ecsctx/__init__.py +67 -0
  13. ecsctx-0.4.1/ecsctx/context.py +388 -0
  14. ecsctx-0.4.1/ecsctx/contrib/__init__.py +1 -0
  15. ecsctx-0.4.1/ecsctx/contrib/celery/__init__.py +11 -0
  16. ecsctx-0.4.1/ecsctx/contrib/celery/log_context.py +126 -0
  17. ecsctx-0.4.1/ecsctx/contrib/django/CLAUDE.md +25 -0
  18. ecsctx-0.4.1/ecsctx/contrib/django/__init__.py +35 -0
  19. ecsctx-0.4.1/ecsctx/contrib/django/context_binder.py +80 -0
  20. ecsctx-0.4.1/ecsctx/contrib/django/decorators.py +156 -0
  21. ecsctx-0.4.1/ecsctx/contrib/django/logging.py +250 -0
  22. ecsctx-0.4.1/ecsctx/contrib/django/middleware.py +87 -0
  23. ecsctx-0.4.1/ecsctx/contrib/django/processors.py +116 -0
  24. ecsctx-0.4.1/ecsctx/contrib/rq/__init__.py +7 -0
  25. ecsctx-0.4.1/ecsctx/contrib/rq/log_context.py +95 -0
  26. ecsctx-0.4.1/ecsctx/ecs_validator.py +92 -0
  27. ecsctx-0.4.1/ecsctx/formatters.py +27 -0
  28. ecsctx-0.4.1/ecsctx/pii/__init__.py +240 -0
  29. ecsctx-0.4.1/ecsctx/pii/crypto.py +98 -0
  30. ecsctx-0.4.1/ecsctx/pii/keyset.py +148 -0
  31. ecsctx-0.4.1/ecsctx/pii/normalize.py +41 -0
  32. ecsctx-0.4.1/ecsctx/pii/provider.py +43 -0
  33. ecsctx-0.4.1/ecsctx/pii/vault.py +219 -0
  34. ecsctx-0.4.1/ecsctx/processors.py +427 -0
  35. ecsctx-0.4.1/pyproject.toml +60 -0
  36. ecsctx-0.4.1/tests/__init__.py +0 -0
  37. ecsctx-0.4.1/tests/conftest.py +72 -0
  38. ecsctx-0.4.1/tests/test_context.py +109 -0
  39. ecsctx-0.4.1/tests/test_crypto.py +85 -0
  40. ecsctx-0.4.1/tests/test_keyset.py +111 -0
  41. ecsctx-0.4.1/tests/test_pii_init.py +190 -0
  42. ecsctx-0.4.1/tests/test_processors.py +134 -0
  43. ecsctx-0.4.1/tests/test_vault.py +175 -0
  44. ecsctx-0.4.1/uv.lock +715 -0
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.12"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: pip install -e ".[test]"
21
+ - run: pytest tests/ -v
22
+
23
+ build:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: actions/setup-python@v5
28
+ with:
29
+ python-version: "3.12"
30
+ - run: pip install build
31
+ - run: python -m build
32
+ - uses: actions/upload-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
@@ -0,0 +1,121 @@
1
+ name: Release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ bump:
7
+ description: "Version bump type"
8
+ required: true
9
+ type: choice
10
+ options:
11
+ - patch
12
+ - minor
13
+ - major
14
+
15
+ permissions:
16
+ contents: write
17
+ id-token: write
18
+
19
+ jobs:
20
+ release:
21
+ runs-on: ubuntu-latest
22
+ environment: pypi
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ with:
26
+ fetch-depth: 0
27
+
28
+ - uses: actions/setup-python@v5
29
+ with:
30
+ python-version: "3.12"
31
+
32
+ - name: Calculate new version
33
+ id: version
34
+ run: |
35
+ current=$(python -c "import re; print(re.search(r'version = \"(.+?)\"', open('pyproject.toml').read()).group(1))")
36
+ IFS='.' read -r major minor patch <<< "$current"
37
+ case "${{ inputs.bump }}" in
38
+ major) major=$((major + 1)); minor=0; patch=0 ;;
39
+ minor) minor=$((minor + 1)); patch=0 ;;
40
+ patch) patch=$((patch + 1)) ;;
41
+ esac
42
+ new="${major}.${minor}.${patch}"
43
+ echo "current=$current" >> "$GITHUB_OUTPUT"
44
+ echo "new=$new" >> "$GITHUB_OUTPUT"
45
+
46
+ - name: Bump version in pyproject.toml and __init__.py
47
+ run: |
48
+ sed -i "s/version = \"${{ steps.version.outputs.current }}\"/version = \"${{ steps.version.outputs.new }}\"/" pyproject.toml
49
+ sed -i "s/__version__ = \"${{ steps.version.outputs.current }}\"/__version__ = \"${{ steps.version.outputs.new }}\"/" ecsctx/__init__.py
50
+
51
+ - name: Generate CHANGELOG entry
52
+ run: |
53
+ NEW_VERSION="v${{ steps.version.outputs.new }}"
54
+ DATE=$(date +%Y-%m-%d)
55
+
56
+ # Find previous tag
57
+ PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
58
+ if [ -z "$PREV_TAG" ]; then
59
+ RANGE="HEAD"
60
+ else
61
+ RANGE="${PREV_TAG}..HEAD"
62
+ fi
63
+
64
+ # Collect commits grouped by type
65
+ FEATURES=$(git log "$RANGE" --pretty=format:"- %s (%h)" --grep="^feat" 2>/dev/null || true)
66
+ FIXES=$(git log "$RANGE" --pretty=format:"- %s (%h)" --grep="^fix" 2>/dev/null || true)
67
+ OTHER=$(git log "$RANGE" --pretty=format:"- %s (%h)" --invert-grep --grep="^feat" --grep="^fix" --grep="^release:" --all-match 2>/dev/null || true)
68
+
69
+ # Build entry
70
+ ENTRY="## ${NEW_VERSION} (${DATE})"$'\n'
71
+ [ -n "$FEATURES" ] && ENTRY+=$'\n'"### Features"$'\n'"${FEATURES}"$'\n'
72
+ [ -n "$FIXES" ] && ENTRY+=$'\n'"### Fixes"$'\n'"${FIXES}"$'\n'
73
+ [ -n "$OTHER" ] && ENTRY+=$'\n'"### Other"$'\n'"${OTHER}"$'\n'
74
+
75
+ # Prepend to CHANGELOG.md
76
+ if [ -f CHANGELOG.md ]; then
77
+ # Insert after the first line (header)
78
+ {
79
+ head -n 1 CHANGELOG.md
80
+ echo ""
81
+ echo "$ENTRY"
82
+ tail -n +2 CHANGELOG.md
83
+ } > CHANGELOG.tmp
84
+ mv CHANGELOG.tmp CHANGELOG.md
85
+ else
86
+ {
87
+ echo "# Changelog"
88
+ echo ""
89
+ echo "$ENTRY"
90
+ } > CHANGELOG.md
91
+ fi
92
+
93
+ - name: Build
94
+ run: |
95
+ pip install build
96
+ python -m build
97
+
98
+ - name: Run tests
99
+ run: |
100
+ pip install -e ".[test]"
101
+ pytest tests/ -v
102
+
103
+ - name: Commit and tag
104
+ run: |
105
+ git config user.name "github-actions[bot]"
106
+ git config user.email "github-actions[bot]@users.noreply.github.com"
107
+ git add pyproject.toml ecsctx/__init__.py CHANGELOG.md
108
+ git commit -m "release: v${{ steps.version.outputs.new }}"
109
+ git tag "v${{ steps.version.outputs.new }}"
110
+ git push origin main --tags
111
+
112
+ - name: Create GitHub Release
113
+ env:
114
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115
+ run: |
116
+ gh release create "v${{ steps.version.outputs.new }}" dist/* \
117
+ --title "v${{ steps.version.outputs.new }}" \
118
+ --generate-notes
119
+
120
+ - name: Publish to PyPI
121
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,33 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ *.egg
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+ ENV/
16
+
17
+ # IDE
18
+ .idea/
19
+ .vscode/
20
+ *.swp
21
+ *.swo
22
+
23
+ # Testing
24
+ .pytest_cache/
25
+ .coverage
26
+ htmlcov/
27
+
28
+ # mypy
29
+ .mypy_cache/
30
+
31
+ # claude code local settings
32
+ .claude/settings.local.json
33
+ .codex/
@@ -0,0 +1,2 @@
1
+ /cache
2
+ /project.local.yml
@@ -0,0 +1,135 @@
1
+ # the name by which the project can be referenced within Serena
2
+ project_name: "ecsctx"
3
+
4
+
5
+ # list of languages for which language servers are started; choose from:
6
+ # al bash clojure cpp csharp
7
+ # csharp_omnisharp dart elixir elm erlang
8
+ # fortran fsharp go groovy haskell
9
+ # java julia kotlin lua markdown
10
+ # matlab nix pascal perl php
11
+ # php_phpactor powershell python python_jedi r
12
+ # rego ruby ruby_solargraph rust scala
13
+ # swift terraform toml typescript typescript_vts
14
+ # vue yaml zig
15
+ # (This list may be outdated. For the current list, see values of Language enum here:
16
+ # https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py
17
+ # For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
18
+ # Note:
19
+ # - For C, use cpp
20
+ # - For JavaScript, use typescript
21
+ # - For Free Pascal/Lazarus, use pascal
22
+ # Special requirements:
23
+ # Some languages require additional setup/installations.
24
+ # See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
25
+ # When using multiple languages, the first language server that supports a given file will be used for that file.
26
+ # The first language is the default language and the respective language server will be used as a fallback.
27
+ # Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
28
+ languages:
29
+ - python
30
+
31
+ # the encoding used by text files in the project
32
+ # For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
33
+ encoding: "utf-8"
34
+
35
+ # line ending convention to use when writing source files.
36
+ # Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
37
+ # This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
38
+ line_ending:
39
+
40
+ # The language backend to use for this project.
41
+ # If not set, the global setting from serena_config.yml is used.
42
+ # Valid values: LSP, JetBrains
43
+ # Note: the backend is fixed at startup. If a project with a different backend
44
+ # is activated post-init, an error will be returned.
45
+ language_backend:
46
+
47
+ # whether to use project's .gitignore files to ignore files
48
+ ignore_all_files_in_gitignore: true
49
+
50
+ # list of additional paths to ignore in this project.
51
+ # Same syntax as gitignore, so you can use * and **.
52
+ # Note: global ignored_paths from serena_config.yml are also applied additively.
53
+ ignored_paths: []
54
+
55
+ # whether the project is in read-only mode
56
+ # If set to true, all editing tools will be disabled and attempts to use them will result in an error
57
+ # Added on 2025-04-18
58
+ read_only: false
59
+
60
+ # list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
61
+ # Below is the complete list of tools for convenience.
62
+ # To make sure you have the latest list of tools, and to view their descriptions,
63
+ # execute `uv run scripts/print_tool_overview.py`.
64
+ #
65
+ # * `activate_project`: Activates a project by name.
66
+ # * `check_onboarding_performed`: Checks whether project onboarding was already performed.
67
+ # * `create_text_file`: Creates/overwrites a file in the project directory.
68
+ # * `delete_lines`: Deletes a range of lines within a file.
69
+ # * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
70
+ # * `execute_shell_command`: Executes a shell command.
71
+ # * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
72
+ # * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
73
+ # * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
74
+ # * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
75
+ # * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
76
+ # * `initial_instructions`: Gets the initial instructions for the current project.
77
+ # Should only be used in settings where the system prompt cannot be set,
78
+ # e.g. in clients you have no control over, like Claude Desktop.
79
+ # * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
80
+ # * `insert_at_line`: Inserts content at a given line in a file.
81
+ # * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
82
+ # * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
83
+ # * `list_memories`: Lists memories in Serena's project-specific memory store.
84
+ # * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
85
+ # * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
86
+ # * `read_file`: Reads a file within the project directory.
87
+ # * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
88
+ # * `remove_project`: Removes a project from the Serena configuration.
89
+ # * `replace_lines`: Replaces a range of lines within a file with new content.
90
+ # * `replace_symbol_body`: Replaces the full definition of a symbol.
91
+ # * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
92
+ # * `search_for_pattern`: Performs a search for a pattern in the project.
93
+ # * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
94
+ # * `switch_modes`: Activates modes by providing a list of their names
95
+ # * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
96
+ # * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
97
+ # * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
98
+ # * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
99
+ excluded_tools: []
100
+
101
+ # list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default)
102
+ included_optional_tools: []
103
+
104
+ # fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
105
+ # This cannot be combined with non-empty excluded_tools or included_optional_tools.
106
+ fixed_tools: []
107
+
108
+ # list of mode names to that are always to be included in the set of active modes
109
+ # The full set of modes to be activated is base_modes + default_modes.
110
+ # If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.
111
+ # Otherwise, this setting overrides the global configuration.
112
+ # Set this to [] to disable base modes for this project.
113
+ # Set this to a list of mode names to always include the respective modes for this project.
114
+ base_modes:
115
+
116
+ # list of mode names that are to be activated by default.
117
+ # The full set of modes to be activated is base_modes + default_modes.
118
+ # If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.
119
+ # Otherwise, this overrides the setting from the global configuration (serena_config.yml).
120
+ # This setting can, in turn, be overridden by CLI parameters (--mode).
121
+ default_modes:
122
+
123
+ # initial prompt for the project. It will always be given to the LLM upon activating the project
124
+ # (contrary to the memories, which are loaded on demand).
125
+ initial_prompt: ""
126
+
127
+ # time budget (seconds) per tool call for the retrieval of additional symbol information
128
+ # such as docstrings or parameter information.
129
+ # This overrides the corresponding setting in the global configuration; see the documentation there.
130
+ # If null or missing, use the setting from the global configuration.
131
+ symbol_info_budget:
132
+
133
+ # list of regex patterns which, when matched, mark a memory entry as read‑only.
134
+ # Extends the list from the global configuration, merging the two lists.
135
+ read_only_memory_patterns: []
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ ## v0.4.1 (2026-03-12)
4
+
5
+ ### Features
6
+ - feat: enhance LoggingContext with labels support and reshape log event structure (e6ccb7b)
7
+ - feat: add timeout configuration for Vault HTTP requests and enhance PII provider documentation (2b043aa)
8
+ - feat: enhance PII configuration with environment variable support and access mode handling (ca3701c)
9
+ - feat: add PII tokenization and encryption module with normalization and keyset provider (73b0ebf)
10
+ - Merge pull request #5 from ottuco/readme_file_updated (dca15f0)
11
+ - feat : README.md file got updated. (2377b4a)
12
+ - feat(django): add Django middleware and processors with lazy settings loading (657f0f2)
13
+ - feat(django): add plug-and-play LOGGING configuration (99df5cf)
14
+ - feat: initial logctx package (4d18526)
15
+
16
+ ### Fixes
17
+ - fix: enhance logging context reset handling to suppress RuntimeError (d33984b)
18
+ - fix: make Django processors read settings lazily (f53a486)
19
+ - fix: avoid circular import in django __init__.py (c71fb03)
20
+
21
+ ### Other
22
+ - ci: add changelog generation to release workflow (996e000)
23
+ - refactor: rename logctx to ecsctx and update imports across the codebase (b95f626)
24
+ - refactor: rename logctx to ecsctx and update imports across the codebase (6b96482)
25
+ - Merge branch 'main' of github.com:ottuco/logctx (6b8f2de)
26
+ - Merge pull request #4 from ottuco/149309 (6167126)
27
+ - Fix: deep merge extra dict in LoggingContext.evolve() to preserve nested keys (63b72c5)
28
+ - Add: Celery context propagation utilities for logging context management (57f22de)
29
+ - Merge pull request #3 from ottuco/origin/Task-147936 (8a9ca7f)
30
+ - Add : missing `__doc__` (146517d)
31
+ - Update : `api_logging` decorator updated. (#2) (cc64510)
32
+ - Add : User Object serialization (#1) (69e457b)
33
+ - refactor: update LoggingContext attributes and ECS mapping for improved clarity (1a7da7c)
34
+ - refactor: simplify contextvars_injector and update README for dynamic merchant_id binding (16a5dbf)
35
+ - refactor: separate Django-specific code into contrib/django (56be223)
36
+
ecsctx-0.4.1/CLAUDE.md ADDED
@@ -0,0 +1,22 @@
1
+ # ecsctx
2
+
3
+ ECS-compliant structured logging with W3C Trace Context support. Framework-agnostic core with Django integration.
4
+
5
+ ## Entry Points
6
+ - `ecsctx/__init__.py` - All public exports
7
+ - `ecsctx/contrib/django/` - Django middleware and processors
8
+
9
+ ## Critical Context
10
+ - `LoggingContext.to_dict()` maps internal attrs to ECS fields (span_id→span.id, user_id→user.id, ip→client.ip)
11
+ - Processor injection order: explicit kwargs > LoggingContext > structlog contextvars > CID trace_id > service metadata
12
+ - `mask_sensitive_data` uses reversible Fernet encryption (not hashing) - requires `LOG_TOKENIZE_SECRET`
13
+ - Django `contextvars_injector` reads settings lazily to avoid circular imports during bootstrap
14
+
15
+ ## Submodules
16
+ - `ecsctx/` - Core module (context, processors, formatters)
17
+ - `ecsctx/contrib/django/` - Django middleware, lazy-loading processors, auditlog binder
18
+
19
+ ## Footguns ⚠️
20
+ - ECS reserved fields (`client`, `user`, `host`, `span`, `trace`) must be nested objects, never flat strings
21
+ - Django's `LogContextBinder` must be imported explicitly (not in `__init__.py`) to avoid circular imports
22
+ - `LoggingContextMiddleware` must be placed AFTER auth middleware to capture user_id
ecsctx-0.4.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ottu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.