3
3
4
4
#include < cctype>
5
5
#include < cstdlib>
6
- #include < ostream>
7
6
#include < string>
8
7
9
8
#include " opentelemetry/sdk/common/env_variables.h"
10
- #include " opentelemetry/sdk/common/global_log_handler.h"
11
9
#include " opentelemetry/sdk/configuration/document_node.h"
12
10
#include " opentelemetry/sdk/configuration/invalid_schema_exception.h"
13
11
#include " opentelemetry/version.h"
@@ -26,7 +24,7 @@ namespace configuration
26
24
* - Some text with ${SUBSTITUTION} in it
27
25
* - Multiple ${SUBSTITUTION_A} substitutions ${SUBSTITUTION_B} in the line
28
26
*/
29
- std::string DocumentNode::DoSubstitution (const std::string &text)
27
+ std::string DocumentNode::DoSubstitution (const std::string &text) const
30
28
{
31
29
static std::string begin_token{" ${" };
32
30
static std::string end_token{" }" };
@@ -90,9 +88,9 @@ std::string DocumentNode::DoSubstitution(const std::string &text)
90
88
- ${ENV_NAME:-fallback} (including when ENV_NAME is actually "env")
91
89
- ${env:ENV_NAME:-fallback}
92
90
*/
93
- std::string DocumentNode::DoOneSubstitution (const std::string &text)
91
+ std::string DocumentNode::DoOneSubstitution (const std::string &text) const
94
92
{
95
- static std::string illegal_msg{" Illegal substitution expression" };
93
+ static std::string illegal_msg{" Illegal substitution expression: " };
96
94
97
95
static std::string env_token{" env:" };
98
96
static std::string env_with_replacement{" env:-" };
@@ -112,29 +110,33 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
112
110
113
111
if (len < 4 )
114
112
{
115
- OTEL_INTERNAL_LOG_ERROR (illegal_msg << " : " << text);
116
- throw InvalidSchemaException (illegal_msg);
113
+ std::string message = illegal_msg;
114
+ message.append (text);
115
+ throw InvalidSchemaException (message);
117
116
}
118
117
119
118
c = text[0 ];
120
119
if (c != ' $' )
121
120
{
122
- OTEL_INTERNAL_LOG_ERROR (illegal_msg << " : " << text);
123
- throw InvalidSchemaException (illegal_msg);
121
+ std::string message = illegal_msg;
122
+ message.append (text);
123
+ throw InvalidSchemaException (message);
124
124
}
125
125
126
126
c = text[1 ];
127
127
if (c != ' {' )
128
128
{
129
- OTEL_INTERNAL_LOG_ERROR (illegal_msg << " : " << text);
130
- throw InvalidSchemaException (illegal_msg);
129
+ std::string message = illegal_msg;
130
+ message.append (text);
131
+ throw InvalidSchemaException (message);
131
132
}
132
133
133
134
c = text[len - 1 ];
134
135
if (c != ' }' )
135
136
{
136
- OTEL_INTERNAL_LOG_ERROR (illegal_msg << " : " << text);
137
- throw InvalidSchemaException (illegal_msg);
137
+ std::string message = illegal_msg;
138
+ message.append (text);
139
+ throw InvalidSchemaException (message);
138
140
}
139
141
140
142
begin_name = 2 ;
@@ -156,8 +158,9 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
156
158
c = text[begin_name];
157
159
if (!std::isalpha (c) && c != ' _' )
158
160
{
159
- OTEL_INTERNAL_LOG_ERROR (illegal_msg << " : " << text);
160
- throw InvalidSchemaException (illegal_msg);
161
+ std::string message = illegal_msg;
162
+ message.append (text);
163
+ throw InvalidSchemaException (message);
161
164
}
162
165
163
166
end_name = begin_name + 1 ;
@@ -190,8 +193,9 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
190
193
pos = text.find (replacement_token, end_name);
191
194
if (pos != end_name)
192
195
{
193
- OTEL_INTERNAL_LOG_ERROR (illegal_msg << " : " << text);
194
- throw InvalidSchemaException (illegal_msg);
196
+ std::string message = illegal_msg;
197
+ message.append (text);
198
+ throw InvalidSchemaException (message);
195
199
}
196
200
// text is of the form ${ENV_NAME:-fallback}
197
201
begin_fallback = pos + replacement_token.length ();
@@ -215,7 +219,7 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
215
219
return fallback;
216
220
}
217
221
218
- bool DocumentNode::BooleanFromString (const std::string &value)
222
+ bool DocumentNode::BooleanFromString (const std::string &value) const
219
223
{
220
224
if (value == " true" )
221
225
{
@@ -227,34 +231,37 @@ bool DocumentNode::BooleanFromString(const std::string &value)
227
231
return false ;
228
232
}
229
233
230
- OTEL_INTERNAL_LOG_ERROR (" Illegal integer value: " << value);
231
- throw InvalidSchemaException (" Illegal bool value" );
234
+ std::string message (" Illegal boolean value: " );
235
+ message.append (value);
236
+ throw InvalidSchemaException (message);
232
237
}
233
238
234
- size_t DocumentNode::IntegerFromString (const std::string &value)
239
+ size_t DocumentNode::IntegerFromString (const std::string &value) const
235
240
{
236
241
const char *ptr = value.c_str ();
237
242
char *end = nullptr ;
238
243
size_t len = value.length ();
239
244
size_t val = strtoll (ptr, &end, 10 );
240
245
if (ptr + len != end)
241
246
{
242
- OTEL_INTERNAL_LOG_ERROR (" Illegal integer value: " << value);
243
- throw InvalidSchemaException (" Illegal integer value" );
247
+ std::string message (" Illegal integer value: " );
248
+ message.append (value);
249
+ throw InvalidSchemaException (message);
244
250
}
245
251
return val;
246
252
}
247
253
248
- double DocumentNode::DoubleFromString (const std::string &value)
254
+ double DocumentNode::DoubleFromString (const std::string &value) const
249
255
{
250
256
const char *ptr = value.c_str ();
251
257
char *end = nullptr ;
252
258
size_t len = value.length ();
253
259
double val = strtod (ptr, &end);
254
260
if (ptr + len != end)
255
261
{
256
- OTEL_INTERNAL_LOG_ERROR (" Illegal double value: " << value);
257
- throw InvalidSchemaException (" Illegal double value" );
262
+ std::string message (" Illegal double value: " );
263
+ message.append (value);
264
+ throw InvalidSchemaException (message);
258
265
}
259
266
return val;
260
267
}
0 commit comments