Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# appmap-python

Python agent for AppMap. Records function calls, HTTP requests, SQL queries, parameters, return values, and exceptions into `.appmap.json` files.

## Running tests

Tests must be run via `tox` or the `appmap-python` wrapper, not bare `pytest`. The wrapper sets `APPMAP=true`, which is required for conditional imports in `appmap/__init__.py` (e.g. `generation`). Subprocess-based tests also need the `appmap-python` script in PATH.

```sh
# Correct - via tox (how CI runs them)
tox

# Correct - via appmap-python wrapper
appmap-python pytest

# Also works for quick local iteration on non-subprocess tests
APPMAP=true .venv/bin/python -m pytest _appmap/test/test_events.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note many tests require APPMAP_DISPLAY_PARAMS=true (which tox sets across the board).

Also note uv run is an alternative to using venv directly.


# WRONG - will fail on subprocess tests
pytest
```

## Project structure

- `appmap/` - Public package entry point (conditional imports based on APPMAP env var)
- `_appmap/` - Internal implementation (event recording, instrumentation, web framework integration)
- `_appmap/test/` - Test suite
- `_appmap/test/data/` - Test fixtures and expected appmap JSON files
8 changes: 4 additions & 4 deletions _appmap/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def _should_display(has_labels):

def display_string(val, has_labels=False):
# If we're asked to display parameters, make a best-effort attempt
# to get a string value for the parameter using repr(). If parameter
# display is disabled, or repr() has raised, just formulate a value
# from the class and id.
# to get a string value for the parameter. str types are returned as-is;
# other types use repr(). If parameter display is disabled, or repr() has
# raised, just formulate a value from the class and id.
value = None
if _should_display(has_labels):
try:
value = repr(val)
value = val if issubclass(type(val), str) else repr(val)
except Exception: # pylint: disable=broad-except
pass

Expand Down
18 changes: 9 additions & 9 deletions _appmap/test/data/expected.appmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'ExampleClass.static_method\\n...\\n'"
"value": "ExampleClass.static_method\n...\n"
},
"parent_id": 1,
"id": 2,
Expand All @@ -49,7 +49,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'ClassMethodMixin#class_method, cls ExampleClass'"
"value": "ClassMethodMixin#class_method, cls ExampleClass"
},
"parent_id": 3,
"id": 4,
Expand All @@ -75,7 +75,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Super#instance_method'"
"value": "Super#instance_method"
},
"parent_id": 5,
"id": 6,
Expand Down Expand Up @@ -127,7 +127,7 @@
"name": "data",
"kind": "req",
"class": "builtins.str",
"value": "'ExampleClass.call_yaml'"
"value": "ExampleClass.call_yaml"
}
],
"id": 10,
Expand All @@ -144,7 +144,7 @@
"name": "data",
"kind": "req",
"class": "builtins.str",
"value": "'ExampleClass.call_yaml'"
"value": "ExampleClass.call_yaml"
},
{
"name": "stream",
Expand Down Expand Up @@ -176,7 +176,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'ExampleClass.call_yaml\\n...\\n'"
"value": "ExampleClass.call_yaml\n...\n"
},
"parent_id": 11,
"id": 12,
Expand All @@ -190,7 +190,7 @@
"name": "data",
"kind": "req",
"class": "builtins.str",
"value": "'ExampleClass.call_yaml'"
"value": "ExampleClass.call_yaml"
},
{
"name": "stream",
Expand Down Expand Up @@ -222,7 +222,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'ExampleClass.call_yaml\\n...\\n'"
"value": "ExampleClass.call_yaml\n...\n"
},
"parent_id": 13,
"id": 14,
Expand Down Expand Up @@ -334,4 +334,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Hello'"
"value": "Hello"
},
"parent_id": 2,
"id": 3,
Expand All @@ -83,7 +83,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'world!'"
"value": "world!"
},
"parent_id": 4,
"id": 5,
Expand All @@ -93,7 +93,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Hello world!'"
"value": "Hello world!"
},
"parent_id": 1,
"id": 6,
Expand Down Expand Up @@ -239,4 +239,4 @@
]
}
]
}
}
8 changes: 4 additions & 4 deletions _appmap/test/data/pytest/expected/pytest-numpy1.appmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
{
"return_value": {
"value": "'Hello'",
"value": "Hello",
"class": "builtins.str"
},
"parent_id": 3,
Expand All @@ -93,7 +93,7 @@
},
{
"return_value": {
"value": "'world!'",
"value": "world!",
"class": "builtins.str"
},
"parent_id": 5,
Expand All @@ -103,7 +103,7 @@
},
{
"return_value": {
"value": "'Hello world!'",
"value": "Hello world!",
"class": "builtins.str"
},
"parent_id": 2,
Expand Down Expand Up @@ -278,4 +278,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Hello'"
"value": "Hello"
},
"parent_id": 2,
"id": 3,
Expand All @@ -83,7 +83,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'world!'"
"value": "world!"
},
"parent_id": 4,
"id": 5,
Expand All @@ -93,7 +93,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Hello world!'"
"value": "Hello world!"
},
"parent_id": 1,
"id": 6,
Expand Down Expand Up @@ -239,4 +239,4 @@
]
}
]
}
}
8 changes: 4 additions & 4 deletions _appmap/test/data/pytest/expected/pytest-numpy2.appmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
{
"return_value": {
"value": "'Hello'",
"value": "Hello",
"class": "builtins.str"
},
"parent_id": 3,
Expand All @@ -93,7 +93,7 @@
},
{
"return_value": {
"value": "'world!'",
"value": "world!",
"class": "builtins.str"
},
"parent_id": 5,
Expand All @@ -103,7 +103,7 @@
},
{
"return_value": {
"value": "'Hello world!'",
"value": "Hello world!",
"class": "builtins.str"
},
"parent_id": 2,
Expand Down Expand Up @@ -278,4 +278,4 @@
]
}
]
}
}
20 changes: 11 additions & 9 deletions _appmap/test/data/unittest/expected/pytest.appmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
"class": "simple.Simple",
"value": "<simple.Simple object at 0xabcdef>"
},
"parameters": [{
"class": "builtins.str",
"kind": "req",
"name": "bang",
"value": "'!'"
}],
"parameters": [
{
"class": "builtins.str",
"kind": "req",
"name": "bang",
"value": "!"
}
],
"id": 2,
"event": "call",
"thread_id": 1
Expand All @@ -83,7 +85,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Hello'"
"value": "Hello"
},
"parent_id": 3,
"id": 4,
Expand All @@ -110,7 +112,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'world'"
"value": "world"
},
"parent_id": 5,
"id": 6,
Expand All @@ -120,7 +122,7 @@
{
"return_value": {
"class": "builtins.str",
"value": "'Hello world!'"
"value": "Hello world!"
},
"parent_id": 2,
"id": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"parameters": [
{
"kind": "req",
"value": "'!'",
"value": "!",
"name": "bang",
"class": "builtins.str"
}
Expand Down Expand Up @@ -67,7 +67,7 @@
},
{
"return_value": {
"value": "'Hello'",
"value": "Hello",
"class": "builtins.str"
},
"parent_id": 2,
Expand All @@ -94,7 +94,7 @@
},
{
"return_value": {
"value": "'world'",
"value": "world",
"class": "builtins.str"
},
"parent_id": 4,
Expand All @@ -104,7 +104,7 @@
},
{
"return_value": {
"value": "'Hello world!'",
"value": "Hello world!",
"class": "builtins.str"
},
"parent_id": 1,
Expand Down Expand Up @@ -145,4 +145,4 @@
]
}
]
}
}
Loading
Loading