Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

61 Zeilen
1.5 KiB

  1. // Copyright 2017, OpenCensus Authors
  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. // Command jaeger is an example program that creates spans
  15. // and uploads to Jaeger.
  16. package main
  17. import (
  18. "context"
  19. "log"
  20. "go.opencensus.io/exporter/jaeger"
  21. "go.opencensus.io/trace"
  22. )
  23. func main() {
  24. ctx := context.Background()
  25. // Register the Jaeger exporter to be able to retrieve
  26. // the collected spans.
  27. exporter, err := jaeger.NewExporter(jaeger.Options{
  28. Endpoint: "http://localhost:14268",
  29. Process: jaeger.Process{
  30. ServiceName: "trace-demo",
  31. },
  32. })
  33. if err != nil {
  34. log.Fatal(err)
  35. }
  36. trace.RegisterExporter(exporter)
  37. // For demoing purposes, always sample. In a production application, you should
  38. // configure this to a trace.ProbabilitySampler set at the desired
  39. // probability.
  40. trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
  41. ctx, span := trace.StartSpan(ctx, "/foo")
  42. bar(ctx)
  43. span.End()
  44. exporter.Flush()
  45. }
  46. func bar(ctx context.Context) {
  47. ctx, span := trace.StartSpan(ctx, "/bar")
  48. defer span.End()
  49. // Do bar...
  50. }