選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

71 行
2.1 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. //
  15. // Package zpages implements a collection of HTML pages that display RPC stats
  16. // and trace data, and also functions to write that same data in plain text to
  17. // an io.Writer.
  18. //
  19. // Users can also embed the HTML for stats and traces in custom status pages.
  20. //
  21. // zpages are currrently work-in-process and cannot display minutely and
  22. // hourly stats correctly.
  23. //
  24. // Performance
  25. //
  26. // Installing the zpages has a performance overhead because additional traces
  27. // and stats will be collected in-process. In most cases, we expect this
  28. // overhead will not be significant but it depends on many factors, including
  29. // how many spans your process creates and how richly annotated they are.
  30. package zpages // import "go.opencensus.io/zpages"
  31. import (
  32. "net/http"
  33. "path"
  34. "sync"
  35. "go.opencensus.io/internal"
  36. )
  37. // TODO(ramonza): Remove Handler to make initialization lazy.
  38. // Handler is deprecated: Use Handle.
  39. var Handler http.Handler
  40. func init() {
  41. mux := http.NewServeMux()
  42. Handle(mux, "/")
  43. Handler = mux
  44. }
  45. // Handle adds the z-pages to the given ServeMux rooted at pathPrefix.
  46. func Handle(mux *http.ServeMux, pathPrefix string) {
  47. enable()
  48. if mux == nil {
  49. mux = http.DefaultServeMux
  50. }
  51. mux.HandleFunc(path.Join(pathPrefix, "rpcz"), rpczHandler)
  52. mux.HandleFunc(path.Join(pathPrefix, "tracez"), tracezHandler)
  53. mux.Handle(path.Join(pathPrefix, "public/"), http.FileServer(fs))
  54. }
  55. var enableOnce sync.Once
  56. func enable() {
  57. enableOnce.Do(func() {
  58. internal.LocalSpanStoreEnabled = true
  59. registerRPCViews()
  60. })
  61. }