You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doc.go 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright The OpenTelemetry 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 trace provides an implementation of the tracing part of the
  16. OpenTelemetry API.
  17. This package is currently in a pre-GA phase. Backwards incompatible changes
  18. may be introduced in subsequent minor version releases as we work to track the
  19. evolving OpenTelemetry specification and user feedback.
  20. To participate in distributed traces a Span needs to be created for the
  21. operation being performed as part of a traced workflow. It its simplest form:
  22. var tracer trace.Tracer
  23. func init() {
  24. tracer = otel.Tracer("instrumentation/package/name")
  25. }
  26. func operation(ctx context.Context) {
  27. var span trace.Span
  28. ctx, span = tracer.Start(ctx, "operation")
  29. defer span.End()
  30. // ...
  31. }
  32. A Tracer is unique to the instrumentation and is used to create Spans.
  33. Instrumentation should be designed to accept a TracerProvider from which it
  34. can create its own unique Tracer. Alternatively, the registered global
  35. TracerProvider from the go.opentelemetry.io/otel package can be used as
  36. a default.
  37. const (
  38. name = "instrumentation/package/name"
  39. version = "0.1.0"
  40. )
  41. type Instrumentation struct {
  42. tracer trace.Tracer
  43. }
  44. func NewInstrumentation(tp trace.TracerProvider) *Instrumentation {
  45. if tp == nil {
  46. tp = otel.TracerProvider()
  47. }
  48. return &Instrumentation{
  49. tracer: tp.Tracer(name, trace.WithInstrumentationVersion(version)),
  50. }
  51. }
  52. func operation(ctx context.Context, inst *Instrumentation) {
  53. var span trace.Span
  54. ctx, span = inst.tracer.Start(ctx, "operation")
  55. defer span.End()
  56. // ...
  57. }
  58. */
  59. package trace // import "go.opentelemetry.io/otel/trace"