Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shareed2k/fiber_tracing
fiber_tracing is middleware for fiber framework
https://github.com/shareed2k/fiber_tracing
fiber-framework jaeger middleware opentracing tracing
Last synced: 3 days ago
JSON representation
fiber_tracing is middleware for fiber framework
- Host: GitHub
- URL: https://github.com/shareed2k/fiber_tracing
- Owner: Shareed2k
- License: mit
- Created: 2020-04-30T14:49:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-27T14:26:06.000Z (8 months ago)
- Last Synced: 2024-08-04T01:06:26.362Z (3 months ago)
- Topics: fiber-framework, jaeger, middleware, opentracing, tracing
- Language: Go
- Homepage:
- Size: 59.6 KB
- Stars: 12
- Watchers: 3
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fiber - shareed2k/fiber_tracing - Middleware trace requests on Fiber framework with OpenTracing API. (⚙️ Middlewares / 🌱 Third Party)
README
## fiber_tracing is middleware for fiber framework
fiber_tracing Middleware trace requests on [Fiber framework](https://gofiber.io/) with OpenTracing API.
You can use every tracer that implement OpenTracing interface### Install
```
go get -u github.com/gofiber/fiber
go get -u github.com/shareed2k/fiber_tracing
```### Config
| Property | Type | Description | Default |
| :--- | :--- | :--- | :--- |
| Tracer | `opentracing.Tracer` | initializes an opentracing tracer., possible values: `jaeger`, `lightstep`, `instana`, `basictracer-go`, ... | `"&opentracing.NoopTracer{}"` |
| OperationName | `func(*fiber.Ctx) string` | Span operation name | `"HTTP " + ctx.Method() + " URL: " + ctx.Path()` |
| ComponentName | `string` | Used for describing the tracing component name | `fiber/v2` |
| ParentSpanKey | `string` | context key string used to get span scoped to the request | `#defaultTracingParentSpanKey` |
| Filter | `func(*fiber.Ctx) bool` | Defines a function to skip middleware. | `nil` |
| Modify | `func(*fiber.Ctx, opentracing.Span)` | Defines a function to edit span like add tags or logs... | `span.SetTag("http.remote_addr", ctx.IP()) ...` |### Example
```go
package mainimport (
"github.com/gofiber/fiber"
"github.com/shareed2k/fiber_tracing"
"github.com/uber/jaeger-client-go/config"
)func main() {
app := fiber.New()defcfg := config.Configuration{
ServiceName: "fiber-tracer",
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &config.ReporterConfig{
LogSpans: true,
BufferFlushInterval: 1 * time.Second,
},
}
cfg, err := defcfg.FromEnv()
if err != nil {
panic("Could not parse Jaeger env vars: " + err.Error())
}
tracer, closer, err := cfg.NewTracer()
if err != nil {
panic("Could not initialize jaeger tracer: " + err.Error())
}defer closer.Close()
app.Use(fiber_tracing.NewWithConfig(fiber_tracing.Config{
Tracer: tracer,
}))// or
/*
app.Use(fiber_tracing.New(tracer))
*/app.Get("/", func(c *fiber.Ctx) {
c.Send("Welcome!")
})app.Listen(3000)
}
```### Example 2 with jaeger default tracer
```go
package mainimport (
"github.com/gofiber/fiber"
"github.com/shareed2k/fiber_tracing"
"github.com/uber/jaeger-client-go/config"
)func main() {
app := fiber.New()closer := fiber_tracing.NewWithJaegerTracer(app)
defer closer.Close()app.Get("/", func(c *fiber.Ctx) {
c.Send("Welcome!")
})app.Listen(3000)
}
```