tracelit 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tracelit/configuration.rb +14 -0
- data/lib/tracelit/instrumentation.rb +23 -4
- data/lib/tracelit/metrics.rb +4 -1
- data/lib/tracelit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac30fca1b8142f07af651ef3b03f63f4f1862e38c14fae393e2855f563f19c5b
|
|
4
|
+
data.tar.gz: 935de9e4afefc7f6f635677f551d8ce6115365fa7e62142cba4d558ae1ade1f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34b639abf3f4cec8aa267ca1f78b1a6349b2e4ee7c1995d60f04f8b95dd79a916ab82b717b1989bd417f6315ef5882b6720d66413d18546c9e8e7fbedbe6d854
|
|
7
|
+
data.tar.gz: 77f510e3104ddb98fe9349d380a2b246dbfa339232bd8694461ccbcc679d6f8c7ce0ffca9972c118643bf402b62932636b95ced8294001d1bd836a196f0d9466
|
|
@@ -99,5 +99,19 @@ module Tracelit
|
|
|
99
99
|
return ::Rails.application.class.module_parent_name.underscore if defined?(::Rails)
|
|
100
100
|
"unknown-service"
|
|
101
101
|
end
|
|
102
|
+
|
|
103
|
+
# Returns resource_attributes with all keys coerced to strings and any
|
|
104
|
+
# values that are not OTel-primitive (String, Integer, Float, true/false)
|
|
105
|
+
# removed. This prevents ConfigurationError when users pass symbols, nils,
|
|
106
|
+
# or other non-primitive values as resource attribute values.
|
|
107
|
+
PRIMITIVE_TYPES = [String, Integer, Float, TrueClass, FalseClass].freeze
|
|
108
|
+
private_constant :PRIMITIVE_TYPES
|
|
109
|
+
|
|
110
|
+
def sanitized_resource_attributes
|
|
111
|
+
resource_attributes.each_with_object({}) do |(k, v), h|
|
|
112
|
+
next unless PRIMITIVE_TYPES.any? { |t| v.is_a?(t) }
|
|
113
|
+
h[k.to_s] = v
|
|
114
|
+
end
|
|
115
|
+
end
|
|
102
116
|
end
|
|
103
117
|
end
|
|
@@ -40,9 +40,10 @@ module Tracelit
|
|
|
40
40
|
|
|
41
41
|
OpenTelemetry::SDK.configure do |otel|
|
|
42
42
|
# Resource attributes identify this service in Tracelit.
|
|
43
|
-
#
|
|
43
|
+
# Keys are coerced to strings; non-primitive values are dropped to
|
|
44
|
+
# prevent ConfigurationError from Resource.create validation.
|
|
44
45
|
base_attrs = {
|
|
45
|
-
OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME
|
|
46
|
+
OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => config.resolved_service_name,
|
|
46
47
|
OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT => config.environment,
|
|
47
48
|
"telemetry.sdk.language" => "ruby",
|
|
48
49
|
"telemetry.sdk.name" => detect_framework,
|
|
@@ -52,7 +53,7 @@ module Tracelit
|
|
|
52
53
|
base_attrs["service.commit_sha"] = sha if sha
|
|
53
54
|
|
|
54
55
|
otel.resource = OpenTelemetry::SDK::Resources::Resource.create(
|
|
55
|
-
base_attrs.merge(config.
|
|
56
|
+
base_attrs.merge(config.sanitized_resource_attributes)
|
|
56
57
|
)
|
|
57
58
|
|
|
58
59
|
# Build the OTLP exporter once — shared by both processors
|
|
@@ -82,6 +83,21 @@ module Tracelit
|
|
|
82
83
|
otel.use_all
|
|
83
84
|
end
|
|
84
85
|
|
|
86
|
+
# Guard: if the SDK configure block failed internally (e.g. a bad
|
|
87
|
+
# resource attribute or instrumentation error caught by the error
|
|
88
|
+
# handler), the global tracer provider is still the ProxyTracerProvider
|
|
89
|
+
# and does not respond to .resource. Detect this and bail out cleanly
|
|
90
|
+
# instead of letting setup_logs / Metrics.setup fail with cryptic errors.
|
|
91
|
+
unless OpenTelemetry.tracer_provider.respond_to?(:resource)
|
|
92
|
+
OpenTelemetry.logger.warn(
|
|
93
|
+
"[Tracelit] OTel SDK did not initialize correctly — " \
|
|
94
|
+
"tracer provider is still a proxy. " \
|
|
95
|
+
"Check the configuration errors logged above. " \
|
|
96
|
+
"Logs and metrics pipelines will not start."
|
|
97
|
+
)
|
|
98
|
+
return
|
|
99
|
+
end
|
|
100
|
+
|
|
85
101
|
# Set sampler after configure — Configurator does not expose
|
|
86
102
|
# sampler= in OTel SDK 1.x, must be set on the provider directly.
|
|
87
103
|
# Skip at 1.0: the default AlwaysOn sampler is correct and we do not touch it.
|
|
@@ -153,8 +169,11 @@ module Tracelit
|
|
|
153
169
|
}
|
|
154
170
|
)
|
|
155
171
|
|
|
172
|
+
tp = OpenTelemetry.tracer_provider
|
|
173
|
+
resource = tp.respond_to?(:resource) ? tp.resource : OpenTelemetry::SDK::Resources::Resource.create({})
|
|
174
|
+
|
|
156
175
|
logger_provider = OpenTelemetry::SDK::Logs::LoggerProvider.new(
|
|
157
|
-
resource:
|
|
176
|
+
resource: resource
|
|
158
177
|
)
|
|
159
178
|
|
|
160
179
|
logger_provider.add_log_record_processor(
|
data/lib/tracelit/metrics.rb
CHANGED
|
@@ -29,8 +29,11 @@ module Tracelit
|
|
|
29
29
|
export_timeout_millis: 10_000
|
|
30
30
|
)
|
|
31
31
|
|
|
32
|
+
tp = OpenTelemetry.tracer_provider
|
|
33
|
+
resource = tp.respond_to?(:resource) ? tp.resource : OpenTelemetry::SDK::Resources::Resource.create({})
|
|
34
|
+
|
|
32
35
|
provider = OpenTelemetry::SDK::Metrics::MeterProvider.new(
|
|
33
|
-
resource:
|
|
36
|
+
resource: resource
|
|
34
37
|
)
|
|
35
38
|
provider.add_metric_reader(reader)
|
|
36
39
|
|
data/lib/tracelit/version.rb
CHANGED