Couchbase C Client  3.3.14
Asynchronous C Client for Couchbase
tracing.h
1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2018-2020 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#ifndef LCB_TRACING_H
19#define LCB_TRACING_H
20
32#ifdef __cplusplus
33namespace lcb
34{
35namespace trace
36{
37class Span;
38class Tracer;
39} // namespace trace
40} // namespace lcb
41typedef lcb::trace::Span lcbtrace_SPAN;
42extern "C" {
43#else /* C only! */
44typedef struct lcbtrace_SPAN_Cdummy lcbtrace_SPAN;
45#endif
46
50#define LCBTRACE_F_THRESHOLD 0x01
51
55#define LCBTRACE_F_EXTERNAL 0x02
56
60typedef enum {
61 LCBTRACE_SERVICE_KV = 0,
62 LCBTRACE_SERVICE_QUERY,
63 LCBTRACE_SERVICE_VIEW,
64 LCBTRACE_SERVICE_SEARCH,
65 LCBTRACE_SERVICE_ANALYTICS,
66 LCBTRACE_SERVICE__MAX
68
69struct lcbtrace_TRACER;
73typedef struct lcbtrace_TRACER {
74 lcb_U16 version;
75 lcb_U64 flags;
76 void *cookie;
77 void (*destructor)(struct lcbtrace_TRACER *tracer);
78 union {
79 struct {
80 void (*report)(struct lcbtrace_TRACER *tracer, lcbtrace_SPAN *span);
81 } v0;
82 struct {
83 void *(*start_span)(struct lcbtrace_TRACER *tracer, const char *name, void *parent);
84 void (*end_span)(void *span);
85 void (*destroy_span)(void *span);
86 void (*add_tag_string)(void *span, const char *name, const char *value, size_t value_len);
87 void (*add_tag_uint64)(void *span, const char *name, uint64_t value);
88 } v1;
89 } v;
91
100LIBCOUCHBASE_API lcbtrace_TRACER *lcb_get_tracer(lcb_INSTANCE *instance);
101
110LIBCOUCHBASE_API void lcb_set_tracer(lcb_INSTANCE *instance, lcbtrace_TRACER *tracer);
111
121LIBCOUCHBASE_API lcbtrace_TRACER *lcbtrace_new(lcb_INSTANCE *instance, lcb_U64 flags);
122
128LIBCOUCHBASE_API void lcbtrace_destroy(lcbtrace_TRACER *tracer);
129
130typedef enum {
131 LCBTRACE_REF_NONE = 0,
132 LCBTRACE_REF_CHILD_OF = 1,
133 LCBTRACE_REF_FOLLOWS_FROM,
134 LCBTRACE_REF__MAX
135} lcbtrace_REF_TYPE;
136
137typedef struct {
138 lcbtrace_REF_TYPE type;
139 lcbtrace_SPAN *span;
140} lcbtrace_REF;
141
143#define LCBTRACE_NOW 0
144
152LIBCOUCHBASE_API
153lcb_U64 lcbtrace_now(void);
154
165LIBCOUCHBASE_API
166lcbtrace_SPAN *lcbtrace_span_start(lcbtrace_TRACER *tracer, const char *operation, lcb_U64 now, lcbtrace_REF *ref);
167
183LIBCOUCHBASE_API
184lcb_STATUS lcbtrace_span_wrap(lcbtrace_TRACER *tracer, const char *opname, uint64_t start, void *external_span,
185 lcbtrace_SPAN **lcbspan);
186
195LIBCOUCHBASE_API
196void lcbtrace_span_finish(lcbtrace_SPAN *span, lcb_U64 now);
197
201LIBCOUCHBASE_API
202int lcbtrace_span_should_finish(lcbtrace_SPAN *span);
203
212LIBCOUCHBASE_API
213lcb_U64 lcbtrace_span_get_start_ts(lcbtrace_SPAN *span);
214
223LIBCOUCHBASE_API
224lcb_U64 lcbtrace_span_get_finish_ts(lcbtrace_SPAN *span);
225
237LIBCOUCHBASE_API
238int lcbtrace_span_is_orphaned(lcbtrace_SPAN *span);
239
248LIBCOUCHBASE_API
249const char *lcbtrace_span_get_operation(lcbtrace_SPAN *span);
250
265LIBCOUCHBASE_API
267
282LIBCOUCHBASE_API
284
295LIBCOUCHBASE_API
296lcb_STATUS lcbtrace_span_get_is_outer(lcbtrace_SPAN *span, int *outer);
297
315LIBCOUCHBASE_API
316lcb_STATUS lcbtrace_span_set_is_outer(lcbtrace_SPAN *span, int outer);
317
328LIBCOUCHBASE_API
329lcb_STATUS lcbtrace_span_get_is_encoding(lcbtrace_SPAN *span, int *encoding);
330
344LIBCOUCHBASE_API
345lcb_STATUS lcbtrace_span_set_is_encode(lcbtrace_SPAN *span, int encode);
346
357LIBCOUCHBASE_API
358lcb_STATUS lcbtrace_span_get_is_dispatch(lcbtrace_SPAN *span, int *dispatch);
359
375LIBCOUCHBASE_API
376lcb_STATUS lcbtrace_span_set_is_dispatch(lcbtrace_SPAN *span, int dispatch);
377
378#define LCBTRACE_OP_REQUEST_ENCODING "request_encoding"
379#define LCBTRACE_OP_DISPATCH_TO_SERVER "dispatch"
380#define LCBTRACE_OP_RESPONSE_DECODING "response_decoding"
381
382#define LCBTRACE_OP_INSERT "insert"
383#define LCBTRACE_OP_APPEND "append"
384#define LCBTRACE_OP_COUNTER "counter"
385#define LCBTRACE_OP_GET "get"
386#define LCBTRACE_OP_GET_FROM_REPLICA "get_from_replica"
387#define LCBTRACE_OP_INSERT "insert"
388#define LCBTRACE_OP_OBSERVE_CAS "observe_cas"
389#define LCBTRACE_OP_OBSERVE_CAS_ROUND "observe_cas_round"
390#define LCBTRACE_OP_OBSERVE_SEQNO "observe_seqno"
391#define LCBTRACE_OP_PREPEND "prepend"
392#define LCBTRACE_OP_REMOVE "remove"
393#define LCBTRACE_OP_REPLACE "replace"
394#define LCBTRACE_OP_TOUCH "touch"
395#define LCBTRACE_OP_UNLOCK "unlock"
396#define LCBTRACE_OP_UPSERT "upsert"
397#define LCBTRACE_OP_EXISTS "exists"
398#define LCBTRACE_OP_LOOKUPIN "lookup_in"
399#define LCBTRACE_OP_MUTATEIN "mutate_in"
400#define LCBTRACE_OP_QUERY "query"
401#define LCBTRACE_OP_ANALYTICS "analytics"
402#define LCBTRACE_OP_SEARCH "search"
403#define LCBTRACE_OP_VIEW "views"
404
405#define LCBTRACE_TAG_SPAN_KIND "span.kind"
409#define LCBTRACE_TAG_DB_INSTANCE "db.name"
414#define LCBTRACE_TAG_COMPONENT "db.couchbase.component"
418#define LCBTRACE_TAG_OPERATION_ID "db.couchbase.operation_id"
423#define LCBTRACE_TAG_SERVICE "db.couchbase.service"
424#define LCBTRACE_TAG_SERVICE_KV "kv"
425#define LCBTRACE_TAG_SERVICE_VIEW "views"
426#define LCBTRACE_TAG_SERVICE_N1QL "query"
427#define LCBTRACE_TAG_SERVICE_SEARCH "search"
428#define LCBTRACE_TAG_SERVICE_ANALYTICS "analytics"
429
434#define LCBTRACE_TAG_LOCAL_ID "db.couchbase.local_id"
435
440#define LCBTRACE_TAG_LOCAL_ADDRESS "net.host.name"
445#define LCBTRACE_TAG_LOCAL_PORT "net.host.port"
446
451#define LCBTRACE_TAG_PEER_ADDRESS "net.peer.name"
456#define LCBTRACE_TAG_PEER_PORT "net.peer.port"
460#define LCBTRACE_TAG_PEER_LATENCY "db.couchbase.server_duration"
464#define LCBTRACE_TAG_SCOPE "db.couchbase.scope"
468#define LCBTRACE_TAG_COLLECTION "db.couchbase.collection"
473#define LCBTRACE_TAG_STATEMENT "db.statement"
477#define LCBTRACE_TAG_OPERATION "db.operation"
481#define LCBTRACE_TAG_DURABILITY "db.couchbase.durability"
485#define LCBTRACE_TAG_RETRIES "db.couchbase.retries"
486
490#define LCBTRACE_TAG_SYSTEM "db.system"
491
495#define LCBTRACE_TAG_TRANSPORT "net.transport"
504LIBCOUCHBASE_API
505lcb_U64 lcbtrace_span_get_span_id(lcbtrace_SPAN *span);
506
515LIBCOUCHBASE_API
516lcb_U64 lcbtrace_span_get_trace_id(lcbtrace_SPAN *span);
517
526LIBCOUCHBASE_API
527lcbtrace_SPAN *lcbtrace_span_get_parent(lcbtrace_SPAN *span);
528
540LIBCOUCHBASE_API
541lcb_STATUS lcbtrace_span_get_tag_str(lcbtrace_SPAN *span, const char *name, char **value, size_t *nvalue);
542
553LIBCOUCHBASE_API
554lcb_STATUS lcbtrace_span_get_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 *value);
555
566LIBCOUCHBASE_API
567lcb_STATUS lcbtrace_span_get_tag_double(lcbtrace_SPAN *span, const char *name, double *value);
568
579LIBCOUCHBASE_API
580lcb_STATUS lcbtrace_span_get_tag_bool(lcbtrace_SPAN *span, const char *name, int *value);
581
591LIBCOUCHBASE_API
592void lcbtrace_span_add_tag_str(lcbtrace_SPAN *span, const char *name, const char *value);
593
603LIBCOUCHBASE_API
604void lcbtrace_span_add_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 value);
605
615LIBCOUCHBASE_API
616void lcbtrace_span_add_tag_double(lcbtrace_SPAN *span, const char *name, double value);
617
627LIBCOUCHBASE_API
628void lcbtrace_span_add_tag_bool(lcbtrace_SPAN *span, const char *name, int value);
629
638#define LCB_CMD_SET_TRACESPAN(cmd, span) \
639 do { \
640 (cmd)->pspan = span; \
641 } while (0)
642
646typedef struct {
647 void *state;
648 void (*report)(void *state, lcbtrace_SPAN *span);
650
655#ifdef __cplusplus
656}
657#endif
658#endif /* LCB_TRACING_H */
lcb_STATUS
Error codes returned by the library.
Definition error.h:213
struct lcb_st lcb_INSTANCE
Library handle representing a connection to a cluster and its data buckets.
Definition couchbase.h:35
lcb_U16 version
version of the structure, current value is 0
Definition tracing.h:74
lcb_U64 flags
tracer-specific flags
Definition tracing.h:75
void * cookie
opaque pointer (e.g.
Definition tracing.h:76
void(* destructor)(struct lcbtrace_TRACER *tracer)
destructor function or NULL, if it is not necessary
Definition tracing.h:77
lcb_STATUS lcbtrace_span_get_is_encoding(lcbtrace_SPAN *span, int *encoding)
Get encoding flag on span.
lcb_STATUS lcbtrace_span_set_is_dispatch(lcbtrace_SPAN *span, int dispatch)
Set dispatch flag on span.
lcb_U64 lcbtrace_now(void)
Get current timestamp.
int lcbtrace_span_is_orphaned(lcbtrace_SPAN *span)
Check if the span is orphaned.
lcb_U64 lcbtrace_span_get_finish_ts(lcbtrace_SPAN *span)
Get finish timestamp of the span.
void lcbtrace_span_add_tag_bool(lcbtrace_SPAN *span, const char *name, int value)
Add boolean tag to span.
lcb_U64 lcbtrace_span_get_span_id(lcbtrace_SPAN *span)
Get ID of the span.
void lcbtrace_span_add_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 value)
Add integer tag to span.
lcb_STATUS lcbtrace_span_get_is_dispatch(lcbtrace_SPAN *span, int *dispatch)
Get dispatch flag on span.
lcb_STATUS lcbtrace_span_get_service(lcbtrace_SPAN *span, lcbtrace_SERVICE *svc)
Get the service for the span.
lcbtrace_SPAN * lcbtrace_span_get_parent(lcbtrace_SPAN *span)
Get parent span of the span.
lcb_STATUS lcbtrace_span_get_tag_uint64(lcbtrace_SPAN *span, const char *name, lcb_U64 *value)
Get value of the integer tag of the span.
lcbtrace_SERVICE
Service the span is associated with.
Definition tracing.h:60
void lcb_set_tracer(lcb_INSTANCE *instance, lcbtrace_TRACER *tracer)
Set current tracer for the connection.
lcb_STATUS lcbtrace_span_get_is_outer(lcbtrace_SPAN *span, int *outer)
Get outer flag on span.
void lcbtrace_span_add_tag_double(lcbtrace_SPAN *span, const char *name, double value)
Add double tag to span.
void lcbtrace_destroy(lcbtrace_TRACER *tracer)
Destroy tracer object.
lcb_STATUS 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_STATUS lcbtrace_span_get_tag_double(lcbtrace_SPAN *span, const char *name, double *value)
Get value of the double tag of the span.
lcb_STATUS lcbtrace_span_set_is_outer(lcbtrace_SPAN *span, int outer)
Set outer flag on span.
lcb_U64 lcbtrace_span_get_start_ts(lcbtrace_SPAN *span)
Get start timestamp of the span.
lcb_U64 lcbtrace_span_get_trace_id(lcbtrace_SPAN *span)
Get trace ID of the span.
const char * lcbtrace_span_get_operation(lcbtrace_SPAN *span)
Get operation code of the span.
void lcbtrace_span_add_tag_str(lcbtrace_SPAN *span, const char *name, const char *value)
Add string tag to span.
void lcbtrace_span_finish(lcbtrace_SPAN *span, lcb_U64 now)
Mark the span as finished.
lcb_STATUS lcbtrace_span_wrap(lcbtrace_TRACER *tracer, const char *opname, uint64_t start, void *external_span, lcbtrace_SPAN **lcbspan)
Wrap external span.
lcbtrace_SPAN * lcbtrace_span_start(lcbtrace_TRACER *tracer, const char *operation, lcb_U64 now, lcbtrace_REF *ref)
Start span.
lcb_STATUS lcbtrace_span_set_is_encode(lcbtrace_SPAN *span, int encode)
Set encoding flag on span.
lcbtrace_TRACER * lcb_get_tracer(lcb_INSTANCE *instance)
Get current tracer of the connection.
lcb_STATUS lcbtrace_span_set_service(lcbtrace_SPAN *span, lcbtrace_SERVICE svc)
Set the service for the span.
lcb_STATUS lcbtrace_span_get_tag_bool(lcbtrace_SPAN *span, const char *name, int *value)
Get value of the boolean tag of the span.
lcbtrace_TRACER * lcbtrace_new(lcb_INSTANCE *instance, lcb_U64 flags)
Create default libcouchbase tracer instance.
Tracer interface.
Definition tracing.h:73
Definition tracing.h:646