lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.22.0 vs lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.23.0
- old
+ new
@@ -52,13 +52,13 @@
def query(sql, options = {})
attributes = client_attributes
case config[:db_statement]
when :include
- attributes['db.statement'] = sql
+ attributes[SemanticConventions::Trace::DB_STATEMENT] = sql
when :obfuscate
- attributes['db.statement'] = obfuscate_sql(sql)
+ attributes[SemanticConventions::Trace::DB_STATEMENT] = obfuscate_sql(sql)
end
tracer.in_span(
database_span_name(sql),
attributes: attributes.merge!(OpenTelemetry::Instrumentation::Mysql2.attributes),
kind: :client
@@ -76,11 +76,12 @@
obfuscated = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)
obfuscated = obfuscated.gsub(generated_mysql_regex, '?')
obfuscated = 'Failed to obfuscate SQL query - quote characters remained after obfuscation' if detect_unmatched_pairs(obfuscated)
obfuscated
end
- rescue StandardError
+ rescue StandardError => e
+ OpenTelemetry.handle_error(message: 'Failed to obfuscate SQL', exception: e)
'OpenTelemetry error: failed to obfuscate sql'
end
def generated_mysql_regex
@generated_mysql_regex ||= Regexp.union(MYSQL_COMPONENTS.map { |component| COMPONENTS_REGEX_MAP[component] })
@@ -100,11 +101,11 @@
when :statement_type
extract_statement_type(sql)
when :db_name
database_name
when :db_operation_and_name
- op = OpenTelemetry::Instrumentation::Mysql2.attributes['db.operation']
+ op = OpenTelemetry::Instrumentation::Mysql2.attributes[SemanticConventions::Trace::DB_OPERATION]
name = database_name
if op && name
"#{op} #{name}"
elsif op
op
@@ -125,15 +126,15 @@
# https://github.com/brianmario/mysql2/blob/ca08712c6c8ea672df658bb25b931fea22555f27/lib/mysql2/client.rb#L25-L26
host = (query_options[:host] || query_options[:hostname]).to_s
port = query_options[:port].to_s
attributes = {
- 'db.system' => 'mysql',
- 'net.peer.name' => host,
- 'net.peer.port' => port
+ SemanticConventions::Trace::DB_SYSTEM => 'mysql',
+ SemanticConventions::Trace::NET_PEER_NAME => host,
+ SemanticConventions::Trace::NET_PEER_PORT => port
}
- attributes['db.name'] = database_name if database_name
- attributes['peer.service'] = config[:peer_service] if config[:peer_service]
+ attributes[SemanticConventions::Trace::DB_NAME] = database_name if database_name
+ attributes[SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
attributes
end
def tracer
Mysql2::Instrumentation.instance.tracer