github.com/OpsMx/go-app-base@v0.0.24/tracer/doc.go (about) 1 // Copyright 2022 OpsMx, Inc 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tracer 16 17 // The `tracer` package provides a way to get HTTP and other 18 // tracing via otel, and export to Jaeger and/or stdout. 19 // A common pattern for using: 20 // 21 // jaegerEndpoint = flag.String("jaeger-endpoint", "", "Jaeger collector endpoint") 22 // traceToStdout = flag.Bool("traceToStdout", false, "log traces to stdout") 23 // traceRatio = flag.Float64("traceRatio", 0.01, "ratio of traces to create, if incoming request is not traced") 24 // 25 // ctx, cancel := context.WithCancel(context.Background()) 26 // defer cancel() 27 // 28 // if *jaegerEndpoint != "" { 29 // *jaegerEndpoint = util.GetEnvar("JAEGER_TRACE_URL", "") 30 // } 31 // 32 // tracerProvider, err := tracer.NewTracerProvider(*jaegerEndpoint, *traceToStdout, version.GitHash(), appName, *traceRatio) 33 // util.Check(err) 34 // defer tracerProvider.Shutdown(ctx) 35 // 36 // Catching signals would also be wise, so Shutdown() can be called properly.