ocecho

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2020 License: Apache-2.0 Imports: 12 Imported by: 1

README

ocecho

OpenCensus instrumentation for Echo framework

License

The Echo middlleware provide OpenCensus instrumentations. It provide tracing and metrics features as same as ochttp. Heavily inspired ochttp official plugin. Many parts of ocecho has been copied from ochttp.

Thanks for authors of ochttp.

Installation

Requires Go 1.12 or later.

go get github.com/HatsuneMiku3939/ocecho

Usage example

// ocecho Middleware
e.Use(ocecho.OpenCensusMiddleware(
    ocecho.OpenCensusConfig{
        Skipper: middleware.DefaultSkipper,
        TraceOptions: ocecho.TraceOptions{
            IsPublicEndpoint: true,
            Propagation:      &b3.HTTPFormat{},
            StartOptions:     trace.StartOptions{},
        },
    },
))

// Register server views
if err := view.Register(ocecho.DefaultServerViews...); err != nil {
    log.Fatalf("Error creating metric views: %v", err)
}

You can found whole example in examples.

Release History

  • 0.3.2
    • Add default Propagation option
  • 0.3.1
    • fix nill reference
  • 0.3.0
    • Broke v0.2.0 compatibility
    • Add Skipper option
    • Update echo.v4
  • 0.2.0
    • Add IsPublicEndpoint option
    • Fix Span name as same as ochttp
  • 0.1.1
    • Fix RequestSize, ResponseSize metric bug
  • 0.1.0
    • Initial release

TODO

  • Add unittest

Meta

Distributed under the Apache license. See LICENSE for more information.

https://github.com/HatsuneMiku3939/

Contributing

  1. Fork it (https://github.com/HatsuneMiku3939/ocecho/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Documentation

Index

Constants

View Source
const (
	HostAttribute       = "http.host"
	MethodAttribute     = "http.method"
	PathAttribute       = "http.path"
	URLAttribute        = "http.url"
	UserAgentAttribute  = "http.user_agent"
	StatusCodeAttribute = "http.status_code"
)

Variables

View Source
var (
	Host           = tag.MustNewKey("http.host")
	StatusCode     = tag.MustNewKey("http.status")
	Path           = tag.MustNewKey("http.path")
	Method         = tag.MustNewKey("http.method")
	KeyServerRoute = tag.MustNewKey("http_server_route")
)
View Source
var (
	ServerRequestCount = stats.Int64(
		"opencensus.io/http/server/request_count",
		"Number of HTTP requests started",
		stats.UnitDimensionless)
	ServerRequestBytes = stats.Int64(
		"opencensus.io/http/server/request_bytes",
		"HTTP request body size if set as ContentLength (uncompressed)",
		stats.UnitBytes)
	ServerResponseBytes = stats.Int64(
		"opencensus.io/http/server/response_bytes",
		"HTTP response body size (uncompressed)",
		stats.UnitBytes)
	ServerLatency = stats.Float64(
		"opencensus.io/http/server/latency",
		"End-to-end latency",
		stats.UnitMilliseconds)
)
View Source
var (
	ServerRequestCountView = &view.View{
		Name:        "opencensus.io/http/server/request_count",
		Description: "Count of HTTP requests started",
		Measure:     ServerRequestCount,
		Aggregation: view.Count(),
	}

	ServerRequestBytesView = &view.View{
		Name:        "opencensus.io/http/server/request_bytes",
		Description: "Size distribution of HTTP request body",
		Measure:     ServerRequestBytes,
		Aggregation: DefaultSizeDistribution,
	}

	ServerResponseBytesView = &view.View{
		Name:        "opencensus.io/http/server/response_bytes",
		Description: "Size distribution of HTTP response body",
		Measure:     ServerResponseBytes,
		Aggregation: DefaultSizeDistribution,
	}

	ServerLatencyView = &view.View{
		Name:        "opencensus.io/http/server/latency",
		Description: "Latency distribution of HTTP requests",
		Measure:     ServerLatency,
		Aggregation: DefaultLatencyDistribution,
	}

	ServerRequestCountByMethod = &view.View{
		Name:        "opencensus.io/http/server/request_count_by_method",
		Description: "Server request count by HTTP method",
		TagKeys:     []tag.Key{Method},
		Measure:     ServerRequestCount,
		Aggregation: view.Count(),
	}

	ServerResponseCountByStatusCode = &view.View{
		Name:        "opencensus.io/http/server/response_count_by_status_code",
		Description: "Server response count by status code",
		TagKeys:     []tag.Key{StatusCode},
		Measure:     ServerLatency,
		Aggregation: view.Count(),
	}
)
View Source
var (
	DefaultSizeDistribution    = view.Distribution(1024, 2048, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456, 1073741824, 4294967296)
	DefaultLatencyDistribution = view.Distribution(1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
)

Functions

func OpenCensusMiddleware

func OpenCensusMiddleware(opts OpenCensusConfig) echo.MiddlewareFunc

OpenCensusMiddleware OpenCensus trace, stats middleware

func TraceStatus

func TraceStatus(httpStatusCode int, statusLine string) trace.Status

Types

type OpenCensusConfig added in v0.3.0

type OpenCensusConfig struct {
	// Skipper defines a function to skip middleware
	Skipper middleware.Skipper

	// TraceOptions defines a Tracer options
	TraceOptions TraceOptions
}

type TraceOptions added in v0.2.0

type TraceOptions struct {
	IsPublicEndpoint bool
	Propagation      propagation.HTTPFormat
	StartOptions     trace.StartOptions
}

TraceOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL