Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats/exporters/ocagent: implement exporter #525

Closed
odeke-em opened this issue Feb 26, 2019 · 1 comment
Closed

stats/exporters/ocagent: implement exporter #525

odeke-em opened this issue Feb 26, 2019 · 1 comment

Comments

@odeke-em
Copy link
Member

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.

@c24t
Copy link
Member

c24t commented May 2, 2019

Fixed in #617.

@c24t c24t closed this as completed May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants