Class: Labkit::Tracing::OpenTelemetryFactory
- Inherits:
-
Object
- Object
- Labkit::Tracing::OpenTelemetryFactory
- Defined in:
- lib/labkit/tracing/open_telemetry_factory.rb
Overview
OpenTelemetryFactory will configure OpenTelemetry distributed tracing
Constant Summary collapse
- OTLP_SCHEME =
"otlp"- DEFAULT_HTTP_ENDPOINT =
The default endpoint for OTLP HTTP exporter
"http://localhost:4318/v1/traces"
Class Method Summary collapse
-
.create_tracer(service_name, connection_string) {|config| ... } ⇒ Tracer?
The configured tracer or nil if initialization fails.
Class Method Details
.create_tracer(service_name, connection_string) {|config| ... } ⇒ Tracer?
Returns The configured tracer or nil if initialization fails.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/labkit/tracing/open_telemetry_factory.rb', line 26 def create_tracer(service_name, connection_string, &) return unless connection_string.present? = parse_otlp_connection_string(connection_string) # The service_name parameter from GITLAB_TRACING takes precedence over the application one service_name = [:service_name] if [:service_name] # parse exporter headers as necessary headers = build_headers() # Get sampler and exporter from GITLAB_TRACING sampler = get_sampler([:sampler], [:sampler_param]) exporter = get_exporter([:http_endpoint], [:udp_endpoint], headers) # Build base resource base_resource = OpenTelemetry::SDK::Resources::Resource.create( OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => service_name ) configure(service_name, base_resource, sampler, exporter, &) extra_params = .except( :sampler, :sampler_param, :http_endpoint, :udp_endpoint, :strict_parsing, :debug, :service_name ) if extra_params.present? = "opentelemetry tracer: invalid option: #{extra_params.keys.join(', ')}" raise if [:strict_parsing] warn end OpenTelemetry.tracer_provider.tracer(service_name) end |