33
44#include < cctype>
55#include < cstdlib>
6- #include < ostream>
76#include < string>
87
98#include " opentelemetry/sdk/common/env_variables.h"
10- #include " opentelemetry/sdk/common/global_log_handler.h"
119#include " opentelemetry/sdk/configuration/document_node.h"
1210#include " opentelemetry/sdk/configuration/invalid_schema_exception.h"
1311#include " opentelemetry/version.h"
@@ -26,7 +24,7 @@ namespace configuration
2624 * - Some text with ${SUBSTITUTION} in it
2725 * - Multiple ${SUBSTITUTION_A} substitutions ${SUBSTITUTION_B} in the line
2826 */
29- std::string DocumentNode::DoSubstitution (const std::string &text)
27+ std::string DocumentNode::DoSubstitution (const std::string &text) const
3028{
3129 static std::string begin_token{" ${" };
3230 static std::string end_token{" }" };
@@ -90,9 +88,9 @@ std::string DocumentNode::DoSubstitution(const std::string &text)
9088 - ${ENV_NAME:-fallback} (including when ENV_NAME is actually "env")
9189 - ${env:ENV_NAME:-fallback}
9290*/
93- std::string DocumentNode::DoOneSubstitution (const std::string &text)
91+ std::string DocumentNode::DoOneSubstitution (const std::string &text) const
9492{
95- static std::string illegal_msg{" Illegal substitution expression" };
93+ static std::string illegal_msg{" Illegal substitution expression: " };
9694
9795 static std::string env_token{" env:" };
9896 static std::string env_with_replacement{" env:-" };
@@ -112,29 +110,33 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
112110
113111 if (len < 4 )
114112 {
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);
117116 }
118117
119118 c = text[0 ];
120119 if (c != ' $' )
121120 {
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);
124124 }
125125
126126 c = text[1 ];
127127 if (c != ' {' )
128128 {
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);
131132 }
132133
133134 c = text[len - 1 ];
134135 if (c != ' }' )
135136 {
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);
138140 }
139141
140142 begin_name = 2 ;
@@ -156,8 +158,9 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
156158 c = text[begin_name];
157159 if (!std::isalpha (c) && c != ' _' )
158160 {
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);
161164 }
162165
163166 end_name = begin_name + 1 ;
@@ -190,8 +193,9 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
190193 pos = text.find (replacement_token, end_name);
191194 if (pos != end_name)
192195 {
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);
195199 }
196200 // text is of the form ${ENV_NAME:-fallback}
197201 begin_fallback = pos + replacement_token.length ();
@@ -215,7 +219,7 @@ std::string DocumentNode::DoOneSubstitution(const std::string &text)
215219 return fallback;
216220}
217221
218- bool DocumentNode::BooleanFromString (const std::string &value)
222+ bool DocumentNode::BooleanFromString (const std::string &value) const
219223{
220224 if (value == " true" )
221225 {
@@ -227,34 +231,37 @@ bool DocumentNode::BooleanFromString(const std::string &value)
227231 return false ;
228232 }
229233
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);
232237}
233238
234- size_t DocumentNode::IntegerFromString (const std::string &value)
239+ size_t DocumentNode::IntegerFromString (const std::string &value) const
235240{
236241 const char *ptr = value.c_str ();
237242 char *end = nullptr ;
238243 size_t len = value.length ();
239244 size_t val = strtoll (ptr, &end, 10 );
240245 if (ptr + len != end)
241246 {
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);
244250 }
245251 return val;
246252}
247253
248- double DocumentNode::DoubleFromString (const std::string &value)
254+ double DocumentNode::DoubleFromString (const std::string &value) const
249255{
250256 const char *ptr = value.c_str ();
251257 char *end = nullptr ;
252258 size_t len = value.length ();
253259 double val = strtod (ptr, &end);
254260 if (ptr + len != end)
255261 {
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);
258265 }
259266 return val;
260267}
0 commit comments