Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad AppMaps generated #341

Closed
apotterri opened this issue Jun 19, 2024 · 2 comments · Fixed by #350
Closed

bad AppMaps generated #341

apotterri opened this issue Jun 19, 2024 · 2 comments · Fixed by #350
Assignees

Comments

@apotterri
Copy link
Collaborator

There is some circumstance (or maybe more than one) under which the agent generates an AppMap with an incorrect structure.

This appears to be related to an exception being thrown when an HTTP request is processed. The simplest example we've found so far appears to be https://github.com/getappmap/vscode-appland/blob/d9b9c325edb40791d94353ccd3541baab1d241fa/test/fixtures/workspaces/project-external-service/tmp/appmap/external_service_example.appmap.json, but there are others listed in getappmap/appmap-js#1824

@zermelo-wisen
Copy link
Collaborator

These AppMaps seems to break this rule: Parent call of a return event is the closest preceding, not yet matched call event in the event array.

They create this incorrect structure with their event order in events array:

┌─── call #1
│┌─── call #2
└┼── ret #3
 └─── ret #4

Instead of this:

┌── call #1
│ ┌── call #2
│ └── ret #3
└── ret #4

@zermelo-wisen
Copy link
Collaborator

An AppMap can be checked with this script:

import argparse
import json


def check(events):
    stack = []
    for e in events:
        if e["event"] == "call":
            stack.append(e)
        elif e["event"] == "return":
            if len(stack) > 0:
                call = stack.pop()
                if call["id"] != e["parent_id"]:
                    return f"Unbalanced call.id:{call['id']} != return.parent_id:{e['parent_id']} return.id:{e['id']}"
            else:
                return "Unbalanced"
    if len(stack) == 0:
        return "Balanced"
    else:
        return "Unbalanced"


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Check if AppMap events are balanced.")
    parser.add_argument("file", type=str, help="Path to AppMap JSON file")
    args = parser.parse_args()

    with open(args.file, "r", encoding="UTF8") as f:
        data = json.load(f)
        events = data["events"]

    result = check(events)
    print(result)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants