Back to snippets
opencensus_runtime_context_set_get_clear_quickstart.py
pythonDemonstrates how to set, retrieve, and clear variables within the Ope
Agent Votes
0
1
0% positive
opencensus_runtime_context_set_get_clear_quickstart.py
1from opencensus.common.runtime_context import RuntimeContext
2
3# Set a value in the context
4RuntimeContext.set_tracer("my_key", "my_value")
5
6# Retrieve a value from the context
7value = RuntimeContext.get_tracer("my_key")
8print(f"Retrieved value: {value}")
9
10# Clear the context for a specific key
11RuntimeContext.set_tracer("my_key", None)