lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.21.1 vs lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.22.0
- old
+ new
@@ -93,23 +93,26 @@
# literals. In such a case, we'll replace the entire query with a
# placeholder.
%r{'|"|\/\*|\*\/}.match(obfuscated)
end
- def database_span_name(sql)
- # Setting span name to the SQL query without obfuscation would
- # result in PII + cardinality issues.
- # First attempt to infer the statement type then fallback to
- # current Otel approach {database.component_name}.{database_instance_name}
- # https://github.com/open-telemetry/opentelemetry-python/blob/39fa078312e6f41c403aa8cad1868264011f7546/ext/opentelemetry-ext-dbapi/tests/test_dbapi_integration.py#L53
- # This creates span names like mysql.default, mysql.replica, postgresql.staging etc.
-
- statement_type = extract_statement_type(sql)
-
- return statement_type unless statement_type.nil?
-
- # fallback
- database_name ? "mysql.#{database_name}" : 'mysql'
+ def database_span_name(sql) # rubocop:disable Metrics/CyclomaticComplexity
+ case config[:span_name]
+ when :statement_type
+ extract_statement_type(sql)
+ when :db_name
+ database_name
+ when :db_operation_and_name
+ op = OpenTelemetry::Instrumentation::Mysql2.attributes['db.operation']
+ name = database_name
+ if op && name
+ "#{op} #{name}"
+ elsif op
+ op
+ elsif name
+ name
+ end
+ end || 'mysql'
end
def database_name
# https://github.com/brianmario/mysql2/blob/ca08712c6c8ea672df658bb25b931fea22555f27/lib/mysql2/client.rb#L78
(query_options[:database] || query_options[:dbname] || query_options[:db])&.to_s