https://dagster.io/ logo
#ask-community
Title
# ask-community
m

Mike Atlas

12/16/2022, 5:35 PM
Is it possible to extend
dagster.OpExecutionContext
to add a member to the
context
without using a resource definition? I'm considering ways to implement some metrics and pretty much want the dependency to always be available just like the
log
member is in the context.
j

jamie

12/16/2022, 5:44 PM
hey @Mike Atlas I think that would be pretty difficult since the dagster code creates and provides the
context
object for each op/asset and there isn’t a way to customize how that context is created. one thing you could consider is writing a custom decorator that wraps
@op
or
@asset
that always adds a
required_resource_key
for the member you want to add. then that would be available to all of your ops and assets
🌈 1
m

Mike Atlas

12/16/2022, 5:49 PM
Nice idea @jamie thanks. Got it... yeah, I've already gone off and started implementing my metrics object as a resource, since it's the lowest friction way I can see to achieve it
I was hoping not to need to bother adding resource defs for every job for the metrics resource, but that's "ok"
Perhaps my feature enhancement request might be a mechanism for a global resource definition ?
🤷‍♂️
j

jamie

12/16/2022, 5:52 PM
yeah i could see that being useful. We’re doing some work on the resource system in early 2023, so if you want to open a GH feature request for the global resource idea we’d definitely consider it as part of the revamp
🌈 1
m

Mike Atlas

12/16/2022, 5:53 PM
will do
Another idea @jamie is that I could abuse the default
log
object and extend it with my own methods to log metrics?
Copy code
@repository(default_logger_defs=MyMetricsEnhancedLogger)
j

jamie

12/16/2022, 6:06 PM
yeah that might work. I’m not deeply familiar with custom loggers, so I don’t know what, if any, issues you might run into with that. @owen might be able to help a bit
m

Mike Atlas

12/16/2022, 6:09 PM
User-defined custom log levels are not supported, and calls to, e.g.,
context.log.trace
or
context.log.notice
will result in hard exceptions at runtime.
hmm maybe not ahaha
I guess ... if I define a custom logger and abuse the
.info
level (or any other level) I could then pipe in a json string of metrics, but that's gross
anyway thank you for the responses!
j

jamie

12/16/2022, 6:40 PM
yeah that all sounds pretty unpleasant. if the custom decorator method seems possible for you i’d give that a try! we did something similar at my previous company and it worked well
👍 1
m

Mike Atlas

12/16/2022, 6:44 PM
I think my enhancement request will just be to support a generic telemetry provider, such as https://opentelemetry.io/docs/instrumentation/python/
❤️ 2
5 Views