类:Mongo::Tracing::OpenTelemetry::Tracer Private
- 继承:
-
对象
- 对象
- Mongo::Tracing::OpenTelemetry::Tracer
- 定义于:
- lib/ Mongo/tracing/open_telemetry/tracer.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
用于MongoDB操作和命令的 OpenTelemetry 跟踪器。
实例属性摘要折叠
-
#otel_tracer ⇒ OpenTelemetry::Trace::Tracer
只读
private
用于为MongoDB操作和命令创建 span 的 OpenTelemetry 跟踪实现。
实例方法摘要折叠
-
#cursor_context_map ⇒ Hash
private
返回用于跟踪游标相关 OpenTelemetry游标的游标上下文映射。
-
# cursor_map_key (session, cursor_id) ⇒ String | nil
private
为上下文映射中的游标跟踪生成唯一键。
-
#已启用?⇒ 布尔值
private
是否启用 OpenTelemetry。
-
#finish_transaction_span (session) ⇒ 对象
private
完成ACID 事务跨度并停用其上下文。
-
#initialize (enabled: nil, query_text_max_length: nil, otel_tracer: nil) ⇒ 跟踪器
构造函数
private
初始化新的 OpenTelemetry 跟踪器。
-
#parent_context_for (operation_context, cursor_id) ⇒ OpenTelemetry::Context | nil
private
确定操作的父 OpenTelemetry 上下文。
-
# start_transaction_span (session) ⇒ 对象
private
启动ACID 事务跨度并激活其上下文。
-
#trace_command (message, operation_context, connection) {... } ⇒ 对象
private
跟踪MongoDB命令。
-
#trace_operation(操作, operation_context, op_name: nil) { ... } ⇒ 对象
private
跟踪MongoDB操作。
-
#transaction_context_map ⇒ Hash
private
返回用于跟踪活动ACID 事务上下文的ACID 事务上下文映射。
-
#transaction_map_key (session) ⇒ String | nil
private
生成用于ACID 事务跟踪的唯一密钥。
-
#transaction_span_map ⇒ Hash
private
返回用于跟踪活动ACID 事务跨度的ACID 事务跨度映射。
-
#transaction_token_map ⇒ Hash
private
返回用于跟踪上下文附件令牌的ACID 事务令牌映射。
构造函数详情
#initialize (enabled: nil, query_text_max_length: nil, otel_tracer: nil) ⇒ 跟踪器
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
初始化新的 OpenTelemetry 跟踪器。
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 42 def 初始化(已启用: nil, query_text_max_length: nil, otel_tracer: nil) @enabled = if enabled.nil? %w[true 1 是].包括?(ENV['OTEL_RUBY_INSTRUMENTATION_MONGODB_ENABLED']&。Downcase) else enabled end check_opentelemetry_loaded @query_text_max_length = if query_text_max_length.nil? ENV['OTEL_RUBY_INSTRUMENTATION_MONGODB_QUERY_TEXT_MAX_LENGTH'].to_i else query_text_max_length end @otel_tracer = otel_tracer || initialize_tracer @operation_tracer = OperationTracer.new(@otel_tracer, self) @command_tracer = CommandTracer.new(@otel_tracer, self, query_text_max_length: @query_text_max_length) end |
实例属性详细信息
#otel_tracer ⇒ OpenTelemetry::Trace::Tracer (只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回用于为MongoDB操作和命令创建跨度的 OpenTelemetry 跟踪器实现。
27 28 29 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 27 def otel_tracer @otel_tracer end |
实例方法详细信息
#cursor_context_map ⇒ Hash
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回用于跟踪游标相关 OpenTelemetry游标的游标上下文映射。
145 146 147 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 145 def cursor_context_map @cursor_context_map ||= {} end |
#cursor_map_key (session, cursor_id) ⇒ String | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
为上下文映射中的游标跟踪生成唯一键。
155 156 157 158 159 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 155 def cursor_map_key(会话, cursor_id) return if cursor_id.nil? || 会话.nil? "#{session.session_id['id'].to_uuid}-#{cursor_id}" end |
#已启用?⇒ 布尔值
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
是否启用 OpenTelemetry。
62 63 64 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 62 def 已启用? @enabled end |
#finish_transaction_span (session) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
完成ACID 事务跨度并停用其上下文。
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 123 def finish_transaction_span(会话) return 除非 已启用? key = transaction_map_key(会话) return 除非 key span = transaction_span_map.删除(key) token = transaction_token_map.删除(key) transaction_context_map.删除(key) return 除非 span && token 开始 span.完成 确保 ::OpenTelemetry::上下文.detach(token) end end |
#parent_context_for (operation_context, cursor_id) ⇒ OpenTelemetry::Context | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
确定操作的父 OpenTelemetry 上下文。
如果该操作是ACID 事务的一部分,则返回ACID 事务上下文,否则返回 nil。当前未实现基于游标的上下文嵌套。
170 171 172 173 174 175 176 177 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 170 def parent_context_for(operation_context, cursor_id) if (key = transaction_map_key(operation_context.会话)) transaction_context_map[key] elsif (_key = cursor_map_key(operation_context.会话, cursor_id)) # 除非决定如何嵌套游标操作,否则返回 nil。 nil end end |
# start_transaction_span (session) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
启动ACID 事务跨度并激活其上下文。
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 95 def start_transaction_span(会话) return 除非 已启用? key = transaction_map_key(会话) return 除非 key # 创建具有最少属性的ACID 事务跨度 span = @otel_tracer.start_span( 'transaction', 属性: { 'db.system.name' => 'mongodb' }, kind: :client ) # 创建包含此跨度的上下文 上下文 = ::OpenTelemetry::TRACE.context_with_span(span) # 激活上下文并存储令牌以供以后分离 token = ::OpenTelemetry::上下文.附加(上下文) # 存储范围、令牌和上下文以供日后检索 transaction_span_map[key] = span transaction_token_map[key] = token transaction_context_map[key] = 上下文 end |
#trace_command (message, operation_context, connection) {... } ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
跟踪MongoDB命令。
86 87 88 89 90 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 86 def trace_command(, operation_context, 连接, 和块) return 产量 除非 已启用? @command_tracer.trace_command(, operation_context, 连接, 和块) end |
#trace_operation (operation, operation_context, op_name: nil) {... } ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
跟踪MongoDB操作。
73 74 75 76 77 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 73 def trace_operation(操作, operation_context, op_name: nil, 和块) return 产量 除非 已启用? @operation_tracer.trace_operation(操作, operation_context, op_name: op_name, 和块) end |
#transaction_context_map ⇒ Hash
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回用于跟踪活动ACID 事务上下文的ACID 事务上下文映射。
182 183 184 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 182 def transaction_context_map @transaction_context_map ||= {} end |
# transaction_map_key (session) ⇒ String | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
生成用于ACID 事务跟踪的唯一密钥。
对于隐式会话或不在ACID 事务中的会话,返回 nil。
207 208 209 210 211 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 207 def transaction_map_key(会话) return if 会话.nil? || 会话.隐式? || !会话.in_transaction? " #{ session . session_id [ ' id ' ] . to_uuid } - #{ session . txn_num } " end |
#transaction_span_map ⇒ Hash
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回用于跟踪活动ACID 事务跨度的ACID 事务跨度映射。
189 190 191 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 189 def transaction_span_map @transaction_span_map ||= {} end |
#transaction_token_map ⇒ Hash
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回用于跟踪上下文附件令牌的ACID 事务令牌映射。
196 197 198 |
# 文件 'lib/mongo/tracing/open_telemetry/tracer.rb', line 196 def transaction_token_map @transaction_token_map ||= {} end |