Class: Tracekit::EndpointResolver
- Inherits:
-
Object
- Object
- Tracekit::EndpointResolver
- Defined in:
- lib/tracekit/endpoint_resolver.rb
Overview
Resolves endpoint URLs for different TraceKit services (traces, metrics, snapshots) Implements the same logic as .NET, Go, and Java SDKs for consistency
CRITICAL: This must match the exact behavior across all SDK implementations
Class Method Summary collapse
-
.extract_base_url(full_url) ⇒ String
Extracts base URL (scheme + host + port) from full URL Always strips any path component, regardless of what it is.
-
.resolve(endpoint, path, use_ssl) ⇒ String
Resolves a full endpoint URL from a base endpoint and path.
Class Method Details
.extract_base_url(full_url) ⇒ String
Extracts base URL (scheme + host + port) from full URL Always strips any path component, regardless of what it is
63 64 65 66 |
# File 'lib/tracekit/endpoint_resolver.rb', line 63 def extract_base_url(full_url) match = full_url.match(%r{^(https?://[^/]+)}) match ? match[1] : full_url end |
.resolve(endpoint, path, use_ssl) ⇒ String
Resolves a full endpoint URL from a base endpoint and path
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tracekit/endpoint_resolver.rb', line 26 def resolve(endpoint, path, use_ssl) # Case 1: Endpoint has a scheme (http:// or https://) if endpoint.start_with?("http://", "https://") # Remove trailing slash endpoint = endpoint.chomp("/") # Check if endpoint has a path component (anything after the host) without_scheme = endpoint.sub(%r{^https?://}i, "") if without_scheme.include?("/") # Endpoint has a path component - extract base and append correct path base_url = extract_base_url(endpoint) return path.empty? ? base_url : "#{base_url}#{path}" end # Just host with scheme, add the path return "#{endpoint}#{path}" end # Case 2: No scheme provided - build URL with scheme scheme = use_ssl ? "https://" : "http://" endpoint = endpoint.chomp("/") "#{scheme}#{endpoint}#{path}" end |