11# Tracing SDK
22
3- <details >
4- <summary >
5- Table of Contents
6- </summary >
3+ <details ><summary >Table of Contents</summary >
74
85* [ Span Processor] ( #span-processor )
96* [ Span Exporter] ( #span-exporter )
107
118</details >
129
10+ ## Span processor
1311
14- # Span processor
15-
16- Span processor is an interface which allows hooks for span start and end method invocations.
17- The span processors are invoked only when [ ` IsRecordingEvents ` ] ( api-tracing.md#isrecordingevents ) is
18- true. This interface must be used to implement [ span exporter] ( #span-exporter ) to batch and convert
12+ Span processor is an interface which allows hooks for span start and end method
13+ invocations. The span processors are invoked only when
14+ [ ` IsRecordingEvents ` ] ( api-tracing.md#isrecordingevents ) is true. This interface
15+ must be used to implement [ span exporter] ( #span-exporter ) to batch and convert
1916spans.
2017
21- Span processors can be registered directly on SDK Tracer and they are invoked in the same order as
22- they were registered.
18+ Span processors can be registered directly on SDK Tracer and they are invoked in
19+ the same order as they were registered.
2320
24- The following diagram shows ` SpanProcessor ` 's relationship to other components in the SDK:
21+ The following diagram shows ` SpanProcessor ` 's relationship to other components
22+ in the SDK:
2523
2624```
2725 +-----+---------------+ +---------------------+ +-------------------+
@@ -38,164 +36,172 @@ The following diagram shows `SpanProcessor`'s relationship to other components i
3836 +-----+---------------+ +---------------------+
3937```
4038
41- ## Interface definition
39+ ### Interface definition
4240
43- ### OnStart(Span)
41+ #### OnStart(Span)
4442
45- ` OnStart ` is called when a span is started.
46- This method is called synchronously on the thread that started the span, therefore it should not
47- block or throw exceptions.
43+ ` OnStart ` is called when a span is started. This method is called synchronously
44+ on the thread that started the span, therefore it should not block or throw
45+ exceptions.
4846
4947** Parameters:**
5048
5149* ` Span ` - a readable span object.
5250
5351** Returns:** ` Void `
5452
55- ### OnEnd(Span)
53+ #### OnEnd(Span)
5654
57- ` OnEnd ` is called when a span is ended.
58- This method is called synchronously on the execution thread, therefore it should not block or throw
59- an exception.
55+ ` OnEnd ` is called when a span is ended. This method is called synchronously on
56+ the execution thread, therefore it should not block or throw an exception.
6057
6158** Parameters:**
6259
6360* ` Span ` - a readable span object.
6461
6562** Returns:** ` Void `
6663
67- ### Shutdown()
64+ #### Shutdown()
6865
69- Shuts down the processor. Called when SDK is shut down. This is an opportunity for processor to do
70- any cleanup required.
66+ Shuts down the processor. Called when SDK is shut down. This is an opportunity
67+ for processor to do any cleanup required.
7168
72- Shutdown should be called only once for each ` Processor ` instance. After the call to shutdown
73- subsequent calls to ` onStart ` or ` onEnd ` are not allowed.
69+ Shutdown should be called only once for each ` Processor ` instance. After the
70+ call to shutdown subsequent calls to ` onStart ` or ` onEnd ` are not allowed.
7471
75- Shutdown should not block indefinitely. Language library authors can decide if they want to make
76- the shutdown timeout to be configurable.
72+ Shutdown should not block indefinitely. Language library authors can decide if
73+ they want to make the shutdown timeout to be configurable.
7774
78- ## Built-in span processors
75+ ### Built-in span processors
7976
80- ### Simple processor
77+ #### Simple processor
8178
82- The implementation of ` SpanProcessor ` that passes ended span directly to the configured
83- ` SpanExporter ` .
79+ The implementation of ` SpanProcessor ` that passes ended span directly to the
80+ configured ` SpanExporter ` .
8481
8582** Configurable parameters:**
8683
8784* ` exporter ` - the exporter where the spans are pushed.
8885
89- ### Batching processor
86+ #### Batching processor
9087
91- The implementation of the ` SpanProcessor ` that batches ended spans and pushes them to the configured
92- ` SpanExporter ` .
88+ The implementation of the ` SpanProcessor ` that batches ended spans and pushes
89+ them to the configured ` SpanExporter ` .
9390
94- First the spans are added to a synchronized queue, then exported to the exporter pipeline in batches.
95- The implementation is responsible for managing the span queue and sending batches of spans to the
96- exporters.
97- This processor can cause high contention in a very high traffic service.
91+ First the spans are added to a synchronized queue, then exported to the exporter
92+ pipeline in batches. The implementation is responsible for managing the span
93+ queue and sending batches of spans to the exporters. This processor can cause
94+ high contention in a very high traffic service.
9895
9996** Configurable parameters:**
10097
10198* ` exporter ` - the exporter where the spans are pushed.
102- * ` maxQueueSize ` - the maximum queue size. After the size is reached spans are dropped. The default
103- value is ` 2048 ` .
104- * ` scheduledDelayMillis ` - the delay interval in milliseconds between two consecutive exports. The
105- default value is ` 5000 ` .
106- * ` maxExportBatchSize ` - the maximum batch size of every export. It must be smaller or equal to
107- ` maxQueueSize ` . The default value is ` 512 ` .
99+ * ` maxQueueSize ` - the maximum queue size. After the size is reached spans are
100+ dropped. The default value is ` 2048 ` .
101+ * ` scheduledDelayMillis ` - the delay interval in milliseconds between two
102+ consecutive exports. The default value is ` 5000 ` .
103+ * ` maxExportBatchSize ` - the maximum batch size of every export. It must be
104+ smaller or equal to ` maxQueueSize ` . The default value is ` 512 ` .
108105
109- # Span Exporter
106+ ## Span Exporter
110107
111- ` Span Exporter ` defines the interface that protocol-specific exporters must implement so that they
112- can be plugged into OpenTelemetry SDK and support sending of telemetry data.
108+ ` Span Exporter ` defines the interface that protocol-specific exporters must
109+ implement so that they can be plugged into OpenTelemetry SDK and support sending
110+ of telemetry data.
113111
114112The goals of the interface are:
115113
116- - Minimize burden of implementation for protocol-dependent telemetry exporters. The protocol
117- exporter is expected to be primarily a simple telemetry data encoder and transmitter.
118-
119- - Allow implementing helpers as composable components that use the same chainable ` Exporter `
120- interface. SDK authors are encouraged to implement common functionality such as queuing, batching,
121- tagging, etc. as helpers. This functionality will be applicable regardless of what protocol exporter
122- is used.
114+ * Minimize burden of implementation for protocol-dependent telemetry exporters.
115+ The protocol exporter is expected to be primarily a simple telemetry data
116+ encoder and transmitter.
117+ * Allow implementing helpers as composable components that use the same
118+ chainable ` Exporter ` interface. SDK authors are encouraged to implement common
119+ functionality such as queuing, batching, tagging, etc. as helpers. This
120+ functionality will be applicable regardless of what protocol exporter is used.
123121
124- ## Interface Definition
122+ ### Interface Definition
125123
126- The exporter must support two functions: ** Export** and ** Shutdown** . In strongly typed languages
127- typically there will be 2 separate ` Exporter ` interfaces, one that accepts spans (SpanExporter) and
128- one that accepts metrics (MetricsExporter).
124+ The exporter must support two functions: ** Export** and ** Shutdown** . In
125+ strongly typed languages typically there will be 2 separate ` Exporter `
126+ interfaces, one that accepts spans (SpanExporter) and one that accepts metrics
127+ (MetricsExporter).
129128
130- ### Export(batch)
129+ #### ` Export(batch) `
131130
132- Exports a batch of telemetry data. Protocol exporters that will implement this function are
133- typically expected to serialize and transmit the data to the destination.
131+ Exports a batch of telemetry data. Protocol exporters that will implement this
132+ function are typically expected to serialize and transmit the data to the
133+ destination.
134134
135- Export() will never be called concurrently for the same exporter instance. Export() can be called
136- again only after the current call returns.
135+ Export() will never be called concurrently for the same exporter instance.
136+ Export() can be called again only after the current call returns.
137137
138- Export() must not block indefinitely, there must be a reasonable upper limit after which the call
139- must time out with an error result (typically FailedRetryable).
138+ Export() must not block indefinitely, there must be a reasonable upper limit
139+ after which the call must time out with an error result (typically
140+ FailedRetryable).
140141
141142** Parameters:**
142143
143- batch - a batch of telemetry data. The exact data type of the batch is language specific, typically
144- it is a list of telemetry items, e.g. for spans in Java it will be typically
145- ` Collection<ExportableSpan> ` .
144+ batch - a batch of telemetry data. The exact data type of the batch is language
145+ specific, typically it is a list of telemetry items, e.g. for spans in Java it
146+ will be typically ` Collection<ExportableSpan> ` .
146147
147- Note that the data type for a span for illustration purposes here is written as an imaginary type
148- ExportableSpan (similarly for metrics it would be e.g. ExportableMetrics). The actual data type must
149- be specified by language library authors, it should be able to represent the span data that can be
150- read by the exporter.
148+ Note that the data type for a span for illustration purposes here is written as
149+ an imaginary type ExportableSpan (similarly for metrics it would be e.g.
150+ ExportableMetrics). The actual data type must be specified by language library
151+ authors, it should be able to represent the span data that can be read by the
152+ exporter.
151153
152154** Returns:** ExportResult:
153155
154156ExportResult is one of:
155157
156- - Success - batch is successfully exported. For protocol exporters this typically means that the
157- data is sent over the wire and delivered to the destination server.
158-
159- - FailedNotRetryable - exporting failed. The caller must not retry exporting the same batch. The
160- batch must be dropped. This for example can happen when the batch contains bad data and cannot be
161- serialized.
158+ * Success - batch is successfully exported. For protocol exporters this
159+ typically means that the data is sent over the wire and delivered to the
160+ destination server.
161+ * FailedNotRetryable - exporting failed. The caller must not retry exporting the
162+ same batch. The batch must be dropped. This for example can happen when the
163+ batch contains bad data and cannot be serialized.
164+ * FailedRetryable - cannot export to the destination. The caller should record
165+ the error and may retry exporting the same batch after some time. This for
166+ example can happen when the destination is unavailable, there is a network
167+ error or endpoint does not exist.
162168
163- - FailedRetryable - cannot export to the destination. The caller should record the error and may
164- retry exporting the same batch after some time. This for example can happen when the destination is
165- unavailable, there is a network error or endpoint does not exist.
169+ #### ` Shutdown() `
166170
167- ### Shutdown()
171+ Shuts down the exporter. Called when SDK is shut down. This is an opportunity
172+ for exporter to do any cleanup required.
168173
169- Shuts down the exporter. Called when SDK is shut down. This is an opportunity for exporter to do any
170- cleanup required.
174+ ` Shutdown ` should be called only once for each ` Exporter ` instance. After the
175+ call to ` Shutdown ` subsequent calls to ` Export ` are not allowed and should
176+ return FailedNotRetryable error.
171177
172- ` Shutdown ` should be called only once for each ` Exporter ` instance. After the call to ` Shutdown `
173- subsequent calls to ` Export ` are not allowed and should return FailedNotRetryable error.
178+ ` Shutdown ` should not block indefinitely (e.g. if it attempts to flush the data
179+ and the destination is unavailable). Language library authors can decide if they
180+ want to make the shutdown timeout to be configurable.
174181
175- ` Shutdown ` should not block indefinitely (e.g. if it attempts to flush the data and the destination
176- is unavailable). Language library authors can decide if they want to make the shutdown timeout to
177- be configurable.
182+ ### Further Language Specialization
178183
179- ## Further Language Specialization
184+ Based on the generic interface definition laid out above library authors must
185+ define the exact interface for the particular language.
180186
181- Based on the generic interface definition laid out above library authors must define the exact
182- interface for the particular language.
187+ Authors are encouraged to use efficient data structures on the interface
188+ boundary that are well suited for fast serialization to wire formats by protocol
189+ exporters and minimize the pressure on memory managers. The latter typically
190+ requires understanding of how to optimize the rapidly-generated, short-lived
191+ telemetry data structures to make life easier for the memory manager of the
192+ specific language. General recommendation is to minimize the number of
193+ allocations and use allocation arenas where possible, thus avoiding explosion of
194+ allocation/deallocation/collection operations in the presence of high rate of
195+ telemetry data generation.
183196
184- Authors are encouraged to use efficient data structures on the interface boundary that are well
185- suited for fast serialization to wire formats by protocol exporters and minimize the pressure on
186- memory managers. The latter typically requires understanding of how to optimize the
187- rapidly-generated, short-lived telemetry data structures to make life easier for the memory manager
188- of the specific language. General recommendation is to minimize the number of allocations and use
189- allocation arenas where possible, thus avoiding explosion of allocation/deallocation/collection
190- operations in the presence of high rate of telemetry data generation.
197+ #### Examples
191198
192- ### Examples
199+ These are examples on what the ` Exporter ` interface can look like in specific
200+ languages. Examples are for illustration purposes only. Language library authors
201+ are free to deviate from these provided that their design remain true to the
202+ spirit of ` Exporter ` concept.
193203
194- These are examples on what the ` Exporter ` interface can look like in specific languages. Examples
195- are for illustration purposes only. Language library authors are free to deviate from these provided
196- that their design remain true to the spirit of ` Exporter ` concept.
197-
198- #### Go SpanExporter Interface
204+ ##### Go SpanExporter Interface
199205
200206``` go
201207type SpanExporter interface {
@@ -217,7 +223,7 @@ const (
217223)
218224```
219225
220- #### Java SpanExporter Interface
226+ ##### Java SpanExporter Interface
221227
222228``` java
223229public interface SpanExporter {
@@ -228,4 +234,4 @@ public interface SpanExporter {
228234 ResultCode export (Collection<ExportableSpan > batch );
229235 void shutdown ();
230236}
231- ```
237+ ```
0 commit comments