foam-otel 3.0.0.alpha.2 → 3.0.0.alpha.3

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.
data/README.md CHANGED
@@ -23,20 +23,17 @@ bundle install
23
23
 
24
24
  ## Initialize
25
25
 
26
- Call `init` once, before the app loads, so OpenTelemetry can instrument
27
- libraries as they are required. Set `enabled: false` to turn Foam off.
26
+ Call `init` once, after the app's gems are loaded and before the app runs. Set `enabled: false` to turn Foam off.
28
27
 
29
- Store the ingest token as `FOAM_OTEL_TOKEN` and pass `ENV["FOAM_OTEL_TOKEN"]`
30
- to `init`.
28
+ Store the ingest token as `FOAM_OTEL_TOKEN` and pass `ENV["FOAM_OTEL_TOKEN"]` to `init`.
31
29
 
32
30
  ### Rails
33
31
 
34
- TODO(jhartquist)
32
+ TODO(jhartquist): Rails setup. The Railtie that adds Foam's Rack middleware is not written, so a Rails app is not covered by header and body capture on server spans until it is.
35
33
 
36
34
  ### Plain Ruby and Rack
37
35
 
38
- Call `init` at the top of `config.ru`, then add the OpenTelemetry Rack
39
- middleware and Foam's:
36
+ Call `init` at the top of `config.ru`, then add the OpenTelemetry Rack middleware and Foam's:
40
37
 
41
38
  ```ruby
42
39
  require "foam/otel"
@@ -54,72 +51,43 @@ use Foam::Rack::Middleware
54
51
  run App
55
52
  ```
56
53
 
54
+ Foam's middleware sets the `content-type`, `content-length`, and `content-encoding` headers on server spans and, in `:advanced` mode, captures bodies. See Network capture.
55
+
57
56
  ## Instrumentation
58
57
 
59
- `init` installs OpenTelemetry's Ruby instrumentation bundle,
60
- `opentelemetry-instrumentation-all`, and the standard library logger
61
- bridge, `opentelemetry-instrumentation-logger`. An instrumentation
62
- installs only when its library is loaded before `init`, so call `init`
63
- after `Bundler.require` or after the app's own requires. A library loaded after
64
- `init` is not instrumented, and a warning is written to stderr once when
65
- `state` finds one. `state[:instrumentations]` lists what installed.
66
-
67
- The bundle covers: action_mailer, action_pack, action_view, active_job,
68
- active_model_serializers, active_record, active_storage, active_support,
69
- anthropic, aws_lambda, aws_sdk, bunny, concurrent_ruby, dalli, delayed_job,
70
- ethon, excon, faraday, grape, graphql, grpc, gruf, http, http_client, httpx,
71
- koala, lmdb, logger, mongo, mysql2, net_http, pg, que, racecar, rack, rails,
72
- rake, rdkafka, redis, resque, restclient, ruby_kafka, sidekiq, sinatra,
73
- trilogy.
74
-
75
- To install an instrumentation outside the bundle, list it in
76
- `additional_instrumentations`.
58
+ `init` installs OpenTelemetry's Ruby instrumentation bundle, `opentelemetry-instrumentation-all`, and the standard library logger bridge, `opentelemetry-instrumentation-logger`. An instrumentation installs only when its library is loaded before `init`, so call `init` after `Bundler.require` or after the app's own requires. A library loaded after `init` is not instrumented, and a warning is written to stderr once when `state` finds one. `state[:instrumentations]` lists what installed.
59
+
60
+ The bundle covers: action_mailer, action_pack, action_view, active_job, active_model_serializers, active_record, active_storage, active_support, anthropic, aws_lambda, aws_sdk, bunny, concurrent_ruby, dalli, delayed_job, ethon, excon, faraday, grape, graphql, grpc, gruf, http, http_client, httpx, koala, lmdb, mongo, mysql2, net_http, pg, que, racecar, rack, rails, rake, rdkafka, redis, resque, restclient, ruby_kafka, sidekiq, sinatra, trilogy.
61
+
62
+ To install an instrumentation outside the bundle, list it in `additional_instrumentations`.
77
63
 
78
64
  TODO(jhartquist): Revisit and review this compatibility guidance.
79
65
 
80
66
  ### Instrumentation versions
81
67
 
82
- Bundler keeps one version of each gem in the application. By the time Foam
83
- starts, those versions are already fixed. `additional_instrumentations` only
84
- configures an instrumentation that Bundler installed and Ruby loaded; it
85
- cannot choose or install another version.
86
-
87
- If a bundled instrumentation does not support the library version your app
88
- uses, pin a compatible `opentelemetry-instrumentation-*` gem in the `Gemfile`
89
- and run `bundle install` again.
90
-
91
- If Bundler accepts the pin, restart the app and the whole bundle will use that
92
- instrumentation version. If it conflicts with `foam-otel` or
93
- `opentelemetry-instrumentation-all`, those versions cannot live in the same
94
- bundle. At that point, change the application library, use a compatible Foam
95
- release, or accept the telemetry gap: the app can keep running, but Foam will
96
- not receive the spans that instrumentation would have produced.
97
-
98
- Even a successful `bundle install` only means the declared gem dependencies
99
- agree. The instrumentation checks the target library when `init` runs. If the
100
- target is unsupported, Foam leaves that instrumentation out of
101
- `state[:instrumentations]`. `additional_instrumentations` cannot bypass the
102
- check or load a second version of the gem.
103
-
104
- The `pg`, `mysql2`, and `trilogy` instrumentations send the full SQL
105
- statement (`db_statement: :include`); the others keep their upstream
106
- defaults. To disable one instrumentation or change its options, pass it
107
- in `additional_instrumentations` or use the upstream environment
108
- variables, which take precedence:
109
- `OTEL_RUBY_INSTRUMENTATION_<NAME>_ENABLED=false` and
110
- `OTEL_RUBY_INSTRUMENTATION_<NAME>_CONFIG_OPTS`, where `<NAME>` is the
111
- instrumentation's class name after `OpenTelemetry::Instrumentation::`,
112
- upper-cased, with `::` replaced by `_`: `PG`, `NET_HTTP`, `ACTIVERECORD`.
68
+ Bundler keeps one version of each gem in the application. By the time Foam starts, those versions are already fixed. `additional_instrumentations` only configures an instrumentation that Bundler installed and Ruby loaded; it cannot choose or install another version.
69
+
70
+ If a bundled instrumentation does not support the library version your app uses, pin a compatible `opentelemetry-instrumentation-*` gem in the `Gemfile` and run `bundle install` again.
71
+
72
+ If Bundler accepts the pin, restart the app and the whole bundle will use that instrumentation version. If it conflicts with `foam-otel` or `opentelemetry-instrumentation-all`, those versions cannot live in the same bundle. At that point, change the application library, use a compatible Foam release, or accept the telemetry gap: the app can keep running, but Foam will not receive the spans that instrumentation would have produced.
73
+
74
+ Even a successful `bundle install` only means the declared gem dependencies agree. The instrumentation checks the target library when `init` runs. If the target is unsupported, Foam leaves that instrumentation out of `state[:instrumentations]`. `additional_instrumentations` cannot bypass the check or load a second version of the gem.
75
+
76
+ The `pg`, `mysql2`, and `trilogy` instrumentations obfuscate SQL statements (`db_statement: :obfuscate`, their default), replacing every literal with `?`, so `WHERE email = 'ada@example.com'` is exported as `WHERE email = ?`. A statement over 2000 characters is exported as a placeholder instead. The other instrumentations keep their upstream defaults.
77
+
78
+ To disable one instrumentation or change its options, pass it in `additional_instrumentations` or use the upstream environment variables, which take precedence: `OTEL_RUBY_INSTRUMENTATION_<NAME>_ENABLED=false` and `OTEL_RUBY_INSTRUMENTATION_<NAME>_CONFIG_OPTS`, where `<NAME>` is the instrumentation's class name after `OpenTelemetry::Instrumentation::`, upper-cased, with `::` replaced by `_`: `PG`, `NET_HTTP`, `ACTIVERECORD`.
79
+
80
+ TODO(jhartquist): `db_capture` init option. The `pg`, `mysql2`, and `trilogy` instrumentations can include the statement (`db_statement: :include`) and `pg` can report row counts (`db_response_returned_rows`, `db_response_affected_rows`), but none hands over results. Result capture needs Foam patches on the drivers, opt-in, through the same redaction and size caps as bodies. See Expanded data capture at the end of this document.
81
+
82
+ TODO(jhartquist): Gen AI providers beyond `anthropic`. There is no OpenTelemetry Ruby instrumentation for the `openai` or `ruby-openai` gems.
113
83
 
114
84
  ## Public API
115
85
 
116
- Every method lives on the `Foam` module. Every helper is a no-op
117
- before `init` and never raises.
86
+ Every method lives on the `Foam` module. Other than the ingest factories, none of them raise exceptions. `set_baggage`, the metric helpers, and `log` need a Foam export path to function properly, so they are no-ops before `init`; the trace context helpers and `record_exception` work on the current OpenTelemetry context whether or not `init` ran.
118
87
 
119
88
  ### `init`
120
89
 
121
- Sets up tracing, metrics, logs, automatic instrumentation, W3C
122
- `tracecontext` and `baggage` propagation, and OTLP export to Foam.
90
+ Sets up tracing, metrics, logs, automatic instrumentation, W3C `tracecontext` and `baggage` propagation, and OTLP export to Foam.
123
91
 
124
92
  Call this once. Use it when Foam should run OpenTelemetry for the process.
125
93
 
@@ -156,93 +124,42 @@ Foam.init(
156
124
  )
157
125
  ```
158
126
 
159
- `name` and `environment` are required. `token` is required only when Foam
160
- is enabled; store it as `FOAM_OTEL_TOKEN` and pass it in.
127
+ `name` and `environment` are required. `token` is required only when Foam is enabled; store it as `FOAM_OTEL_TOKEN` and pass it in.
161
128
 
162
129
  - `name` - the service name, sent as `service.name`.
163
- - `environment` - the deployment environment, sent as
164
- `deployment.environment.name`.
165
- - `enabled` - `false` turns Foam off; `init` returns without configuring
166
- OpenTelemetry.
167
- - `token` - the Foam ingest token, sent as a bearer token on every export.
168
- Required; a missing token is reported on stderr and leaves Foam
169
- uninitialized.
130
+ - `environment` - the deployment environment, sent as `deployment.environment.name`.
131
+ - `enabled` - `false` turns Foam off; `init` returns without configuring OpenTelemetry. With a token, it still reports the outcome (see below).
132
+ - `token` - the Foam ingest token, sent as a bearer token on every export. Required when Foam is enabled; a missing token is reported on stderr and leaves Foam uninitialized.
170
133
  - `version` - the service version, sent as `service.version` when given.
171
- - `sample_rate` - a number from `0.0` to `1.0`. Rarely if ever updated.
172
- Only change it for services sending telemetry in the petabytes range.
173
- `OTEL_TRACES_SAMPLER` is not consulted.
174
- - `additional_span_processors`, `additional_log_record_processors`,
175
- `additional_metric_readers` - the app's own OpenTelemetry components, added
176
- to Foam's providers after Foam's own exporters.
177
- - `additional_resource_attributes` - attributes merged into the resource
178
- of every signal. `service.name`, `service.version`, and
179
- `deployment.environment.name` come from the options above; a value for
180
- one of them here is reported on stderr and ignored.
181
- - `additional_instrumentations` - instrumentations to install next to the
182
- bundle. An entry is an instrumentation's registry name, its class name
183
- without the trailing `::Instrumentation`
184
- (`"OpenTelemetry::Instrumentation::Logger"`), or a `[name, config]` pair
185
- to install it with options
186
- (`["OpenTelemetry::Instrumentation::PG", {db_statement: :obfuscate}]`).
187
- Require the instrumentation's gem before `init`; an entry whose
188
- instrumentation is not loaded fails `init`. An entry naming a bundled
189
- instrumentation replaces Foam's configuration for it.
190
- - `ignored_outbound_hosts` - skips tracing of outbound HTTP requests to
191
- these hostnames. The endpoint host is always skipped. Use it for hosts
192
- whose traffic would drown the traces, such as a sidecar health check on
193
- `localhost` or another vendor's OTLP ingest host. Hosts are compared as
194
- written; `localhost` and `127.0.0.1` are different hosts. A request to a
195
- skipped host still carries a `traceparent` marked not sampled, so an
196
- OpenTelemetry service behind it records nothing for that request.
197
- - `disable_log_sending` - `true` stops shipping the app's `Logger` lines to
198
- Foam. `Foam.log` is unaffected. See Loggers.
199
- - `network_capture` - `:off`, `:basic`, or `:advanced`. See Network
200
- capture.
201
- - `redact` - keys to mask beyond the built-in list, as
202
- `{secrets: [...], pii: [...]}`. A value under a `secrets` key keeps its
203
- last four characters when it is 12 characters or longer; a value under
204
- a `pii` key is fully masked. See Redaction.
205
- - `before_send` - a callable that receives each span and log record before
206
- export and returns it, edited or not, to send it, or `nil` to drop it.
207
- See Before send.
208
-
209
- Every signal carries a resource with the service identity from the options
210
- above, `telemetry.distro.name` and `telemetry.distro.version` naming this
211
- gem, `host.name`, `host.arch`, `host.id`, `os.type`, and `os.version`, and
212
- the process and SDK attributes the OpenTelemetry SDK adds.
213
- `OTEL_RESOURCE_ATTRIBUTES` can add further attributes. It cannot override
214
- any of the attributes above, and `OTEL_SERVICE_NAME` cannot override
215
- `name`.
216
-
217
- `init` never raises. A failure or an option holding an invalid value is
218
- reported on stderr with a `[foam-otel]` prefix and leaves `state`
219
- uninitialized.
220
-
221
- `init` also reports its outcome to Foam: one log record with the message
222
- and the `state`, sent straight to the endpoint with the token. It is sent
223
- in the background, never blocks the app, and is dropped when it cannot be
224
- delivered. Nothing is sent without a token.
134
+ - `sample_rate` - the fraction of root traces kept, from `0.0` to `1.0`; child spans follow their parent. Leave it at `1.0` unless volume forces sampling. `OTEL_TRACES_SAMPLER` is not consulted.
135
+ - `additional_span_processors`, `additional_log_record_processors`, `additional_metric_readers` - the app's own OpenTelemetry components, added to Foam's providers after Foam's own exporters.
136
+ - `additional_resource_attributes` - attributes merged into the resource of every signal. `service.name`, `service.version`, and `deployment.environment.name` come from the options above; a value for one of them here is reported on stderr and ignored.
137
+ - `additional_instrumentations` - instrumentations to install next to the bundle. An entry is an instrumentation's registry name, which is its class name without the trailing `::Instrumentation` (`"OpenTelemetry::Instrumentation::Logger"`), or a `[name, config]` pair to install it with options (`["OpenTelemetry::Instrumentation::PG", {db_statement: :include}]`). Require the instrumentation's gem before `init`; an entry whose instrumentation is not loaded fails `init`. An entry naming a bundled instrumentation replaces Foam's configuration for it.
138
+ - `ignored_outbound_hosts` - skips tracing of outbound HTTP requests to these hostnames. The endpoint host is always skipped. Use it for hosts whose traffic would drown the traces, such as a sidecar health check on `localhost` or another vendor's OTLP ingest host. Hosts are compared as written; `localhost` and `127.0.0.1` are different hosts. A request to a skipped host still carries a `traceparent` marked not sampled, so an OpenTelemetry service behind it records nothing for that request.
139
+ - `disable_log_sending` - `true` stops shipping the app's `Logger` lines to Foam. `Foam.log` is unaffected. See Loggers.
140
+ - `network_capture` - `:off`, `:basic`, or `:advanced`. Use `:advanced` unless security and compliance rule it out. See Network capture.
141
+ - `redact` - keys to mask beyond the built-in list, as `{secrets: [...], pii: [...]}`. A value under a `secrets` key keeps its last four characters when it is 12 characters or longer; a value under a `pii` key is fully masked. See Redaction.
142
+ - `before_send` - a callable that receives each span and log record before export and returns it, edited or not, to send it, or `nil` to drop it. See Before send.
143
+
144
+ TODO(jhartquist): `propagation_targets`, an allowlist of the hosts that receive `traceparent`, `tracestate`, and `baggage`. Spans stay on for every other host; only the headers are withheld. Today `ignored_outbound_hosts` is the only lever and it drops the spans too. The client patches see the host and can strip the headers after the instrumentation injects them. The endpoint host stays fully ignored.
145
+
146
+ Every signal carries a resource with the service identity from the options above, `telemetry.distro.name` and `telemetry.distro.version` naming this gem, `host.name`, `host.arch`, `host.id` when it can be read, `os.type`, and `os.version`, and the process and SDK attributes the OpenTelemetry SDK adds. `OTEL_RESOURCE_ATTRIBUTES` can add further attributes. It cannot override any of the attributes above, and `OTEL_SERVICE_NAME` cannot override `name`.
147
+
148
+ `init` never raises. A failure or an option holding an invalid value is reported on stderr with a `[foam-otel]` prefix and leaves `state` uninitialized.
149
+
150
+ `init` also reports its outcome to Foam: one log record with the message and the `state`, sent straight to the endpoint with the token. It is sent in the background, never blocks the app, and is dropped when it cannot be delivered. Nothing is sent without a token.
225
151
 
226
152
  ### `set_endpoint(url)`
227
153
 
228
- For tests and local development only. Sets the OTLP/HTTP base URL,
229
- without a signal path, that every export and report goes to, such as a
230
- local collector. Production apps do not call it: the default is Foam's
231
- ingest endpoint, `https://otel.api.foam.ai`.
154
+ For tests and local development only. Sets the OTLP/HTTP base URL, without a signal path, that every export and report goes to, such as a local collector. Production apps do not call it: the default is Foam's ingest endpoint, `https://otel.api.foam.ai`.
232
155
 
233
- Call it before `init` or before creating an ingest component. Exporters
234
- keep the endpoint they were built with: a call after `init` is reported on
235
- stderr, and only later reports follow the new value.
236
- `OTEL_EXPORTER_OTLP_ENDPOINT` and the per-signal endpoint variables are not
237
- consulted.
156
+ Call it before `init` or before creating an ingest component. Exporters keep the endpoint they were built with, so a later call changes only later reports and ingest components; after `init` it is also reported on stderr. `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS`, and their per-signal forms are not consulted. The upstream exporters still read the timeout, compression, and certificate variables.
238
157
 
239
158
  ### `create_foam_ingest_span_processor(name, environment, token, redact: nil, before_send: nil)`
240
159
 
241
- Returns a span processor that exports traces to Foam without taking over
242
- the global tracer provider.
160
+ Returns a span processor that exports traces to Foam without taking over the global tracer provider.
243
161
 
244
- Use it when another OpenTelemetry SDK already owns traces and Foam is
245
- only an extra export destination. Attach it to that provider.
162
+ Use it when another OpenTelemetry SDK already owns traces and Foam is only an extra export destination. Attach it to that provider.
246
163
 
247
164
  ```ruby
248
165
  processor = Foam.create_foam_ingest_span_processor(
@@ -255,9 +172,7 @@ tracer_provider.add_span_processor(processor)
255
172
 
256
173
  ### `create_foam_ingest_log_record_processor(name, environment, token, redact: nil, before_send: nil)`
257
174
 
258
- Returns a log record processor that exports logs to Foam without taking
259
- over the global logger provider. It also gives `log` a provider of its
260
- own, so `log` delivers without `init`.
175
+ Returns a log record processor that exports logs to Foam without taking over the global logger provider. It also gives `log` a provider of its own, so `log` delivers without `init`.
261
176
 
262
177
  ```ruby
263
178
  processor = Foam.create_foam_ingest_log_record_processor(
@@ -270,8 +185,7 @@ logger_provider.add_log_record_processor(processor)
270
185
 
271
186
  ### `create_foam_ingest_metric_reader(name, environment, token, redact: nil)`
272
187
 
273
- Returns a metric reader that exports metrics to Foam without taking over
274
- the global meter provider.
188
+ Returns a metric reader that exports metrics to Foam without taking over the global meter provider.
275
189
 
276
190
  ```ruby
277
191
  reader = Foam.create_foam_ingest_metric_reader(
@@ -282,34 +196,19 @@ reader = Foam.create_foam_ingest_metric_reader(
282
196
  meter_provider.add_metric_reader(reader)
283
197
  ```
284
198
 
285
- All three export to the endpoint set by `set_endpoint` and take the same
286
- `redact` option as `init`. The span processor and the log record processor
287
- also take the same `before_send` option; the metric reader does not. Each
288
- one records its signal as `ingest` in `state` and reports the attachment
289
- to Foam.
199
+ All three export to the endpoint set by `set_endpoint` and take the same `redact` option as `init`. The span processor and the log record processor also take the same `before_send` option; the metric reader does not. Each one records its signal as `ingest` in `state` and reports the attachment to Foam.
290
200
 
291
- Foam identifies the service by the `name` and `environment` passed in: on
292
- the copy sent to Foam they overwrite the provider's `service.name` and
293
- `deployment.environment.name`, and `foam.ingest.host` names the host of
294
- the endpoint the copy goes to. The provider's own telemetry is left
295
- unchanged. Pass the same values to all three.
201
+ Foam identifies the service by the `name` and `environment` passed in: on the copy sent to Foam they overwrite the provider's `service.name` and `deployment.environment.name`, and `foam.ingest.host` names the host of the endpoint the copy goes to. The provider's own telemetry is left unchanged. Pass the same values to all three.
296
202
 
297
- Unlike every other public method, these raise `ArgumentError` when `name`,
298
- `environment`, or `token` is blank or `redact` or `before_send` is invalid.
203
+ Unlike every other public method, these are not guarded: they raise `ArgumentError` when `name`, `environment`, or `token` is blank or `redact` or `before_send` is invalid, and let any other failure through. Returning nothing instead would fail later, inside the app's provider, with less to go on.
299
204
 
300
- Do not combine `init` and an ingest component for the same signal. The
301
- ingest components do not install instrumentations; register the ones the
302
- app needs with the OpenTelemetry SDK directly.
205
+ Do not combine `init` and an ingest component for the same signal. The ingest components do not install instrumentations; register the ones the app needs with the OpenTelemetry SDK directly.
303
206
 
304
207
  ### `inject_trace_context(carrier)`
305
208
 
306
- Writes the W3C `traceparent`, `tracestate`, and `baggage` headers for the
307
- current span into `carrier`, a hash of string keys.
209
+ Writes the W3C `traceparent`, `tracestate`, and `baggage` headers for the current span into `carrier`, a hash of string keys.
308
210
 
309
- Use it when the app sends a message itself (a Kafka record, a queue payload,
310
- a custom socket). The HTTP instrumentations already inject these headers;
311
- do not call it on ordinary HTTP requests. Writes nothing when no span is
312
- active.
211
+ Use it when the app sends a message itself (a Kafka record, a queue payload, a custom socket). The HTTP instrumentations already inject these headers; do not call it on ordinary HTTP requests. Without an active span it writes only `baggage`, and only when baggage is set.
313
212
 
314
213
  ```ruby
315
214
  headers = {}
@@ -317,11 +216,11 @@ Foam.inject_trace_context(headers)
317
216
  producer.publish(topic, payload, headers: headers)
318
217
  ```
319
218
 
219
+ TODO(jhartquist): a carrier that already holds a `traceparent` has it overwritten. Decide whether to keep the existing one, replace it, or link the two.
220
+
320
221
  ### `extract_trace_context(carrier)`
321
222
 
322
- Reads those headers from `carrier` and returns an OpenTelemetry context.
323
- Run the receiving work inside it so its spans continue the sender's trace.
324
- Returns the current context when the carrier has no trace headers.
223
+ Reads those headers from `carrier` and returns an OpenTelemetry context. Run the receiving work inside it so its spans continue the sender's trace. Returns the current context when the carrier has no trace headers.
325
224
 
326
225
  ```ruby
327
226
  context = Foam.extract_trace_context(message.headers)
@@ -330,18 +229,11 @@ OpenTelemetry::Context.with_current(context) do
330
229
  end
331
230
  ```
332
231
 
333
- Foam's helpers always speak W3C, whichever propagator the SDK configured
334
- globally (see `OTEL_PROPAGATORS`).
232
+ Foam's helpers always speak W3C, whichever propagator the SDK configured globally (see `OTEL_PROPAGATORS`).
335
233
 
336
234
  ### `set_baggage(key, value)`
337
235
 
338
- Adds a key-value pair to the current context's baggage. Baggage travels
339
- with the trace context to every downstream service, where `baggage(key)`
340
- reads it; it is not written onto spans. The value lasts for the rest of
341
- the current scope, for example the rest of the request when called from a
342
- Rails controller, and is dropped when that scope ends. Outside any span or
343
- context scope the call is ignored and warned about once, so a value can
344
- never outlive the work it belongs to. No-op before `init`.
236
+ Adds a key-value pair to the current context's baggage. Baggage travels with the trace context to every downstream service, where `baggage(key)` reads it; it is not written onto spans. The value lasts for the rest of the current scope, for example the rest of the request when called from a Rails controller, and is dropped when that scope ends. Outside any span or context scope the call is ignored and warned about once, so a value can never outlive the work it belongs to. No-op before `init`.
345
237
 
346
238
  ```ruby
347
239
  Foam.set_baggage("tenant", current_tenant.id)
@@ -349,8 +241,7 @@ Foam.set_baggage("tenant", current_tenant.id)
349
241
 
350
242
  ### `baggage(key)`
351
243
 
352
- Returns the baggage value for `key`, whether set in this process or
353
- received from an upstream service, or `nil`.
244
+ Returns the baggage value for `key`, whether set in this process or received from an upstream service, or `nil`.
354
245
 
355
246
  ### Metric helpers
356
247
 
@@ -361,31 +252,22 @@ Foam.add_up_down_counter("queue.depth", -1)
361
252
  Foam.set_metric("cache.size", 1024, unit: "By", description: "Entries in the cache")
362
253
  ```
363
254
 
364
- - `increment_counter(name, value = 1, ...)` adds to a counter that only
365
- goes up.
255
+ - `increment_counter(name, value = 1, ...)` adds to a counter that only goes up.
366
256
  - `record_histogram(name, value, ...)` records one value in a histogram.
367
- - `add_up_down_counter(name, value, ...)` adds to a counter that can go
368
- down; pass a negative value to decrement.
257
+ - `add_up_down_counter(name, value, ...)` adds to a counter that can go down; pass a negative value to decrement.
369
258
  - `set_metric(name, value, ...)` sets a gauge to its latest value.
370
259
 
371
- Every helper takes `attributes: {}`, `unit: nil`, and `description: nil`.
372
- The instrument is created on the first call for a name, and `unit` and
373
- `description` apply then; later calls reuse it. Values are exported on
374
- Foam's metrics pipeline under the `foam-otel` scope. Calls before `init`,
375
- or when Foam is disabled, are dropped.
260
+ Every helper takes `attributes: {}`, `unit: nil`, and `description: nil`. The instrument is created on the first call for a name, and `unit` and `description` apply then; later calls reuse it. Values are exported on Foam's metrics pipeline under the `foam-otel` scope. Calls before `init`, when Foam is disabled, or in a setup that only attaches an ingest metric reader are dropped.
261
+
262
+ TODO(jhartquist): observable (pull) instruments. The metrics SDK has observable counters, gauges, and up-down counters; the helpers cover the four synchronous kinds only. v1 used observables for runtime metrics (GC, heap, threads, RSS), which this version does not send.
376
263
 
377
264
  ### `log(body, severity: :info, attributes: {})`
378
265
 
379
- Sends a log record to Foam on Foam's own export path. The record goes only
380
- to Foam: nothing is written to the app's log output, and nothing is emitted
381
- through a logger provider Foam does not own. A record emitted inside a
382
- request carries the trace and span ids of the current span.
266
+ Sends a log record to Foam on Foam's own export path. The record goes only to Foam: nothing is written to the app's log output, and nothing is emitted through a logger provider Foam does not own. A record emitted inside a request carries the trace and span ids of the current span.
383
267
 
384
- Use it to send a log directly, for example when the app's logger is not
385
- captured automatically (see Loggers).
268
+ Use it to send a log directly, for example when the app's logger is not captured automatically (see Loggers).
386
269
 
387
- `severity` is one of `:trace`, `:debug`, `:info`, `:warn`, `:error`,
388
- `:fatal`. Calls before `init`, or when Foam is disabled, are dropped.
270
+ `severity` is one of `:trace`, `:debug`, `:info`, `:warn`, `:error`, `:fatal`. Calls are no-ops when Foam is disabled, or before `init` or the ingest log record processor gives `log` a provider.
389
271
 
390
272
  ```ruby
391
273
  Foam.log("checkout failed")
@@ -394,9 +276,7 @@ Foam.log("checkout failed", severity: :error, attributes: {"order.id" => order.i
394
276
 
395
277
  ### `record_exception(exception, attributes: nil)`
396
278
 
397
- Records an exception on the active span and marks the span as errored,
398
- for exceptions the app rescues and handles itself. Unhandled exceptions
399
- are recorded by the instrumentation already.
279
+ Records an exception on the active span and marks the span as errored, for exceptions the app rescues and handles itself. Unhandled exceptions are recorded by the instrumentation already.
400
280
 
401
281
  ```ruby
402
282
  begin
@@ -407,38 +287,29 @@ rescue PaymentError => e
407
287
  end
408
288
  ```
409
289
 
410
- The span gets an `exception` event with the type, message, and stack
411
- trace, plus any `attributes`, and its status becomes error with the
412
- exception's message. The active span is used whichever SDK started it.
413
- Without an active span nothing is recorded.
290
+ The span gets an `exception` event with the type, message, and stack trace, plus any `attributes`, and its status becomes error with the exception's message. The active span is used whichever SDK started it. Without an active span nothing is recorded.
414
291
 
415
292
  ### `flush(timeout: 30)`
416
293
 
417
- Exports everything Foam's providers still hold. Call it before a point
418
- where the process may be killed without a normal exit, for example at the
419
- end of a job on a runner that stops the process.
294
+ Exports everything Foam's providers still hold. Call it before a point where the process may be killed without a normal exit, for example at the end of a job on a runner that stops the process.
420
295
 
421
296
  ```ruby
422
297
  Foam.flush(timeout: 5)
423
298
  ```
424
299
 
425
- `timeout` is in seconds and bounds the whole call. A provider that runs
426
- out of time is reported on stderr.
300
+ `timeout` is in seconds and bounds the whole call. A provider that runs out of time is reported on stderr.
427
301
 
428
302
  ### `shutdown(timeout: 30)`
429
303
 
430
- Flushes and shuts down Foam's providers, including the one behind `log`
431
- when an ingest component created it. Both `init` and the ingest log
432
- factory register it with `at_exit`, so most apps never call it. Call it
433
- yourself before a process is killed without a normal exit.
304
+ Flushes and shuts down Foam's providers, including the one behind `log` when an ingest component created it. Both `init` and the ingest log factory register it with `at_exit`, so most apps never call it. Call it yourself before a process is killed without a normal exit.
305
+
306
+ `timeout` is in seconds and bounds the whole call. A provider that runs out of time is reported on stderr.
434
307
 
435
- `timeout` is in seconds and bounds the whole call. A provider that runs
436
- out of time is reported on stderr.
308
+ `at_exit` covers a normal exit, an unhandled exception, and a signal the process handles by exiting. `exit!`, `KILL`, and a crash lose the last batch, and so does a batch that outlasts the timeout. An exception outside any span is invisible unless the app logs it.
437
309
 
438
310
  ### `state`
439
311
 
440
- Returns whether Foam initialized, which instrumentations registered, which
441
- signals have an export path, and the identity `init` was given.
312
+ Returns whether Foam initialized, which instrumentations registered, which signals have an export path, and the identity `init` was given.
442
313
 
443
314
  Use it in health checks, tests, or diagnostics to confirm Foam is running.
444
315
 
@@ -454,128 +325,100 @@ Foam.state
454
325
  # baggage: :global,
455
326
  # profile: :none
456
327
  # },
457
- # params: {name: "checkout", environment: "production"}
328
+ # params: {name: "checkout-api", environment: "production"}
458
329
  # }
459
330
  ```
460
331
 
461
- `instrumentations` lists the instrumentations that installed, by gem name
462
- without the `opentelemetry-instrumentation-` prefix, with the version of
463
- the library each one instruments (`net_http` reports the Ruby version;
464
- `aws_lambda` has no version). An instrumentation whose library is absent
465
- or unsupported is left out.
332
+ `instrumentations` lists the instrumentations that installed, by gem name without the `opentelemetry-instrumentation-` prefix, with the version of the library each one instruments (`net_http` reports the Ruby version; `aws_lambda` has no version). An instrumentation whose library is absent or unsupported is left out.
466
333
 
467
- A library loaded after `init` is not instrumented and stays out of the
468
- list; a warning is written to stderr the first time a `state` call finds
469
- one. See Instrumentation for the bundle.
334
+ A library loaded after `init` is not instrumented and stays out of the list; a warning is written to stderr the first time a `state` call finds one. See Instrumentation for the bundle.
470
335
 
471
- `params` holds the `name` and `environment` passed to `init`, never the
472
- token, and is empty before `init`.
336
+ `params` holds the `name` and `environment` passed to `init`, never the token, and is empty before `init`.
473
337
 
474
- Each `signals` value names the source of the Foam export path for that
475
- signal:
338
+ Each `signals` value names the source of the Foam export path for that signal:
476
339
 
477
340
  - `:global` - `init` registered Foam's provider as the global provider.
478
- - `:ingest` - a `create_foam_ingest_*` object was built for another SDK's
479
- pipeline.
480
- - `:local` - logs only: another SDK owns the global provider and Foam keeps
481
- its own so `log` still delivers.
341
+ - `:ingest` - traces, metrics, and logs only: a `create_foam_ingest_*` object was built for another SDK's pipeline.
342
+ - `:local` - logs only: another SDK owns the global provider and Foam keeps its own so `log` still delivers.
482
343
  - `:none` - no Foam export path.
483
344
 
484
- `:global` is checked against the live OpenTelemetry global at each call.
485
- When another SDK takes a slot after `init`, that signal reports `:none`
486
- (`:local` for logs) and a warning is written to stderr once. Only the slot
487
- is affected: the Foam helpers keep their own references and keep working.
488
- `profile` is not supported and always reports `:none`.
345
+ `:global` is checked against the live OpenTelemetry global at each call. When another SDK takes a slot after `init`, that signal reports `:none` (`:local` for logs) and a warning is written to stderr once. Only the slot is affected: the Foam helpers keep their own references and keep working. `baggage` is `:global` or `:none`. `profile` is not supported and always reports `:none`.
489
346
 
490
347
  ## Custom spans and other OpenTelemetry APIs
491
348
 
492
- TODO(jhartquist)
349
+ TODO(jhartquist): custom spans and the OpenTelemetry API: getting a tracer, `in_span`, attributes, events, and how Foam's helpers relate to them.
493
350
 
494
351
  ## Network capture
495
352
 
496
- `network_capture` defaults to `:basic` and controls extra HTTP detail on
497
- server and client spans.
353
+ `network_capture` defaults to `:basic` and controls extra HTTP detail on server and client spans.
498
354
 
499
- - `:off` keeps the standard OpenTelemetry HTTP telemetry, with no extra
500
- capture.
501
- - `:basic` adds the `content-type`, `content-length`, and
502
- `content-encoding` headers of the request and the response as span
503
- attributes. No other header attribute is added.
355
+ - `:off` keeps the standard OpenTelemetry HTTP telemetry, with no extra capture.
356
+ - `:basic` adds the `content-type`, `content-length`, and `content-encoding` headers of the request and the response as `http.request.header.<name>` and `http.response.header.<name>` span attributes. No other header attribute is added.
504
357
  - `:advanced` adds the request and response bodies as well.
505
358
 
506
- TODO(jhartquist): `:basic` headers on client spans.
359
+ There is no option to record other headers.
360
+
361
+ ### Header capture
507
362
 
508
- Header capture is applied through the Rack instrumentation. An
509
- `additional_instrumentations` entry naming it replaces this
510
- configuration.
363
+ Server spans get the headers from `Foam::Rack::Middleware`, placed after the OpenTelemetry Rack middleware. A Rails app is not covered yet.
364
+
365
+ Client spans get the headers from Foam's hooks on `Net::HTTP`, Excon, HTTPClient, and Faraday, applied unless `network_capture` is `:off`. The `Net::HTTP` hook is always installed; the others install only when their gem is loaded before `init`, and Faraday's covers connections built after `init`. Faraday is covered on the Faraday span whatever the adapter. `http`, `httpx`, `ethon`, and `restclient` are not covered.
366
+
367
+ Faraday over the `httpclient` adapter sends each request with the trace marked not sampled, so a Foam server on the other side records no span for it. The issue is in the upstream HTTPClient instrumentation, which ignores the untraced context Faraday runs its adapter in; Net::HTTP and Excon honor it.
368
+
369
+ TODO(jhartquist): cover `http`, `httpx`, `ethon`, and `restclient`.
370
+
371
+ TODO(jhartquist): the HTTPClient trace break above. The fix is `return super if OpenTelemetry::Common::Utilities.untraced?` at the top of the instrumentation's `do_get_block`, upstream or redefined at init until a release carries it.
511
372
 
512
373
  ### Body capture
513
374
 
514
- In `:advanced` mode each captured body arrives as `foam.http.body.chunk`
515
- log records correlated to the span, and the span carries the body's size
516
- and content.
375
+ In `:advanced` mode each captured body arrives as `foam.http.body.chunk` log records correlated to the span, and the span carries the body's size and content and whether the capture was complete.
517
376
 
518
- - Bodies with a textual content type are captured. gzip and deflate are
519
- decoded. Other encodings and binary types yield one record with the size
520
- only.
521
- - At most 1 MiB of a body is kept, in chunks of at most 64 KiB. The rest
522
- counts toward the size.
523
- - Bodies are redacted by content type with the same keys as span
524
- attributes.
377
+ - Bodies with a textual content type, or one declaring a charset, are captured. gzip and deflate are decoded. Other encodings and binary types yield one record with the size only; an empty body yields none.
378
+ - At most 1 MiB of a body is kept, sent as records of at most 64 KiB each. The rest counts toward the size.
379
+ - Bodies are parsed by content type and redacted with the same keys as span attributes.
525
380
 
526
381
  ### Rack bodies
527
382
 
528
- Server bodies need `Foam::Rack::Middleware` directly after the
529
- OpenTelemetry Rack middleware, as shown under "Plain Ruby and Rack". A
530
- Rails app is not covered yet.
383
+ Server bodies need `Foam::Rack::Middleware` after the OpenTelemetry Rack middleware, as shown under "Plain Ruby and Rack". A Rails app is not covered yet.
531
384
 
532
- - The request body is captured whether or not the app reads it when the
533
- server buffers request bodies, as Puma does. Otherwise what the app reads
534
- is captured.
535
- - A streamed response is captured chunk by chunk as the server sends it.
536
- - A streaming body (`call`), a file sent by path (`to_path`), and a hijacked
537
- connection are not captured.
385
+ - The request body is captured whether or not the app reads it when the input is rewindable, as it is under Puma, which buffers request bodies. Otherwise what the app reads is captured.
386
+ - A streamed response is observed as the server sends it, without buffering or delaying it. The records are emitted when the body closes; a stream idle for over 60 seconds is closed as incomplete and the rest is dropped.
387
+ - A streaming body (`call`), a file sent by path (`to_path`), and a hijacked connection are not captured.
538
388
 
539
389
  ### Client bodies
540
390
 
541
- Client bodies are captured on the client span of `Net::HTTP`, Faraday,
542
- Excon, and HTTPClient. Each client is patched in `:advanced` mode only, and
543
- only when its OpenTelemetry instrumentation installed. Other clients are
544
- not captured.
391
+ Client bodies are captured in `:advanced` by the same hooks that set the headers.
392
+
393
+ - `Net::HTTP`: a request sent through `body_stream` and a response read in a block or into an IO are not captured.
394
+ - Faraday: bodies are captured on the Faraday span through Foam's Faraday middleware, whatever the adapter. A request whose body is an IO and a response streamed with `on_data` are not captured.
395
+ - Excon: a request sent with `request_block` and a response received with `response_block` are not captured.
396
+ - HTTPClient: a request whose body is an IO or multipart parts is not captured. A response read in a block is captured.
397
+ - RestClient, `http`, `httpx`, and `ethon`: no bodies, since they get no header capture either.
545
398
 
546
- - `Net::HTTP`: a request sent through `body_stream` and a response read in
547
- a block or into an IO are not captured.
548
- - Faraday: bodies are captured on the Faraday span. A request sent from an
549
- IO and a response streamed with `on_data` are not captured.
550
- - Excon: a request sent with `request_block` and a response received with
551
- `response_block` are not captured.
552
- - HTTPClient: a request sent from an IO or as multipart parts is not
553
- captured. A response read in a block is captured.
399
+ TODO(jhartquist): capture streamed bodies: a request sent from an IO and a response the client streams to the app.
554
400
 
555
401
  ## Loggers
556
402
 
557
- Every line written through the standard library `Logger` is sent to Foam
558
- as a log record carrying the current trace and span IDs. The record's body
559
- is the formatted line and its severity follows the `Logger` level. The
560
- app's log output is unchanged. A `Logger` created before `init` is
561
- covered. `Rails.logger` lines are sent once each. `puts` and direct
562
- writes to `$stdout` are not captured.
403
+ Foam installs `opentelemetry-instrumentation-logger`, which hooks `Logger#format_message`, so every logger built on `Logger` is covered, including one created before `init`. Each line becomes one log record: the body is the formatted line and the severity follows the `Logger` level, except that `unknown` arrives with no severity. The app's own log output is unchanged; the trace and span IDs are on the record sent to Foam, not written into the app's lines. The record carries the resource attributes but none of its own: a JSON-formatted line arrives as one string body, with its fields inside the text. Use `Foam.log` to send a record with attributes.
563
404
 
564
- If the app already sends its logs through its own OpenTelemetry pipeline,
565
- set `disable_log_sending: true` so records do not arrive twice. If another
566
- SDK owns logs, set it and attach `create_foam_ingest_log_record_processor`
567
- to that SDK's provider. `Foam.log` delivers either way.
405
+ Covered:
568
406
 
569
- TODO(jhartquist): working alongside other popular Ruby loggers.
407
+ - `Logger`: every line except `Logger#<<`, which writes to the device directly.
408
+ - Rails 7.1 and later: `Rails.logger`, `ActiveSupport::Logger`, `TaggedLogging`, and `BroadcastLogger`. A broadcast sends one record per line, tags included in the body, provided ActiveSupport is loaded before `init`; otherwise every sink sends its own record.
409
+ - `Sidekiq::Logger`, MonoLogger, LogStashLogger, Ougai, and fluent-logger build on `Logger` and should be covered; Lograge formats `Rails.logger` lines and is covered through it. LogStashLogger's `MultiLogger` should send one record per logger it wraps. None of these is tested here.
410
+
411
+ Not covered, since they do not build on `Logger`: Semantic Logger, `logging`, log4r, yell, and Puma's own server lines. Use `Foam.log` for a record from these. Semantic Logger also ships an `:open_telemetry` appender. `puts` and direct writes to `$stdout` or `$stderr` are never captured, nor is a `Logger` whose device is `nil` or `File::NULL`.
412
+
413
+ If another SDK owns logs, set `disable_log_sending: true` so records do not arrive twice, and attach `create_foam_ingest_log_record_processor` to that SDK's provider. `Foam.log` delivers either way.
414
+
415
+ Secrets in a log line are masked before export. See Redaction.
570
416
 
571
417
  ## Pre-forking servers and threads
572
418
 
573
- TODO(jhartquist)
419
+ TODO(jhartquist): pre-forking servers (Puma in cluster mode, Unicorn, Pitchfork, Resque): whether to call `init` before or after the fork, and what the SDK's batch processors and the metric reader do in the child. Foam registers no fork hook today.
574
420
 
575
- The current span and baggage are stored per fiber. A `Thread.new` or
576
- `Fiber.new` starts with none, so spans started inside it begin a new trace.
577
- To continue the trace, capture the context first and make it current
578
- inside the thread:
421
+ The current span and baggage are stored per fiber. A `Thread.new` or `Fiber.new` starts with none, so spans started inside it begin a new trace. To continue the trace, capture the context first and make it current inside the thread:
579
422
 
580
423
  ```ruby
581
424
  context = OpenTelemetry::Context.current
@@ -586,35 +429,17 @@ end
586
429
 
587
430
  ## Redaction
588
431
 
589
- Foam masks the values of sensitive keys in everything it exports: span,
590
- span event, and span link attributes; log bodies and attributes; metric
591
- data point attributes; and resource attributes. A built-in list of
592
- credential and personal-data keys always applies, matched by exact name
593
- or by a sensitive segment of the key (`legacy_api_key_2`, `stripeToken`).
594
- Keys match after normalization: case, `-`, `.`, and camelCase boundaries
595
- are folded, so `apiKey`, `api-key`, and `API_KEY` are one key. Header
596
- attributes match on the header name. The sensitive pairs of a query
597
- string are masked in `url.query` and in any string value holding one.
598
- Captured HTTP bodies are masked by content type with the same keys, with
599
- their framing kept; a body the masking fails on is replaced whole.
600
-
601
- The `redact` option adds the app's own keys, matched exactly after the
602
- same normalization. A value under a built-in or `pii` key becomes
603
- `[REDACTED]`. A value under a `secrets` key becomes `********`, followed
604
- by its last four characters when it is 12 characters or longer.
605
-
606
- Masking changes values only: keys stay present, and span names, event
607
- names, and severity are untouched. It is applied after `before_send`, to
608
- the copy sent to Foam, through `init` and through the ingest components
609
- alike. The app's own span and log objects, and the copies handed to other
610
- processors and exporters, are unchanged.
432
+ Foam masks the values of sensitive keys in everything it exports: span, span event, and span link attributes; log bodies and attributes; metric data point attributes; and resource attributes. A built-in list of credential and personal-data keys always applies, matched by exact name or by a sensitive segment of the key (`legacy_api_key_2`, `stripeToken`). Keys match after normalization: case, `-`, `.`, and camelCase boundaries are folded, so `apiKey`, `api-key`, and `API_KEY` are one key. Header attributes match on the header name. SQL statements arrive from the database instrumentations with every literal replaced with `?` (see Instrumentation) and are redacted like any other string. Captured HTTP bodies are masked by content type with the same keys, with their framing kept. When masking a body fails, the whole body is replaced with `********`.
433
+
434
+ Every other string is scanned as text, a log body included. A string that is a whole JSON document is masked by key at every depth, so a list or object under a sensitive key becomes one mask. Any other string has the value after each sensitive key masked, whether the key is quoted as JSON writes it or bare before `=`, `:`, or `=>`, and whether it sits in a query string, a header line, or prose. The value ends at the next delimiter, so the rest of the line is kept, a quoted URL's closing quote included. Such a string is scanned up to 1 MiB; the rest collapses into one mask. `url.query` is masked pair by pair, and names such as `code` and `sig` count as sensitive only inside a query string. Masking is value-only: the key and the surrounding text stay.
435
+
436
+ The `redact` option adds the app's own keys, matched exactly after the same normalization. A value under a built-in or `pii` key becomes `[REDACTED]`. A value under a `secrets` key becomes `********`, followed by its last four characters when it is 12 characters or longer. That tail is kept only where the value is read whole under its key: an attribute, a hash or array, or a whole JSON document. A value found by scanning text or a `url.query` pair becomes `[REDACTED]` whatever its key.
437
+
438
+ Masking changes values only: keys stay present, and span names, event names, and severity are untouched. It is applied after `before_send`, to the copy sent to Foam, through `init` and through the ingest components alike. The app's own span and log objects, and the copies handed to other processors and exporters, are unchanged.
611
439
 
612
440
  ## Before send
613
441
 
614
- `before_send` is the app's last look at each span and log record before
615
- it is sent to Foam. The hook receives an event and returns it, edited or
616
- not, to send it, or `nil` to drop it. Metrics and Foam's own reports never
617
- pass through it.
442
+ `before_send` is the app's last look at each span and log record before it is sent to Foam. The hook receives an event and returns it, edited or not, to send it, or `nil` to drop it. Metrics and Foam's own reports never pass through it.
618
443
 
619
444
  ```ruby
620
445
  Foam.init(
@@ -665,31 +490,51 @@ For a log record:
665
490
  }
666
491
  ```
667
492
 
668
- `name`, `attributes`, `events`, and `links` of a span and `body`,
669
- `severity_text`, `severity_number`, and `attributes` of a log record are
670
- sent as returned. The read-only fields hold what the SDK recorded, as the
671
- SDK holds it; edits to them are ignored. Timestamps are Integer
672
- nanoseconds since the epoch. An event added without a
673
- `timestamp` gets the span's start time. A link added needs a
674
- `span_context`.
675
-
676
- The hook receives a copy: edits reach Foam only through the return value,
677
- and the app's own span and log objects are unchanged. Redaction runs after
678
- the hook, so the hook sees values before masking and what it returns is
679
- masked before export. A hook that raises, or returns anything other than
680
- an event of the same type, leaves the event as it was, without a
681
- diagnostic. An event holding a value that cannot be copied is sent as it
682
- was without calling the hook. A span or log record emitted inside the
683
- hook passes through the hook itself.
493
+ `name`, `attributes`, `events`, and `links` of a span and `body`, `severity_text`, `severity_number`, and `attributes` of a log record are sent as returned. The read-only fields hold what the SDK recorded, as the SDK holds it; edits to them are ignored. Timestamps are Integer nanoseconds since the epoch. An event added without a `timestamp` gets the span's start time. A link added needs a `span_context`.
494
+
495
+ The hook receives a copy: edits are honored only through the return value, and the app's own span and log objects are unchanged. Redaction runs after the hook, so the hook sees values before masking and what it returns is masked before export. A hook that raises, or returns anything other than an event of the same type with well-formed fields, leaves the event as it was, without a diagnostic. An event holding a value that cannot be copied is sent as it was without calling the hook. A span or log record emitted inside the hook passes through the hook itself, so a hook that emits on every call never stops.
684
496
 
685
497
  ## OpenTelemetry configuration and compliance
686
498
 
687
- TODO(jhartquist)
499
+ TODO(jhartquist): which `OTEL_*` variables `init` honors, which it overrides, and the Ruby entries in the specification compliance matrix.
688
500
 
689
501
  ## OpenTelemetry Profiling
690
502
 
691
503
  Not supported. `state` reports `profile: :none`.
692
504
 
505
+ TODO(jhartquist): the OpenTelemetry Ruby SDK has no profiles signal. Track upstream progress:
506
+
507
+ - [Profiling SIG language SDK support tracker](https://github.com/open-telemetry/sig-profiling/issues/106)
508
+ - [OpenTelemetry eBPF profiler](https://github.com/open-telemetry/opentelemetry-ebpf-profiler), which runs outside the process and covers any language
509
+
510
+ ## TODO(jhartquist): Expanded data capture (DB results, gRPC, messaging, AWS)
511
+
512
+ Extension points Foam is not using yet, ordered by how much new data they unlock. Every payload would go through the same redaction and size caps as HTTP bodies.
513
+
514
+ ### Database results
515
+
516
+ No Ruby driver instrumentation returns results. `pg`, `mysql2`, and `trilogy` can include the statement and `pg` can report row counts; `redis` and `mongo` can include the command. Result capture means Foam patches on the drivers (`PG::Connection#exec` and its variants, `Mysql2::Client#query`, `Trilogy#query`), gated by `db_capture` and opt-in: results are the most PII-dense payload in the system.
517
+
518
+ ### gRPC
519
+
520
+ The `grpc` and `gruf` instrumentations give spans and allowlisted metadata, no payloads. The seam is gRPC's own interceptors: `GRPC::ClientInterceptor` and `GRPC::ServerInterceptor` would see the request and response messages as Ruby objects, with no wire framing to undo. The app registers interceptors per stub and per server, so installing one from `init` means patching stub and server construction. http2 outside gRPC is `httpx`, covered by the client TODO under Network capture.
521
+
522
+ ### Messaging and AWS
523
+
524
+ The `bunny`, `rdkafka`, `ruby_kafka`, `racecar`, `sidekiq`, `resque`, `que`, `delayed_job`, and `active_job` instrumentations have no payload hooks. Message capture means Foam patches on publish and consume, with Sidekiq's client and server middleware as the one clean seam. The `aws_sdk` instrumentation has no request or response hooks either; an `aws-sdk-core` plugin would see every call.
525
+
526
+ ## TODO(jhartquist): Resource detectors, propagators, samplers
527
+
528
+ OpenTelemetry packages outside the instrumentation bundle that Foam does not wire yet.
529
+
530
+ - Resource detectors. Foam's resource carries the service identity, the distro, host, and OS attributes, and the process and SDK attributes the OpenTelemetry SDK adds; `OTEL_RESOURCE_ATTRIBUTES` adds to it. The contrib detectors, `opentelemetry-resource-detector-aws`, `-azure`, `-container`, and `-google_cloud_platform`, are not run. The cloud ones probe metadata endpoints, so they belong off the `init` critical path.
531
+ - Propagators. `init` keeps the SDK's default propagators, W3C `tracecontext` and `baggage`. The SDK honors `OTEL_PROPAGATORS` for `b3`, `b3multi`, `jaeger`, `xray`, and `ottrace` when the propagator gem is present, but the gems are not dependencies of `foam-otel`, and `inject_trace_context` and `extract_trace_context` speak W3C whatever is configured.
532
+ - Samplers. `sample_rate` builds a parent-based ratio sampler and `OTEL_TRACES_SAMPLER` is not consulted. `opentelemetry-sampler-xray` is the only contrib sampler; there is no remote sampler for Jaeger.
533
+
534
+ ## TODO(jhartquist): Safely
535
+
536
+ Every public method except the ingest factories, and every capture hook, runs under `Internal::Safely`: a failure inside the gem is written to stderr with the `[foam-otel]` prefix and the call returns a fallback, so nothing reaches the app. One broad boundary per public call and per hook, instead of a wrap at each site, would give one place to rate-limit and report, at the cost of skipping the rest of a hook after its first failure. Additionally, a failure could also be reported to Foam over the path `init` uses for its own outcome.
537
+
693
538
  ## Development
694
539
 
695
540
  ```sh
@@ -700,13 +545,6 @@ bundle exec standardrb --fix # lint and autoformat
700
545
  bundle exec rake # unit, e2e, then lint (what CI checks)
701
546
  ```
702
547
 
703
- The end-to-end tests run a real OTLP collector and the fixture apps under
704
- `e2e/apps/` with puma, then assert on what the collector received.
705
- `rake e2e` downloads the pinned `otelcol-contrib` release to
706
- `~/.cache/foam-otel` the first time (about 350 MB; set `FOAM_OTELCOL_DIR`
707
- to cache it elsewhere) and installs the fixture apps' bundles. Run one file
708
- with `bundle exec rspec e2e/spec/rack_init_spec.rb`.
548
+ The end-to-end tests run a real OTLP collector and the fixture apps under `e2e/apps/` with puma, then assert on what the collector received. `rake e2e` downloads the pinned `otelcol-contrib` release to `~/.cache/foam-otel` the first time (about 350 MB; set `FOAM_OTELCOL_DIR` to cache it elsewhere), and the suite installs a fixture app's bundle when it starts the app. Run one file with `bundle exec rspec e2e/spec/rack_init_spec.rb`; that does not download the collector, so run `rake e2e:install` once first.
709
549
 
710
- Each run writes the collector config, the received telemetry, and the
711
- output of both processes to `tmp/e2e/`. A failure prints the tail of both
712
- stderr files.
550
+ Each run writes the collector config, the received telemetry, and the output of both processes to `tmp/e2e/`. A failure prints the tail of both stderr files.