reddit / baseplate.py

reddit's python service framework
https://baseplate.readthedocs.io
BSD 3-Clause "New" or "Revised" License
539 stars 173 forks source link

Feat: KV store on RequestContext class #964

Closed trevorriles closed 1 month ago

trevorriles commented 1 month ago

Add a kv field to the baseplate RequestContext object to allow passing arbitrary data.

This can be used to explicitly pass opentelemetry context across processes, for example with our internal graphql codebase we can do things like:

Attach to context in kv store

trace.context_api.attach(context.kv["otel"])

Store span in context:

trace.set_span_in_context(span, context.kv["otel"])

Of course this can be used for other non-tracing purposes as well.

trevorriles commented 1 month ago

@chriskuehl I'm going to close this for now. I put this together to solve a specific issue I had within graphql. I'm going to see if I can solve it with out introducing functionality that might increase confusion within bp.py core.

I may be back with something similar as I begin to work with the graphql team, but we don't need this in the upcoming release.