Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Is adding stats.Exporter into ocagent on the schedule? #28

Closed
moooofly opened this issue Oct 19, 2018 · 9 comments
Closed

Is adding stats.Exporter into ocagent on the schedule? #28

moooofly opened this issue Oct 19, 2018 · 9 comments

Comments

@moooofly
Copy link
Contributor

moooofly commented Oct 19, 2018

hi, @odeke-em , this is what I need right now.

Just as opencensus-go-exporter-stackdriver did

@moooofly moooofly changed the title Is there adding stats.Exporter into ocagent on the schedule Is adding stats.Exporter into ocagent on the schedule? Oct 19, 2018
@odeke-em
Copy link
Contributor

@moooofly thanks for this question. We shall be implementing stats and metrics soon and we actually have a bunch of issues open for it in the opencensus-service repository, but are blocked on the protocol definitions for the services in the agent/opencensus-service :)

@moooofly
Copy link
Contributor Author

Ok, glad to hear you are on top of this. @odeke-em 😄

@odeke-em
Copy link
Contributor

Aye aye, cheers, we've got you, thanks for being vigilant and for using it! If I may ask what company are you or what's your usage of OpenCensus? Please feel free to send me an email if you'd prefer to keep the information confidential :)

@songy23
Copy link
Contributor

songy23 commented Oct 19, 2018

FYI we're waiting on one last PR to unblock the metrics service work: census-instrumentation/opencensus-proto#137.

@moooofly
Copy link
Contributor Author

hi, @odeke-em

It's ok. I'm working at LiuLiShuo, we have been working on distributed tracing system for a while, migrating from zipkin to opencensus ecosystem.

@odeke-em
Copy link
Contributor

@moooofly awesome, thanks for that confirmation!

So interestingly in a couple of hours, the OpenCensus service will be able to accept traces from Zipkin. I have finished adding that functionality in census-instrumentation/opencensus-service#111, am just waiting on that PR to be reviewed and merged but essentially you'll be able to accept Zipkin traffic and then that'll get transformed into OpenCensus spans and then exported to a backend of your choice.

@odeke-em
Copy link
Contributor

@moooofly also wow, congrats on your just recently announced IPO at the NYSE from September 27th 2018!! Hope that OpenCensus brings value to your teams and customers.

@odeke-em
Copy link
Contributor

@moooofly btw in regards to

migrating from zipkin to opencensus ecosystem.

If right now you download the latest opencensus-service as per https://github.com/census-instrumentation/opencensus-service/releases/tag/v0.0.1 you can now receive traffic from your Zipkin applications (in whatever language) that use the Zipkin /v2 API without having to change their code -- it should mostly work. The only thing that's left is tweaking the Zipkin OpenCensus-Go exporter to send over the remote endpoint but otherwise it intercepts Zipkin traffic when run at whatever address that your applications are uploading spans.

Also please feel free to add your company to https://opencensus.io/introduction/ and https://opencensus.io/community/users/ and thank you for using OpenCensus!

@odeke-em
Copy link
Contributor

odeke-em commented Dec 9, 2018

All done here as per #31 with PRs #32 #34 and here is a demo that can upload stats and transform them to metrics to the OpenCensus Agent

package main

import (
	"context"
	"log"
	"math/rand"
	"time"

	"contrib.go.opencensus.io/exporter/ocagent"
	"go.opencensus.io/stats"
	"go.opencensus.io/stats/view"
	"go.opencensus.io/trace"
)

func main() {
	oce, err := ocagent.NewExporter(ocagent.WithInsecure())
	if err != nil {
		log.Fatalf("Failed to create ocagent-exporter: %v", err)
	}

	// Enable trace exporting
	trace.RegisterExporter(oce)
	trace.ApplyConfig(trace.Config{
		DefaultSampler: trace.AlwaysSample(),
	})

	// Enable stats exporting
	view.RegisterExporter(oce)
	mLatencyMs := stats.Float64("latency", "The latency per call", "ms")
	views := []*view.View{
		{
			Name:        "ocagent/example/latency",
			Description: "The latency distribution per call",
			Measure:     mLatencyMs,
			Aggregation: view.Distribution(0, 5, 10, 20, 50, 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600),
		},
		{
			Name:        "ocagent/example/counts",
			Description: "The number of calls",
			Measure:     mLatencyMs,
			Aggregation: view.Count(),
		},
	}

	if err := view.Register(views...); err != nil {
		log.Fatalf("Failed to register the views: %v", err)
	}

	rng := rand.New(rand.NewSource(time.Now().UnixNano()))
	for {
		ctx := context.Background()
		startTime := time.Now()
		_, span := trace.StartSpan(ctx, "foo")
		time.Sleep(time.Duration(rng.Int63n(1000)) * time.Millisecond)
		span.End()
		timeSpentMs := float64(time.Since(startTime) / time.Millisecond)
		stats.Record(ctx, mLatencyMs.M(timeSpentMs))
	}
}

@odeke-em odeke-em closed this as completed Dec 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants