|
1 | 1 | --- |
2 | 2 | title: Manual Instrumentation |
3 | 3 | linkTitle: Manual |
4 | | -aliases: [/docs/instrumentation/ruby/manual_instrumentation] |
| 4 | +aliases: |
| 5 | + - /docs/instrumentation/ruby/manual_instrumentation |
| 6 | + - /docs/instrumentation/ruby/events |
| 7 | + - /docs/instrumentation/ruby/context-propagation |
5 | 8 | weight: 4 |
6 | 9 | --- |
7 | 10 |
|
|
79 | 82 | > ⚠ Sampling decisions happen at the moment of span creation. |
80 | 83 | > If your sampler considers span attributes when deciding to sample a span, then you _must_ pass those attributes as part of span creation. Any attributes added after creation will not be seen by the sampler, because the sampling decision has already been made. |
81 | 84 |
|
82 | | - |
83 | 85 | #### Semantic Attributes |
84 | 86 |
|
85 | 87 | Semantic Attributes are attributes that are defined by the [OpenTelemetry Specification][] in order to provide a shared set of attribute keys across multiple languages, frameworks, and runtimes for common concepts like HTTP methods, status codes, user agents, and more. These attributes are available in the [Semantic Conventions gem][semconv-gem]. |
86 | 88 |
|
87 | 89 | For details, see [Trace semantic conventions][semconv-spec]. |
88 | 90 |
|
89 | | -[OpenTelemetry Specification]: {{< relref "/docs/reference/specification" >}} |
| 91 | +### Span Events |
| 92 | + |
| 93 | +An event is a human-readable message on a span that represents "something happening" during it's lifetime. For example, imagine a function that requires exclusive access to a resource that is under a mutex. An event could be created at two points - once, when we try to gain access to the resource, and another when we acquire the mutex. |
| 94 | + |
| 95 | +```ruby |
| 96 | +span.add_event("Acquiring lock") |
| 97 | +if mutex.try_lock |
| 98 | + span.add_event("Got lock, doing work...") |
| 99 | + # some code here |
| 100 | + span.add_event("Releasing lock") |
| 101 | +else |
| 102 | + span.add_event("Lock already in use") |
| 103 | +end |
| 104 | +``` |
| 105 | + |
| 106 | +A useful characteristic of events is that their timestamps are displayed as offsets from the beginning of the span, allowing you to easily see how much time elapsed between them. |
| 107 | + |
| 108 | +Events can also have attributes of their own e.g. |
| 109 | + |
| 110 | +```ruby |
| 111 | +span.add_event("Cancelled wait due to external signal", attributes: { "pid" => 4328, "signal" => "SIGHUP" }) |
| 112 | +``` |
| 113 | + |
| 114 | +## Context Propagation |
| 115 | + |
| 116 | +> Distributed Tracing tracks the progression of a single Request, called a Trace, as it is handled by Services that make up an Application. A Distributed Trace transverses process, network and security boundaries. [Glossary][] |
| 117 | +
|
| 118 | +This requires _context propagation_, a mechanism where identifiers for a trace are sent to remote processes. |
| 119 | + |
| 120 | +> ℹ The OpenTelemetry Ruby SDK will take care of context propagation as long as your service is leveraging auto-instrumented libraries. Please refer to the [README][auto-instrumentation] for more details. |
| 121 | +
|
| 122 | +In order to propagate trace context over the wire, a propagator must be registered with the OpenTelemetry SDK. |
| 123 | +The W3 TraceContext and Baggage propagators are configured by default. |
| 124 | +Operators may override this value by setting `OTEL_PROPAGATORS` environment variable to a comma separated list of [propagators][propagators]. |
| 125 | +For example, to add B3 propagation, set `OTEL_PROPAGATORS` to the complete list of propagation formats you wish to support: |
| 126 | + |
| 127 | +```sh |
| 128 | +export OTEL_PROPAGATORS=tracecontext,baggage,b3 |
| 129 | +``` |
| 130 | + |
| 131 | +Propagators other than `tracecontext` and `baggage` must be added as gem dependencies to your Gemfile, e.g.: |
| 132 | + |
| 133 | +```ruby |
| 134 | +gem 'opentelemetry-propagator-b3' |
| 135 | +``` |
| 136 | + |
| 137 | +[glossary]: /docs/concepts/glossary/ |
| 138 | +[propagators]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/propagator |
| 139 | +[auto-instrumentation]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation |
90 | 140 | [semconv-gem]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/semantic_conventions |
91 | 141 | [semconv-spec]: {{< relref "/docs/reference/specification/trace/semantic_conventions" >}} |
| 142 | +[OpenTelemetry Specification]: {{< relref "/docs/reference/specification" >}} |
0 commit comments