This repository was archived by the owner on Sep 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
stats/exporters/ocagent: implement exporter #525
Copy link
Copy link
Closed
Description
Currently we've only got the ocagent trace exporter. It would be nice to have once for stats too so that we can start to use the OpenCensus Agent.
I see #454 open but that issue will involve doing a bunch of double work since it is almost rewriting those exporters. With the ocagent exporter converts stats aka view_data to OpenCensus Proto Metrics, folks can then switch over to just using the agent.
I am coming here as I am currently writing the guide for the new OpenCensus Redis-Py wrapper https://pypi.org/project/ocredis/ and it works great with the Trace exporter i.e.
#!/usr/bin/env python
import ocredis
from opencensus.trace.tracer import Tracer
from opencensus.trace.exporters.ocagent.trace_exporter import TraceExporter
from opencensus.trace.samplers import always_on
from opencensus.common.transports import async_
def create_opencensus_exporters_and_tracer():
# Create the ocagent-exporter that'll upload our traces
# to the OpenCensus Agent.
octe = TraceExporter(service_name='pysearch', transport=async_.AsyncTransport)
tracer_init_args = dict(exporter=octe,
# Always sampling for demo purposes.
sampler=always_on.AlwaysOnSampler())
return tracer_init_args
def main():
r = ocredis.OcRedis(host='localhost', port=6379, db=10)
tracer_init_args = create_opencensus_exporters_and_tracer()
while True:
query = raw_input('$ ')
response = do_search(r, query, **tracer_init_args)
print('> ' + response + '\n')
def do_search(client, query, **tracer_init_kwargs):
tracer = Tracer(**tracer_init_kwargs)
with tracer.span('Search') as span:
span.add_annotation('Searching', query=query)
# Check Redis if we've already memoized the response.
response = client.get(query)
if response is not None: # Cache hit
span.add_annotation('Cache hit', store='redis', client='redis-py')
print('Cache hit! Now deleting it to make for a cache miss later')
# Clear the response so that the next search will return a cache-miss.
client.delete(query)
else: # Cache miss
span.add_annotation('Cache miss', store='redis', client='redis-py')
print('Cache miss! Now processing and memoizing it to make for a cache hit later')
# Now process the result and memoize it.
response = query.upper()
client.set(query, response)
span.finish()
return response
if __name__ == '__main__':
main()but after writing that, I came over to use the ocagent-stats exporter but didn't find any.
Reactions are currently unavailable