Пример #1
0
    def record_delete(self):
        if not self.recording.is_running():
            return 'No recording is in progress', 404

        self.recording.stop()

        return json.loads(generation.dump(self.recording))
Пример #2
0
    def record(self, klass, method, **kwds):
        if not env.Env.current.enabled:
            yield
            return

        self.appmap_path = Path(env.Env.current.output_dir) / self.name
        self.appmap_path.mkdir(parents=True, exist_ok=True)

        framework = {'name': self.name}
        if self.version is not None:
            framework['version'] = self.version

        self.metadata = {
            'app': configuration.Config().name,
            'frameworks': [framework],
            'recorder': {
                'name': self.name
            }
        }

        rec = recording.Recording()
        with rec:
            yield

        fi = FuncItem(klass, method, **kwds)
        filename = fi.filename + '.appmap.json'
        metadata = fi.metadata
        metadata.update(self.metadata)
        (self.appmap_path / filename).write_text(generation.dump(rec, metadata))
Пример #3
0
    def record(self, klass, method, **kwds):
        if not env.Env.current.enabled:
            yield
            return

        Metadata.add_framework(self.name, self.version)

        item = FuncItem(klass, method, **kwds)

        metadata = item.metadata
        metadata.update({
            'app': configuration.Config().name,
            'recorder': {
                'name': self.name
            }
        })

        rec = recording.Recording()
        try:
            with rec:
                yield metadata
        finally:
            basedir = env.Env.current.output_dir / self.name
            write_appmap(basedir, item.filename,
                         generation.dump(rec, metadata))
Пример #4
0
    def test_labeled_function(self, monkeypatch):
        def check_labels(self, to_dict):
            if self.name == 'labeled_method':
                assert list(self.labels) == ['super', 'important']
            elif self.name == 'instance_method':
                assert not self.labels
            ret = to_dict(self)
            return ret

        monkeypatch.setattr(
            generation.FuncEntry, 'to_dict',
            partialmethod(check_labels, generation.FuncEntry.to_dict))

        from example_class import ExampleClass  # pylint: disable=import-error
        rec = appmap.Recording()
        with rec:
            ExampleClass().labeled_method()
            ExampleClass().instance_method()

        generation.dump(rec)
Пример #5
0
    def _generate(check_fn, method_name):
        monkeypatch.setattr(generation.FuncEntry, 'to_dict',
                            partialmethod(
                                check_fn,
                                generation.FuncEntry.to_dict))

        from example_class import ExampleClass  # pylint: disable=import-error
        rec = appmap.Recording()
        with rec:
            m = getattr(ExampleClass(), method_name)
            m()

        return generation.dump(rec)
Пример #6
0
    def recording(self, request):
        """Handle recording requests."""
        if request.method == 'GET':
            return JsonResponse({'enabled': self.recorder.enabled})
        if request.method == 'POST':
            if self.recorder.enabled:
                return HttpResponse('Recording is already in progress',
                                    status=409)
            self.recorder.clear()
            self.recorder.start_recording()
            return HttpResponse()

        if request.method == 'DELETE':
            if not self.recorder.enabled:
                return HttpResponse('No recording is in progress', status=404)

            self.recorder.stop_recording()
            return HttpResponse(generation.dump(self.recorder),
                                content_type='application/json')

        return HttpResponseBadRequest()