Hi, how do I log an `AssetMaterialization` outside...
# ask-community
c
Hi, how do I log an
AssetMaterialization
outside of a
dagit
environment?
Copy code
@op
def sample_op(context: OpExecutionContext):
    context.log_event(AssetMaterialization(
        asset_key=["aaa", "bbb", "ccc"]
    ))

context: OpExecutionContext = build_op_context()
sample_op(context)
print(context.instance.get_event_records(EventRecordsFilter(event_type=DagsterEventType.ASSET_MATERIALIZATION)))
I am running this as a normal Python code (i.e. not using
dagit
), and I could not get the context to log the AssetMaterialization. (and the last line returns an empty list)
Copy code
@op
def sample_op(context: OpExecutionContext):
    context.log_event(AssetMaterialization(asset_key=["aaa", "bbb", "ccc"]))
    return 100

@op
def sample_verification(context: OpExecutionContext, dummy: int):
    print(context.instance.get_event_records (EventRecordsFilter (event_type=DagsterEventType.ASSET_MATERIALIZATION)))

@job
def sample_job():
    dummy = sample_op()
    sample_verification(dummy)


sample_job.execute_in_process()
Something like this would work, but I can only work with it within a
job or op