MySQL 9.1.0
Source Code Documentation
mysql_telemetry_logs_client.h
Go to the documentation of this file.
1/* Copyright (c) 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_TELEMETRY_LOGS_CLIENT_H
25#define MYSQL_TELEMETRY_LOGS_CLIENT_H
26
27/**
28 @file include/mysql/psi/mysql_telemetry_logs_client.h
29 Instrumentation helpers for telemetry logs client.
30*/
31
32#include <cstring> // strlen
33
34/* HAVE_PSI_*_INTERFACE */
35#include "my_psi_config.h" // IWYU pragma: keep
36
38
39#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
40/* PSI_LOGS_CALL() as direct call. */
41#include "pfs_telemetry_logs_client_provider.h" // IWYU pragma: keep
42#endif
43
44#ifndef PSI_LOGS_CLIENT_CALL
45#define PSI_LOGS_CLIENT_CALL(M) \
46 SERVICE_PLACEHOLDER(mysql_server_telemetry_logs_client)->M
47#endif
48
49/**
50 @defgroup psi_api_logs_client Logger Client Instrumentation (API)
51 @ingroup psi_api
52 @{
53*/
54
55/**
56 @def mysql_log_client_register(P1, P2, P3)
57 Registration of logger clients.
58*/
59#define mysql_log_client_register(P1, P2, P3) \
60 inline_mysql_log_client_register(P1, P2, P3)
61
63 PSI_logger_info_v1 *info [[maybe_unused]], size_t count [[maybe_unused]],
64 const char *category [[maybe_unused]]) {
65#ifdef HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE
66 PSI_LOGS_CLIENT_CALL(register_logger_client)(info, count, category);
67#endif /* HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE */
68}
69
70/**
71 @def mysql_log_client_unregister(P1, P2)
72 Logger client unregistration.
73*/
74#define mysql_log_client_unregister(P1, P2) \
75 inline_mysql_log_client_unregister(P1, P2)
76
78 [[maybe_unused]],
79 size_t count
80 [[maybe_unused]]) {
81#ifdef HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE
82 PSI_LOGS_CLIENT_CALL(unregister_logger_client)(info, count);
83#endif /* HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE */
84}
85
86/**
87 @def mysql_log_client_check_enabled(P1, P2)
88 Logger client check if log level is enabled for this logger.
89*/
90#define mysql_log_client_check_enabled(P1, P2) \
91 inline_mysql_log_client_check_enabled(P1, P2)
92
93static inline PSI_logger *inline_mysql_log_client_check_enabled(
94 PSI_logger_key key [[maybe_unused]], OTELLogLevel level [[maybe_unused]]) {
95#ifdef HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE
96 return PSI_LOGS_CLIENT_CALL(check_enabled)(key, level);
97#else
98 return nullptr;
99#endif /* HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE */
100}
101
102/**
103 @def mysql_log_client_log(P1, P2, P3, P4, P5, P6)
104 Emit log record.
105*/
106#define mysql_log_client_log(P1, P2, P3, P4, P5, P6) \
107 inline_mysql_log_client_log(P1, P2, P3, P4, P5, P6)
108
110 PSI_logger *logger [[maybe_unused]], OTELLogLevel level [[maybe_unused]],
111 const char *message [[maybe_unused]], time_t timestamp [[maybe_unused]],
112 const log_attribute_t *attr_array [[maybe_unused]],
113 size_t attr_count [[maybe_unused]]) {
114#ifdef HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE
115 PSI_LOGS_CLIENT_CALL(log_emit)
116 (logger, level, message, timestamp, attr_array, attr_count);
117#endif /* HAVE_PSI_SERVER_TELEMETRY_LOGS_INTERFACE */
118}
119
120#ifdef __cplusplus
121
122/**
123 @class PSI_LogRecord
124 C++ wrapper for emitting a telemetry log record.
125*/
127 public:
128 PSI_LogRecord(PSI_logger_key key, OTELLogLevel level, const char *message)
129 : m_level(level), m_message(message) {
131 }
132
133 bool check_enabled() const { return m_psi != nullptr; }
134
135 void add_attribute_bool(const char *name, bool value) {
136 if (m_attr_count >= MAX_LOG_ATTRIBUTES) return;
138 }
139
140 void add_attribute_string(const char *name, const char *value) {
141 if (m_attr_count >= MAX_LOG_ATTRIBUTES) return;
143 }
144
145 void add_attribute_string_view(const char *name, const char *value,
146 size_t len) {
147 if (m_attr_count >= MAX_LOG_ATTRIBUTES) return;
149 }
150
151 void add_attribute_double(const char *name, double value) {
152 if (m_attr_count >= MAX_LOG_ATTRIBUTES) return;
154 }
155
156 void add_attribute_uint64(const char *name, uint64_t value) {
157 if (m_attr_count >= MAX_LOG_ATTRIBUTES) return;
159 }
160
161 void emit() {
164 }
165
166 protected:
167 PSI_logger *m_psi{nullptr};
170 const char *m_message;
172 size_t m_attr_count{0};
173};
174
175/**
176 @class PSI_SimpleLogger
177 C++ wrapper for emitting one or more simple (no attributes)
178 telemetry log records.
179*/
181 public:
183
184 void error(const char *message) const {
186 PSI_logger *psi = mysql_log_client_check_enabled(m_logger_key, level);
187 if (psi != nullptr)
188 mysql_log_client_log(psi, level, message, time(nullptr), nullptr, 0);
189 }
190
191 void warn(const char *message) const {
193 PSI_logger *psi = mysql_log_client_check_enabled(m_logger_key, level);
194 if (psi != nullptr)
195 mysql_log_client_log(psi, level, message, time(nullptr), nullptr, 0);
196 }
197
198 void info(const char *message) const {
200 PSI_logger *psi = mysql_log_client_check_enabled(m_logger_key, level);
201 if (psi != nullptr)
202 mysql_log_client_log(psi, level, message, time(nullptr), nullptr, 0);
203 }
204
205 void debug(const char *message) const {
207 PSI_logger *psi = mysql_log_client_check_enabled(m_logger_key, level);
208 if (psi != nullptr)
209 mysql_log_client_log(psi, level, message, time(nullptr), nullptr, 0);
210 }
211
212 public:
214};
215
216#endif
217
218/** @} (end of group psi_api_logs_client) */
219
220#endif
C++ wrapper for emitting a telemetry log record.
Definition: mysql_telemetry_logs_client.h:126
PSI_logger_key m_logger_key
Definition: mysql_telemetry_logs_client.h:168
OTELLogLevel m_level
Definition: mysql_telemetry_logs_client.h:169
void add_attribute_bool(const char *name, bool value)
Definition: mysql_telemetry_logs_client.h:135
size_t m_attr_count
Definition: mysql_telemetry_logs_client.h:172
void add_attribute_string_view(const char *name, const char *value, size_t len)
Definition: mysql_telemetry_logs_client.h:145
PSI_logger * m_psi
Definition: mysql_telemetry_logs_client.h:167
PSI_LogRecord(PSI_logger_key key, OTELLogLevel level, const char *message)
Definition: mysql_telemetry_logs_client.h:128
const char * m_message
Definition: mysql_telemetry_logs_client.h:170
void add_attribute_string(const char *name, const char *value)
Definition: mysql_telemetry_logs_client.h:140
void add_attribute_uint64(const char *name, uint64_t value)
Definition: mysql_telemetry_logs_client.h:156
log_attribute_t m_attrs[MAX_LOG_ATTRIBUTES]
Definition: mysql_telemetry_logs_client.h:171
void add_attribute_double(const char *name, double value)
Definition: mysql_telemetry_logs_client.h:151
void emit()
Definition: mysql_telemetry_logs_client.h:161
bool check_enabled() const
Definition: mysql_telemetry_logs_client.h:133
C++ wrapper for emitting one or more simple (no attributes) telemetry log records.
Definition: mysql_telemetry_logs_client.h:180
void warn(const char *message) const
Definition: mysql_telemetry_logs_client.h:191
void debug(const char *message) const
Definition: mysql_telemetry_logs_client.h:205
void info(const char *message) const
Definition: mysql_telemetry_logs_client.h:198
PSI_SimpleLogger(PSI_logger_key key)
Definition: mysql_telemetry_logs_client.h:182
void error(const char *message) const
Definition: mysql_telemetry_logs_client.h:184
PSI_logger_key m_logger_key
Definition: mysql_telemetry_logs_client.h:213
static void inline_mysql_log_client_log(PSI_logger *logger, OTELLogLevel level, const char *message, time_t timestamp, const log_attribute_t *attr_array, size_t attr_count)
Definition: mysql_telemetry_logs_client.h:109
static void inline_mysql_log_client_unregister(PSI_logger_info_v1 *info, size_t count)
Definition: mysql_telemetry_logs_client.h:77
static void inline_mysql_log_client_register(PSI_logger_info_v1 *info, size_t count, const char *category)
Definition: mysql_telemetry_logs_client.h:62
static PSI_logger * inline_mysql_log_client_check_enabled(PSI_logger_key key, OTELLogLevel level)
Definition: mysql_telemetry_logs_client.h:93
#define mysql_log_client_check_enabled(P1, P2)
Logger client check if log level is enabled for this logger.
Definition: mysql_telemetry_logs_client.h:90
#define mysql_log_client_log(P1, P2, P3, P4, P5, P6)
Emit log record.
Definition: mysql_telemetry_logs_client.h:106
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
static int count
Definition: myisam_ftdump.cc:45
constexpr value_type timestamp
Definition: classic_protocol_constants.h:278
static const char * category
Definition: sha2_password.cc:170
static Logger logger
The "top-level" logger used when no connection context is given.
Definition: test_trace_plugin.cc:296
Performance schema instrumentation (declarations).
#define PSI_LOGS_CLIENT_CALL(M)
Definition: pfs_telemetry_logs_client_provider.h:45
required string key
Definition: replication_asynchronous_connection_failover.proto:60
constexpr size_t MAX_LOG_ATTRIBUTES
Definition: server_telemetry_logs_client_bits.h:48
OTELLogLevel
Log levels as supported by opentelemetry-cpp (+ "none"), see: api/include/opentelemetry/logs/severity...
Definition: server_telemetry_logs_client_bits.h:43
@ TLOG_DEBUG
Definition: server_telemetry_logs_client_bits.h:43
@ TLOG_WARN
Definition: server_telemetry_logs_client_bits.h:43
@ TLOG_INFO
Definition: server_telemetry_logs_client_bits.h:43
unsigned int PSI_logger_key
Definition: server_telemetry_logs_client_bits.h:45
case opt name
Definition: sslopt-case.h:29
Defines a logger from the side of instrumented code (log API client).
Definition: server_telemetry_logs_client_bits.h:57
Definition: server_telemetry_attribute_bits.h:57
void set_double(const char *attr_name, double v)
Definition: server_telemetry_attribute_bits.h:92
void set_string(const char *attr_name, const char *v)
Definition: server_telemetry_attribute_bits.h:98
void set_string_view(const char *attr_name, const char *v, size_t len)
Definition: server_telemetry_attribute_bits.h:104
void set_bool(const char *attr_name, bool v)
Definition: server_telemetry_attribute_bits.h:62
void set_uint64(const char *attr_name, uint64_t v)
Definition: server_telemetry_attribute_bits.h:86