Couchbase C Client  2.10.0
Asynchronous C Client for Couchbase
tracing.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2018 Couchbase, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #if !defined(LCB_TRACING_H) && defined(LCB_TRACING)
19 #define LCB_TRACING_H
20 
33 #ifdef __cplusplus
34 namespace lcb
35 {
36 namespace trace
37 {
38 class Span;
39 class Tracer;
40 } // namespace trace
41 } // namespace lcb
42 typedef lcb::trace::Span lcbtrace_SPAN;
43 extern "C" {
44 #else /* C only! */
45 typedef struct lcbtrace_SPAN_Cdummy lcbtrace_SPAN;
46 #endif
47 
51 #define LCBTRACE_F_THRESHOLD 0x01
52 
53 struct lcbtrace_TRACER;
57 typedef struct lcbtrace_TRACER {
58  lcb_U16 version;
59  lcb_U64 flags;
60  void *cookie;
61  void (*destructor)(struct lcbtrace_TRACER *tracer);
62  union {
63  struct {
64  void (*report)(struct lcbtrace_TRACER *tracer, lcbtrace_SPAN *span);
65  } v0;
66  } v;
68 
77 LIBCOUCHBASE_API lcbtrace_TRACER *lcb_get_tracer(lcb_t instance);
78 
87 LIBCOUCHBASE_API void lcb_set_tracer(lcb_t instance, lcbtrace_TRACER *tracer);
88 
98 LIBCOUCHBASE_API lcbtrace_TRACER *lcbtrace_new(lcb_t instance, lcb_U64 flags);
99 
105 LIBCOUCHBASE_API void lcbtrace_destroy(lcbtrace_TRACER *tracer);
106 
107 typedef enum {
108  LCBTRACE_REF_NONE = 0,
109  LCBTRACE_REF_CHILD_OF = 1,
110  LCBTRACE_REF_FOLLOWS_FROM,
111  LCBTRACE_REF__MAX
112 } lcbtrace_REF_TYPE;
113 
114 typedef struct {
115  lcbtrace_REF_TYPE type;
116  lcbtrace_SPAN *span;
117 } lcbtrace_REF;
118 
120 #define LCBTRACE_NOW 0
121 
129 LIBCOUCHBASE_API
130 lcb_U64 lcbtrace_now(void);
131 
142 LIBCOUCHBASE_API
143 lcbtrace_SPAN *lcbtrace_span_start(lcbtrace_TRACER *tracer, const char *operation, lcb_U64 now, lcbtrace_REF *ref);
144 
153 LIBCOUCHBASE_API
154 void lcbtrace_span_finish(lcbtrace_SPAN *span, lcb_U64 now);
155 
164 LIBCOUCHBASE_API
165 lcb_U64 lcbtrace_span_get_start_ts(lcbtrace_SPAN *span);
166 
175 LIBCOUCHBASE_API
176 lcb_U64 lcbtrace_span_get_finish_ts(lcbtrace_SPAN *span);
177 
189 LIBCOUCHBASE_API
190 int lcbtrace_span_is_orphaned(lcbtrace_SPAN *span);
191 
200 LIBCOUCHBASE_API
201 const char *lcbtrace_span_get_operation(lcbtrace_SPAN *span);
202 
203 #define LCBTRACE_OP_REQUEST_ENCODING "request_encoding"
204 #define LCBTRACE_OP_DISPATCH_TO_SERVER "dispatch_to_server"
205 #define LCBTRACE_OP_RESPONSE_DECODING "response_decoding"
206 
207 #define LCBTRACE_OP_ADD "add"
208 #define LCBTRACE_OP_APPEND "append"
209 #define LCBTRACE_OP_COUNTER "counter"
210 #define LCBTRACE_OP_GET "get"
211 #define LCBTRACE_OP_GET_FROM_REPLICA "get_from_replica"
212 #define LCBTRACE_OP_INSERT "insert"
213 #define LCBTRACE_OP_OBSERVE_CAS "observe_cas"
214 #define LCBTRACE_OP_OBSERVE_CAS_ROUND "observe_cas_round"
215 #define LCBTRACE_OP_OBSERVE_SEQNO "observe_seqno"
216 #define LCBTRACE_OP_PREPEND "prepend"
217 #define LCBTRACE_OP_REMOVE "remove"
218 #define LCBTRACE_OP_REPLACE "replace"
219 #define LCBTRACE_OP_TOUCH "touch"
220 #define LCBTRACE_OP_UNLOCK "unlock"
221 #define LCBTRACE_OP_UPSERT "upsert"
222 #define LCBTRACE_OP_UPSERT "upsert"
223 
224 #define LCBTRACE_OP_STORE2NAME(code) \
225  (code == LCB_ADD) \
226  ? LCBTRACE_OP_ADD \
227  : (code == LCB_PREPEND) ? LCBTRACE_OP_PREPEND : (code == LCB_APPEND) ? LCBTRACE_OP_APPEND : LCBTRACE_OP_UPSERT
228 
229 #define LCBTRACE_TAG_DB_TYPE "db.type"
230 #define LCBTRACE_TAG_SPAN_KIND "span.kind"
231 
234 #define LCBTRACE_TAG_DB_INSTANCE "db.instance"
235 
239 #define LCBTRACE_TAG_COMPONENT "component"
240 
243 #define LCBTRACE_TAG_OPERATION_ID "couchbase.operation_id"
244 
248 #define LCBTRACE_TAG_SERVICE "couchbase.service"
249 #define LCBTRACE_TAG_SERVICE_KV "kv"
250 #define LCBTRACE_TAG_SERVICE_VIEW "view"
251 #define LCBTRACE_TAG_SERVICE_N1QL "n1ql"
252 #define LCBTRACE_TAG_SERVICE_SEARCH "search"
253 #define LCBTRACE_TAG_SERVICE_ANALYTICS "analytics"
255 #define LCBTRACE_TAG_LOCAL_ID "couchbase.local_id"
256 
260 #define LCBTRACE_TAG_LOCAL_ADDRESS "local.address"
261 
265 #define LCBTRACE_TAG_PEER_ADDRESS "peer.address"
266 
272 #define LCBTRACE_TAG_PEER_LATENCY "peer.latency"
273 
282 LIBCOUCHBASE_API
283 lcb_U64 lcbtrace_span_get_span_id(lcbtrace_SPAN *span);
284 
293 LIBCOUCHBASE_API
294 lcb_U64 lcbtrace_span_get_trace_id(lcbtrace_SPAN *span);
295 
304 LIBCOUCHBASE_API
305 lcbtrace_SPAN *lcbtrace_span_get_parent(lcbtrace_SPAN *span);
306 
318 LIBCOUCHBASE_API
319 lcb_error_t lcbtrace_span_get_tag_str(lcbtrace_SPAN *span, const char *name, char **value, size_t *nvalue);
320 
331 LIBCOUCHBASE_API
332 lcb_error_t lcbtrace_span_get_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 *value);
333 
344 LIBCOUCHBASE_API
345 lcb_error_t lcbtrace_span_get_tag_double(lcbtrace_SPAN *span, const char *name, double *value);
346 
357 LIBCOUCHBASE_API
358 lcb_error_t lcbtrace_span_get_tag_bool(lcbtrace_SPAN *span, const char *name, int *value);
359 
369 LIBCOUCHBASE_API
370 void lcbtrace_span_add_tag_str(lcbtrace_SPAN *span, const char *name, const char *value);
371 
381 LIBCOUCHBASE_API
382 void lcbtrace_span_add_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 value);
383 
393 LIBCOUCHBASE_API
394 void lcbtrace_span_add_tag_double(lcbtrace_SPAN *span, const char *name, double value);
395 
405 LIBCOUCHBASE_API
406 void lcbtrace_span_add_tag_bool(lcbtrace_SPAN *span, const char *name, int value);
407 
416 #define LCB_CMD_SET_TRACESPAN(cmd, span) \
417  do { \
418  (cmd)->_hashkey.type = LCB_KV_TRACESPAN; \
419  (cmd)->_hashkey.contig.bytes = span; \
420  } while (0);
421 
425 typedef struct {
426  void *state;
427  void (*report)(void *state, lcbtrace_SPAN *span);
429 
434 #ifdef __cplusplus
435 }
436 #endif
437 #endif /* LCB_TRACING_H */
lcb_U64 lcbtrace_span_get_finish_ts(lcbtrace_SPAN *span)
Get finish timestamp of the span.
void lcbtrace_span_add_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 value)
Add integer tag to span.
lcb_error_t lcbtrace_span_get_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 *value)
Get value of the integer tag of the span.
void lcbtrace_span_add_tag_str(lcbtrace_SPAN *span, const char *name, const char *value)
Add string tag to span.
void(* destructor)(struct lcbtrace_TRACER *tracer)
destructor function or NULL, if it is not necessary
Definition: tracing.h:61
lcb_U64 lcbtrace_now(void)
Get current timestamp.
Tracer interface.
Definition: tracing.h:57
void lcbtrace_span_add_tag_double(lcbtrace_SPAN *span, const char *name, double value)
Add double tag to span.
lcbtrace_TRACER * lcb_get_tracer(lcb_t instance)
Get current tracer of the connection.
void lcbtrace_destroy(lcbtrace_TRACER *tracer)
Destroy tracer object.
Definition: tracing.h:449
lcb_U64 lcbtrace_span_get_span_id(lcbtrace_SPAN *span)
Get ID of the span.
lcb_error_t lcbtrace_span_get_tag_str(lcbtrace_SPAN *span, const char *name, char **value, size_t *nvalue)
Get value of the string tag of the span.
lcb_U64 lcbtrace_span_get_trace_id(lcbtrace_SPAN *span)
Get trace ID of the span.
int lcbtrace_span_is_orphaned(lcbtrace_SPAN *span)
Check if the span is orphaned.
void lcb_set_tracer(lcb_t instance, lcbtrace_TRACER *tracer)
Set current tracer for the connection.
lcb_error_t lcbtrace_span_get_tag_double(lcbtrace_SPAN *span, const char *name, double *value)
Get value of the double tag of the span.
void lcbtrace_span_add_tag_bool(lcbtrace_SPAN *span, const char *name, int value)
Add boolean tag to span.
lcb_U64 flags
tracer-specific flags
Definition: tracing.h:59
lcb_U64 lcbtrace_span_get_start_ts(lcbtrace_SPAN *span)
Get start timestamp of the span.
struct lcb_st * lcb_t
Library handle representing a connection to a cluster and its data buckets.
Definition: couchbase.h:41
lcb_error_t
Error codes returned by the library.
Definition: error.h:580
void * cookie
opaque pointer (e.g.
Definition: tracing.h:60
lcbtrace_SPAN * lcbtrace_span_get_parent(lcbtrace_SPAN *span)
Get parent span of the span.
lcb_U16 version
version of the structure, current value is 0
Definition: tracing.h:58
void lcbtrace_span_finish(lcbtrace_SPAN *span, lcb_U64 now)
Mark the span as finished.
const char * lcbtrace_span_get_operation(lcbtrace_SPAN *span)
Get operation code of the span.
lcbtrace_TRACER * lcbtrace_new(lcb_t instance, lcb_U64 flags)
Create default libcouchbase tracer instance.
lcbtrace_SPAN * lcbtrace_span_start(lcbtrace_TRACER *tracer, const char *operation, lcb_U64 now, lcbtrace_REF *ref)
Start span.
lcb_error_t lcbtrace_span_get_tag_bool(lcbtrace_SPAN *span, const char *name, int *value)
Get value of the boolean tag of the span.